summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-24 03:18:07 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-24 03:18:07 +0200
commit035cbdfe1bc5aea16cbcada5e3c00ecf5ac08c96 (patch)
tree91a3a86c8589cec7d2ebb70e2fdfb4e9f05cc3c5 /lib
parent94b507f2c1c7244493473a0a6673d726a6fe9cf5 (diff)
Breake some of the helper functions out of process_block.c
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfs/Makemodule.am1
-rw-r--r--lib/sqfs/blk_proc/deduplicate.c49
-rw-r--r--lib/sqfs/blk_proc/fragtbl.c22
-rw-r--r--lib/sqfs/blk_proc/internal.h10
-rw-r--r--lib/sqfs/blk_proc/process_block.c63
5 files changed, 82 insertions, 63 deletions
diff --git a/lib/sqfs/Makemodule.am b/lib/sqfs/Makemodule.am
index 90c83cc..28f5a93 100644
--- a/lib/sqfs/Makemodule.am
+++ b/lib/sqfs/Makemodule.am
@@ -20,6 +20,7 @@ libsquashfs_la_SOURCES += lib/sqfs/dir_reader.c lib/sqfs/read_tree.c
libsquashfs_la_SOURCES += lib/sqfs/inode.c lib/sqfs/blk_proc/fragtbl.c
libsquashfs_la_SOURCES += lib/sqfs/blk_proc/process_block.c lib/sqfs/io.c
libsquashfs_la_SOURCES += lib/sqfs/blk_proc/internal.h lib/sqfs/data_reader.c
+libsquashfs_la_SOURCES += lib/sqfs/blk_proc/deduplicate.c
libsquashfs_la_CPPFLAGS = $(AM_CPPFLAGS)
libsquashfs_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) $(ZLIB_CFLAGS)
libsquashfs_la_CFLAGS += $(XZ_CFLAGS) $(LZO_CFLAGS) $(LZ4_CFLAGS)
diff --git a/lib/sqfs/blk_proc/deduplicate.c b/lib/sqfs/blk_proc/deduplicate.c
new file mode 100644
index 0000000..34e4e37
--- /dev/null
+++ b/lib/sqfs/blk_proc/deduplicate.c
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: LGPL-3.0-or-later */
+/*
+ * deduplicate.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#define SQFS_BUILDING_DLL
+#include "internal.h"
+
+int store_block_location(sqfs_block_processor_t *proc, uint64_t offset,
+ uint32_t size, uint32_t chksum)
+{
+ size_t new_sz;
+ void *new;
+
+ if (proc->num_blocks == proc->max_blocks) {
+ new_sz = proc->max_blocks * 2;
+ new = realloc(proc->blocks, sizeof(proc->blocks[0]) * new_sz);
+
+ if (new == NULL)
+ return SQFS_ERROR_ALLOC;
+
+ proc->blocks = new;
+ proc->max_blocks = new_sz;
+ }
+
+ proc->blocks[proc->num_blocks].offset = offset;
+ proc->blocks[proc->num_blocks].signature = MK_BLK_SIG(chksum, size);
+ proc->num_blocks += 1;
+ return 0;
+}
+
+size_t deduplicate_blocks(sqfs_block_processor_t *proc, size_t count)
+{
+ size_t i, j;
+
+ for (i = 0; i < proc->file_start; ++i) {
+ for (j = 0; j < count; ++j) {
+ if (proc->blocks[i + j].signature !=
+ proc->blocks[proc->file_start + j].signature)
+ break;
+ }
+
+ if (j == count)
+ break;
+ }
+
+ return i;
+}
diff --git a/lib/sqfs/blk_proc/fragtbl.c b/lib/sqfs/blk_proc/fragtbl.c
index 81baf09..3f6c644 100644
--- a/lib/sqfs/blk_proc/fragtbl.c
+++ b/lib/sqfs/blk_proc/fragtbl.c
@@ -34,3 +34,25 @@ int sqfs_block_processor_write_fragment_table(sqfs_block_processor_t *proc,
super->fragment_table_start = start;
return 0;
}
+
+int grow_fragment_table(sqfs_block_processor_t *proc, size_t index)
+{
+ size_t newsz;
+ void *new;
+
+ if (index < proc->max_fragments)
+ return 0;
+
+ do {
+ newsz = proc->max_fragments ? proc->max_fragments * 2 : 16;
+ } while (index >= newsz);
+
+ new = realloc(proc->fragments, sizeof(proc->fragments[0]) * newsz);
+
+ if (new == NULL)
+ return SQFS_ERROR_ALLOC;
+
+ proc->max_fragments = newsz;
+ proc->fragments = new;
+ return 0;
+}
diff --git a/lib/sqfs/blk_proc/internal.h b/lib/sqfs/blk_proc/internal.h
index ac628c8..90a9d91 100644
--- a/lib/sqfs/blk_proc/internal.h
+++ b/lib/sqfs/blk_proc/internal.h
@@ -100,4 +100,14 @@ int sqfs_block_process(sqfs_block_t *block, sqfs_compressor_t *cmp,
SQFS_INTERNAL int process_completed_block(sqfs_block_processor_t *proc,
sqfs_block_t *block);
+SQFS_INTERNAL int grow_fragment_table(sqfs_block_processor_t *proc,
+ size_t index);
+
+SQFS_INTERNAL size_t deduplicate_blocks(sqfs_block_processor_t *proc,
+ size_t count);
+
+SQFS_INTERNAL int store_block_location(sqfs_block_processor_t *proc,
+ uint64_t offset, uint32_t size,
+ uint32_t chksum);
+
#endif /* INTERNAL_H */
diff --git a/lib/sqfs/blk_proc/process_block.c b/lib/sqfs/blk_proc/process_block.c
index ccc6df0..78de31b 100644
--- a/lib/sqfs/blk_proc/process_block.c
+++ b/lib/sqfs/blk_proc/process_block.c
@@ -47,69 +47,6 @@ static int allign_file(sqfs_block_processor_t *proc, sqfs_block_t *blk)
proc->devblksz);
}
-static int store_block_location(sqfs_block_processor_t *proc, uint64_t offset,
- uint32_t size, uint32_t chksum)
-{
- size_t new_sz;
- void *new;
-
- if (proc->num_blocks == proc->max_blocks) {
- new_sz = proc->max_blocks * 2;
- new = realloc(proc->blocks, sizeof(proc->blocks[0]) * new_sz);
-
- if (new == NULL)
- return SQFS_ERROR_ALLOC;
-
- proc->blocks = new;
- proc->max_blocks = new_sz;
- }
-
- proc->blocks[proc->num_blocks].offset = offset;
- proc->blocks[proc->num_blocks].signature = MK_BLK_SIG(chksum, size);
- proc->num_blocks += 1;
- return 0;
-}
-
-static size_t deduplicate_blocks(sqfs_block_processor_t *proc, size_t count)
-{
- size_t i, j;
-
- for (i = 0; i < proc->file_start; ++i) {
- for (j = 0; j < count; ++j) {
- if (proc->blocks[i + j].signature !=
- proc->blocks[proc->file_start + j].signature)
- break;
- }
-
- if (j == count)
- break;
- }
-
- return i;
-}
-
-static size_t grow_fragment_table(sqfs_block_processor_t *proc, size_t index)
-{
- size_t newsz;
- void *new;
-
- if (index < proc->max_fragments)
- return 0;
-
- do {
- newsz = proc->max_fragments ? proc->max_fragments * 2 : 16;
- } while (index >= newsz);
-
- new = realloc(proc->fragments, sizeof(proc->fragments[0]) * newsz);
-
- if (new == NULL)
- return SQFS_ERROR_ALLOC;
-
- proc->max_fragments = newsz;
- proc->fragments = new;
- return 0;
-}
-
int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
{
size_t start, count;