aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs/blk_proc
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-25 06:50:03 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-25 06:50:03 +0200
commit9434bdfaedb733e1441d87fedde8056efeda7145 (patch)
tree48b2d8c9e113170f9b64337507acd5d0981e9c87 /lib/sqfs/blk_proc
parent8f0f1f4c8047a97012c55dc057780ff76667aacc (diff)
More refactoring of the block processor
Basically just moving functions around and renaming things. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/blk_proc')
-rw-r--r--lib/sqfs/blk_proc/block.c (renamed from lib/sqfs/blk_proc/process_block.c)41
-rw-r--r--lib/sqfs/blk_proc/deduplicate.c49
-rw-r--r--lib/sqfs/blk_proc/fragment.c (renamed from lib/sqfs/blk_proc/fragtbl.c)4
-rw-r--r--lib/sqfs/blk_proc/internal.h11
-rw-r--r--lib/sqfs/blk_proc/pthread.c2
-rw-r--r--lib/sqfs/blk_proc/serial.c3
6 files changed, 48 insertions, 62 deletions
diff --git a/lib/sqfs/blk_proc/process_block.c b/lib/sqfs/blk_proc/block.c
index 2951406..69a7119 100644
--- a/lib/sqfs/blk_proc/process_block.c
+++ b/lib/sqfs/blk_proc/block.c
@@ -9,6 +9,47 @@
#include <string.h>
+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].hash = MK_BLK_HASH(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].hash !=
+ proc->blocks[proc->file_start + j].hash)
+ break;
+ }
+
+ if (j == count)
+ break;
+ }
+
+ return i;
+}
+
static int allign_file(sqfs_block_processor_t *proc, sqfs_block_t *blk)
{
if (!(blk->flags & SQFS_BLK_ALLIGN))
diff --git a/lib/sqfs/blk_proc/deduplicate.c b/lib/sqfs/blk_proc/deduplicate.c
deleted file mode 100644
index 08a108e..0000000
--- a/lib/sqfs/blk_proc/deduplicate.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* 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].hash = MK_BLK_HASH(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].hash !=
- proc->blocks[proc->file_start + j].hash)
- break;
- }
-
- if (j == count)
- break;
- }
-
- return i;
-}
diff --git a/lib/sqfs/blk_proc/fragtbl.c b/lib/sqfs/blk_proc/fragment.c
index 39e8136..5fa2349 100644
--- a/lib/sqfs/blk_proc/fragtbl.c
+++ b/lib/sqfs/blk_proc/fragment.c
@@ -72,8 +72,8 @@ static int store_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
return 0;
}
-int handle_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
- sqfs_block_t **blk_out)
+int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
+ sqfs_block_t **blk_out)
{
uint64_t hash;
size_t i, size;
diff --git a/lib/sqfs/blk_proc/internal.h b/lib/sqfs/blk_proc/internal.h
index b6a0342..1c403a9 100644
--- a/lib/sqfs/blk_proc/internal.h
+++ b/lib/sqfs/blk_proc/internal.h
@@ -111,15 +111,8 @@ SQFS_INTERNAL int process_completed_block(sqfs_block_processor_t *proc,
sqfs_block_t *block);
SQFS_INTERNAL
-int handle_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
- sqfs_block_t **blk_out);
-
-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);
+int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
+ sqfs_block_t **blk_out);
SQFS_INTERNAL void free_blk_list(sqfs_block_t *list);
diff --git a/lib/sqfs/blk_proc/pthread.c b/lib/sqfs/blk_proc/pthread.c
index 57b61c1..7b95c7c 100644
--- a/lib/sqfs/blk_proc/pthread.c
+++ b/lib/sqfs/blk_proc/pthread.c
@@ -226,7 +226,7 @@ static int process_done_queue(sqfs_block_processor_t *proc,
if (it->flags & SQFS_BLK_IS_FRAGMENT) {
block = NULL;
- status = handle_fragment(proc, it, &block);
+ status = process_completed_fragment(proc, it, &block);
if (block != NULL && status == 0) {
pthread_mutex_lock(&proc->mtx);
diff --git a/lib/sqfs/blk_proc/serial.c b/lib/sqfs/blk_proc/serial.c
index 67272a3..fcbf002 100644
--- a/lib/sqfs/blk_proc/serial.c
+++ b/lib/sqfs/blk_proc/serial.c
@@ -54,7 +54,8 @@ int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
if (block->flags & SQFS_BLK_IS_FRAGMENT) {
block->checksum = crc32(0, block->data, block->size);
- proc->status = handle_fragment(proc, block, &fragblk);
+ proc->status = process_completed_fragment(proc, block,
+ &fragblk);
free(block);
if (proc->status != 0) {