summaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-09 14:13:04 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-09 14:13:04 +0100
commit6a7a7aaa4c7c715577d9649657412f99c06e1a95 (patch)
treeb15db872afadd13596626f8fd22263190ee6f8b3 /lib/sqfs
parentda3add97f8d4a1bb4d14989f5bd0b6f5f7bc9891 (diff)
block processor: merge left overs of block.c/fragment.c into common.c
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/Makemodule.am3
-rw-r--r--lib/sqfs/block_processor/block.c72
-rw-r--r--lib/sqfs/block_processor/common.c135
-rw-r--r--lib/sqfs/block_processor/fragment.c81
4 files changed, 136 insertions, 155 deletions
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am
index 644ced2..082b6b1 100644
--- a/lib/sqfs/Makemodule.am
+++ b/lib/sqfs/Makemodule.am
@@ -19,9 +19,8 @@ libsquashfs_la_SOURCES += lib/sqfs/dir_writer.c lib/sqfs/xattr_reader.c
libsquashfs_la_SOURCES += lib/sqfs/read_table.c lib/sqfs/comp/compressor.c
libsquashfs_la_SOURCES += lib/sqfs/comp/internal.h lib/sqfs/xattr_writer.c
libsquashfs_la_SOURCES += lib/sqfs/dir_reader.c lib/sqfs/read_tree.c
-libsquashfs_la_SOURCES += lib/sqfs/inode.c lib/sqfs/block_processor/fragment.c
+libsquashfs_la_SOURCES += lib/sqfs/inode.c
libsquashfs_la_SOURCES += lib/sqfs/write_super.c lib/sqfs/data_reader.c
-libsquashfs_la_SOURCES += lib/sqfs/block_processor/block.c
libsquashfs_la_SOURCES += lib/sqfs/block_processor/internal.h
libsquashfs_la_SOURCES += lib/sqfs/block_processor/common.c
libsquashfs_la_SOURCES += lib/sqfs/block_processor/fileapi.c
diff --git a/lib/sqfs/block_processor/block.c b/lib/sqfs/block_processor/block.c
deleted file mode 100644
index e88456a..0000000
--- a/lib/sqfs/block_processor/block.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
-/*
- * process_block.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#define SQFS_BUILDING_DLL
-#include "internal.h"
-
-#include <string.h>
-
-int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
-{
- sqfs_u64 location;
- sqfs_u32 size;
- int err;
-
- size = blk->size;
- if (!(blk->flags & SQFS_BLK_IS_COMPRESSED))
- size |= 1 << 24;
-
- err = sqfs_block_writer_write(proc->wr, blk, &location);
- if (err)
- return err;
-
- if (blk->size != 0) {
- if (blk->flags & SQFS_BLK_FRAGMENT_BLOCK) {
- err = sqfs_frag_table_set(proc->frag_tbl, blk->index,
- location, size);
- if (err)
- return err;
- } else {
- blk->inode->extra[blk->index] = size;
- }
- }
-
- if (blk->flags & SQFS_BLK_LAST_BLOCK)
- sqfs_inode_set_file_block_start(blk->inode, location);
-
- return 0;
-}
-
-int block_processor_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp,
- sqfs_u8 *scratch, size_t scratch_size)
-{
- ssize_t ret;
-
- if (block->size == 0) {
- block->checksum = 0;
- return 0;
- }
-
- block->checksum = crc32(0, block->data, block->size);
-
- if (block->flags & SQFS_BLK_IS_FRAGMENT)
- return 0;
-
- if (!(block->flags & SQFS_BLK_DONT_COMPRESS)) {
- ret = cmp->do_block(cmp, block->data, block->size,
- scratch, scratch_size);
- if (ret < 0)
- return ret;
-
- if (ret > 0) {
- memcpy(block->data, scratch, ret);
- block->size = ret;
- block->flags |= SQFS_BLK_IS_COMPRESSED;
- }
- }
-
- return 0;
-}
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c
index 23991ea..fe9773e 100644
--- a/lib/sqfs/block_processor/common.c
+++ b/lib/sqfs/block_processor/common.c
@@ -49,3 +49,138 @@ int sqfs_block_processor_set_hooks(sqfs_block_processor_t *proc, void *user_ptr,
return sqfs_block_writer_set_hooks(proc->wr, user_ptr, hooks);
}
+
+int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
+{
+ sqfs_u64 location;
+ sqfs_u32 size;
+ int err;
+
+ size = blk->size;
+ if (!(blk->flags & SQFS_BLK_IS_COMPRESSED))
+ size |= 1 << 24;
+
+ err = sqfs_block_writer_write(proc->wr, blk, &location);
+ if (err)
+ return err;
+
+ if (blk->size != 0) {
+ if (blk->flags & SQFS_BLK_FRAGMENT_BLOCK) {
+ err = sqfs_frag_table_set(proc->frag_tbl, blk->index,
+ location, size);
+ if (err)
+ return err;
+ } else {
+ blk->inode->extra[blk->index] = size;
+ }
+ }
+
+ if (blk->flags & SQFS_BLK_LAST_BLOCK)
+ sqfs_inode_set_file_block_start(blk->inode, location);
+
+ return 0;
+}
+
+int block_processor_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp,
+ sqfs_u8 *scratch, size_t scratch_size)
+{
+ ssize_t ret;
+
+ if (block->size == 0) {
+ block->checksum = 0;
+ return 0;
+ }
+
+ block->checksum = crc32(0, block->data, block->size);
+
+ if (block->flags & SQFS_BLK_IS_FRAGMENT)
+ return 0;
+
+ if (!(block->flags & SQFS_BLK_DONT_COMPRESS)) {
+ ret = cmp->do_block(cmp, block->data, block->size,
+ scratch, scratch_size);
+ if (ret < 0)
+ return ret;
+
+ if (ret > 0) {
+ memcpy(block->data, scratch, ret);
+ block->size = ret;
+ block->flags |= SQFS_BLK_IS_COMPRESSED;
+ }
+ }
+
+ return 0;
+}
+
+int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
+ sqfs_block_t **blk_out)
+{
+ sqfs_u32 index, offset;
+ size_t size;
+ int err;
+
+ err = sqfs_frag_table_find_tail_end(proc->frag_tbl,
+ frag->checksum, frag->size,
+ &index, &offset);
+ if (err == 0)
+ goto out_duplicate;
+
+ if (proc->frag_block != NULL) {
+ size = proc->frag_block->size + frag->size;
+
+ if (size > proc->max_block_size) {
+ *blk_out = proc->frag_block;
+ proc->frag_block = NULL;
+ }
+ }
+
+ if (proc->frag_block == NULL) {
+ size = sizeof(sqfs_block_t) + proc->max_block_size;
+
+ err= sqfs_frag_table_append(proc->frag_tbl, 0, 0, &index);
+ if (err)
+ goto fail;
+
+ proc->frag_block = calloc(1, size);
+ if (proc->frag_block == NULL) {
+ err = SQFS_ERROR_ALLOC;
+ goto fail;
+ }
+
+ proc->frag_block->index = index;
+ proc->frag_block->flags = SQFS_BLK_FRAGMENT_BLOCK;
+ }
+
+ err = sqfs_frag_table_add_tail_end(proc->frag_tbl,
+ proc->frag_block->index,
+ proc->frag_block->size,
+ frag->size, frag->checksum);
+ if (err)
+ goto fail;
+
+ sqfs_inode_set_frag_location(frag->inode, proc->frag_block->index,
+ proc->frag_block->size);
+
+ if (proc->hooks != NULL && proc->hooks->pre_fragment_store != NULL) {
+ proc->hooks->pre_fragment_store(proc->user_ptr, frag);
+ }
+
+ memcpy(proc->frag_block->data + proc->frag_block->size,
+ frag->data, frag->size);
+
+ proc->frag_block->flags |= (frag->flags & SQFS_BLK_DONT_COMPRESS);
+ proc->frag_block->size += frag->size;
+ return 0;
+fail:
+ free(*blk_out);
+ *blk_out = NULL;
+ return err;
+out_duplicate:
+ sqfs_inode_set_frag_location(frag->inode, index, offset);
+
+ if (proc->hooks != NULL &&
+ proc->hooks->notify_fragment_discard != NULL) {
+ proc->hooks->notify_fragment_discard(proc->user_ptr, frag);
+ }
+ return 0;
+}
diff --git a/lib/sqfs/block_processor/fragment.c b/lib/sqfs/block_processor/fragment.c
deleted file mode 100644
index 3701b3c..0000000
--- a/lib/sqfs/block_processor/fragment.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* SPDX-License-Identifier: LGPL-3.0-or-later */
-/*
- * fragtbl.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#define SQFS_BUILDING_DLL
-#include "internal.h"
-
-int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
- sqfs_block_t **blk_out)
-{
- sqfs_u32 index, offset;
- size_t size;
- int err;
-
- err = sqfs_frag_table_find_tail_end(proc->frag_tbl,
- frag->checksum, frag->size,
- &index, &offset);
- if (err == 0)
- goto out_duplicate;
-
- if (proc->frag_block != NULL) {
- size = proc->frag_block->size + frag->size;
-
- if (size > proc->max_block_size) {
- *blk_out = proc->frag_block;
- proc->frag_block = NULL;
- }
- }
-
- if (proc->frag_block == NULL) {
- size = sizeof(sqfs_block_t) + proc->max_block_size;
-
- err= sqfs_frag_table_append(proc->frag_tbl, 0, 0, &index);
- if (err)
- goto fail;
-
- proc->frag_block = calloc(1, size);
- if (proc->frag_block == NULL) {
- err = SQFS_ERROR_ALLOC;
- goto fail;
- }
-
- proc->frag_block->index = index;
- proc->frag_block->flags = SQFS_BLK_FRAGMENT_BLOCK;
- }
-
- err = sqfs_frag_table_add_tail_end(proc->frag_tbl,
- proc->frag_block->index,
- proc->frag_block->size,
- frag->size, frag->checksum);
- if (err)
- goto fail;
-
- sqfs_inode_set_frag_location(frag->inode, proc->frag_block->index,
- proc->frag_block->size);
-
- if (proc->hooks != NULL && proc->hooks->pre_fragment_store != NULL) {
- proc->hooks->pre_fragment_store(proc->user_ptr, frag);
- }
-
- memcpy(proc->frag_block->data + proc->frag_block->size,
- frag->data, frag->size);
-
- proc->frag_block->flags |= (frag->flags & SQFS_BLK_DONT_COMPRESS);
- proc->frag_block->size += frag->size;
- return 0;
-fail:
- free(*blk_out);
- *blk_out = NULL;
- return err;
-out_duplicate:
- sqfs_inode_set_frag_location(frag->inode, index, offset);
-
- if (proc->hooks != NULL &&
- proc->hooks->notify_fragment_discard != NULL) {
- proc->hooks->notify_fragment_discard(proc->user_ptr, frag);
- }
- return 0;
-}