summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-05 18:22:28 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-05 18:22:28 +0200
commitf92cf3b98f51d355c92900f1d316b141b2b9d4fd (patch)
tree87d86e178288ef4c70831ac3b6ae977786fcab34
parentf85394c5887350a9728e108e72d908e08fc4cb78 (diff)
Cleanup: add SQFS_*/sqfs_* prefix to block processor
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/sqfs/block_processor.h49
-rw-r--r--lib/sqfs/block_processor.c29
-rw-r--r--lib/sqfs/block_processor_parallel.c63
-rw-r--r--lib/sqfs/process_block.c10
-rw-r--r--lib/sqfshelper/data_writer.c63
5 files changed, 111 insertions, 103 deletions
diff --git a/include/sqfs/block_processor.h b/include/sqfs/block_processor.h
index 5d7ed3b..552bd89 100644
--- a/include/sqfs/block_processor.h
+++ b/include/sqfs/block_processor.h
@@ -4,32 +4,32 @@
*
* Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
*/
-#ifndef BLOCK_PROCESSOR_H
-#define BLOCK_PROCESSOR_H
+#ifndef SFQS_BLOCK_PROCESSOR_H
+#define SFQS_BLOCK_PROCESSOR_H
#include "config.h"
#include "sqfs/compress.h"
enum {
/* only calculate checksum, do NOT compress the data */
- BLK_DONT_COMPRESS = 0x0001,
+ SQFS_BLK_DONT_COMPRESS = 0x0001,
/* set by compressor worker if the block was actually compressed */
- BLK_IS_COMPRESSED = 0x0002,
+ SQFS_BLK_IS_COMPRESSED = 0x0002,
/* do not calculate block checksum */
- BLK_DONT_CHECKSUM = 0x0004,
+ SQFS_BLK_DONT_CHECKSUM = 0x0004,
/* set by compressor worker if compression failed */
- BLK_COMPRESS_ERROR = 0x0008,
+ SQFS_BLK_COMPRESS_ERROR = 0x0008,
/* first user setable block flag */
- BLK_USER = 0x0080
+ SQFS_BLK_USER = 0x0080
};
-typedef struct block_t {
+typedef struct sqfs_block_t {
/* used internally, ignored and overwritten when enqueueing blocks */
- struct block_t *next;
+ struct sqfs_block_t *next;
uint32_t sequence_number;
/* Size of the data area */
@@ -49,9 +49,9 @@ typedef struct block_t {
/* raw data to be processed */
uint8_t data[];
-} block_t;
+} sqfs_block_t;
-typedef struct block_processor_t block_processor_t;
+typedef struct sqfs_block_processor_t sqfs_block_processor_t;
/*
Gets called for each processed block. May be called from a different thread
@@ -61,19 +61,19 @@ typedef struct block_processor_t block_processor_t;
A non-zero return value is interpreted as fatal error.
*/
-typedef int (*block_cb)(void *user, block_t *blk);
+typedef int (*sqfs_block_cb)(void *user, sqfs_block_t *blk);
#ifdef __cplusplus
extern "C" {
#endif
-block_processor_t *block_processor_create(size_t max_block_size,
- compressor_t *cmp,
- unsigned int num_workers,
- void *user,
- block_cb callback);
+sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
+ compressor_t *cmp,
+ unsigned int num_workers,
+ void *user,
+ sqfs_block_cb callback);
-void block_processor_destroy(block_processor_t *proc);
+void sqfs_block_processor_destroy(sqfs_block_processor_t *proc);
/*
Add a block to be processed. Returns non-zero on error and prints a message
@@ -83,26 +83,27 @@ void block_processor_destroy(block_processor_t *proc);
a after processing and calling the block callback.
Even on failure, the workers may still be running and
- block_processor_finish must be called before cleaning up.
+ sqfs_block_processor_finish must be called before cleaning up.
*/
-int block_processor_enqueue(block_processor_t *proc, block_t *block);
+int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
+ sqfs_block_t *block);
/*
Wait for the compressor workers to finish. Returns zero on success, non-zero
if an internal error occoured or one of the block callbacks returned a
non-zero value.
*/
-int block_processor_finish(block_processor_t *proc);
+int sqfs_block_processor_finish(sqfs_block_processor_t *proc);
/*
Convenience function to process a data block. Returns 0 on success,
prints to stderr on failure.
*/
-int process_block(block_t *block, compressor_t *cmp,
- uint8_t *scratch, size_t scratch_size);
+int sqfs_block_process(sqfs_block_t *block, compressor_t *cmp,
+ uint8_t *scratch, size_t scratch_size);
#ifdef __cplusplus
}
#endif
-#endif /* BLOCK_PROCESSOR_H */
+#endif /* SFQS_BLOCK_PROCESSOR_H */
diff --git a/lib/sqfs/block_processor.c b/lib/sqfs/block_processor.c
index 3a6926c..2bf307f 100644
--- a/lib/sqfs/block_processor.c
+++ b/lib/sqfs/block_processor.c
@@ -13,25 +13,27 @@
#include <stdlib.h>
#include <stdio.h>
-struct block_processor_t {
+struct sqfs_block_processor_t {
size_t max_block_size;
compressor_t *cmp;
- block_cb cb;
+ sqfs_block_cb cb;
void *user;
int status;
uint8_t scratch[];
};
-block_processor_t *block_processor_create(size_t max_block_size,
- compressor_t *cmp,
- unsigned int num_workers,
- void *user,
- block_cb callback)
+sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
+ compressor_t *cmp,
+ unsigned int num_workers,
+ void *user,
+ sqfs_block_cb callback)
{
- block_processor_t *proc = alloc_flex(sizeof(*proc), 1, max_block_size);
+ sqfs_block_processor_t *proc;
(void)num_workers;
+ proc = alloc_flex(sizeof(*proc), 1, max_block_size);
+
if (proc == NULL) {
perror("Creating block processor");
return NULL;
@@ -44,15 +46,16 @@ block_processor_t *block_processor_create(size_t max_block_size,
return proc;
}
-void block_processor_destroy(block_processor_t *proc)
+void sqfs_block_processor_destroy(sqfs_block_processor_t *proc)
{
free(proc);
}
-int block_processor_enqueue(block_processor_t *proc, block_t *block)
+int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
+ sqfs_block_t *block)
{
- if (process_block(block, proc->cmp,
- proc->scratch, proc->max_block_size))
+ if (sqfs_block_process(block, proc->cmp,
+ proc->scratch, proc->max_block_size))
goto fail;
if (proc->cb(proc->user, block))
@@ -66,7 +69,7 @@ fail:
return -1;
}
-int block_processor_finish(block_processor_t *proc)
+int sqfs_block_processor_finish(sqfs_block_processor_t *proc)
{
return proc->status;
}
diff --git a/lib/sqfs/block_processor_parallel.c b/lib/sqfs/block_processor_parallel.c
index a4e0f6e..6fca018 100644
--- a/lib/sqfs/block_processor_parallel.c
+++ b/lib/sqfs/block_processor_parallel.c
@@ -17,22 +17,22 @@
#define MAX_BACKLOG_FACTOR (10)
typedef struct {
- block_processor_t *shared;
+ sqfs_block_processor_t *shared;
compressor_t *cmp;
pthread_t thread;
uint8_t scratch[];
} compress_worker_t;
-struct block_processor_t {
+struct sqfs_block_processor_t {
pthread_mutex_t mtx;
pthread_cond_t queue_cond;
pthread_cond_t done_cond;
/* needs rw access by worker and main thread */
- block_t *queue;
- block_t *queue_last;
+ sqfs_block_t *queue;
+ sqfs_block_t *queue_last;
- block_t *done;
+ sqfs_block_t *done;
bool terminate;
size_t backlog;
@@ -41,7 +41,7 @@ struct block_processor_t {
uint32_t dequeue_id;
unsigned int num_workers;
- block_cb cb;
+ sqfs_block_cb cb;
void *user;
int status;
@@ -51,9 +51,10 @@ struct block_processor_t {
compress_worker_t *workers[];
};
-static void store_completed_block(block_processor_t *shared, block_t *blk)
+static void store_completed_block(sqfs_block_processor_t *shared,
+ sqfs_block_t *blk)
{
- block_t *it = shared->done, *prev = NULL;
+ sqfs_block_t *it = shared->done, *prev = NULL;
while (it != NULL) {
if (it->sequence_number >= blk->sequence_number)
@@ -74,8 +75,8 @@ static void store_completed_block(block_processor_t *shared, block_t *blk)
static void *worker_proc(void *arg)
{
compress_worker_t *worker = arg;
- block_processor_t *shared = worker->shared;
- block_t *blk = NULL;
+ sqfs_block_processor_t *shared = worker->shared;
+ sqfs_block_t *blk = NULL;
for (;;) {
pthread_mutex_lock(&shared->mtx);
@@ -103,21 +104,21 @@ static void *worker_proc(void *arg)
shared->queue_last = NULL;
pthread_mutex_unlock(&shared->mtx);
- if (process_block(blk, worker->cmp, worker->scratch,
- shared->max_block_size)) {
- blk->flags |= BLK_COMPRESS_ERROR;
+ if (sqfs_block_process(blk, worker->cmp, worker->scratch,
+ shared->max_block_size)) {
+ blk->flags |= SQFS_BLK_COMPRESS_ERROR;
}
}
return NULL;
}
-block_processor_t *block_processor_create(size_t max_block_size,
- compressor_t *cmp,
- unsigned int num_workers,
- void *user,
- block_cb callback)
+sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
+ compressor_t *cmp,
+ unsigned int num_workers,
+ void *user,
+ sqfs_block_cb callback)
{
- block_processor_t *proc;
+ sqfs_block_processor_t *proc;
unsigned int i;
int ret;
@@ -210,10 +211,10 @@ fail_free:
return NULL;
}
-void block_processor_destroy(block_processor_t *proc)
+void sqfs_block_processor_destroy(sqfs_block_processor_t *proc)
{
+ sqfs_block_t *blk;
unsigned int i;
- block_t *blk;
pthread_mutex_lock(&proc->mtx);
proc->terminate = true;
@@ -246,15 +247,16 @@ void block_processor_destroy(block_processor_t *proc)
free(proc);
}
-static int process_completed_blocks(block_processor_t *proc, block_t *queue)
+static int process_completed_blocks(sqfs_block_processor_t *proc,
+ sqfs_block_t *queue)
{
- block_t *it;
+ sqfs_block_t *it;
while (queue != NULL) {
it = queue;
queue = queue->next;
- if (it->flags & BLK_COMPRESS_ERROR) {
+ if (it->flags & SQFS_BLK_COMPRESS_ERROR) {
proc->status = -1;
} else {
if (proc->cb(proc->user, it))
@@ -267,16 +269,17 @@ static int process_completed_blocks(block_processor_t *proc, block_t *queue)
return proc->status;
}
-int block_processor_enqueue(block_processor_t *proc, block_t *block)
+int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
+ sqfs_block_t *block)
{
- block_t *queue = NULL, *it, *prev;
+ sqfs_block_t *queue = NULL, *it, *prev;
block->sequence_number = proc->enqueue_id++;
block->next = NULL;
pthread_mutex_lock(&proc->mtx);
- if ((block->flags & BLK_DONT_COMPRESS) &&
- (block->flags & BLK_DONT_CHECKSUM)) {
+ if ((block->flags & SQFS_BLK_DONT_COMPRESS) &&
+ (block->flags & SQFS_BLK_DONT_CHECKSUM)) {
store_completed_block(proc, block);
} else {
while (proc->backlog > proc->num_workers * MAX_BACKLOG_FACTOR)
@@ -313,9 +316,9 @@ int block_processor_enqueue(block_processor_t *proc, block_t *block)
return process_completed_blocks(proc, queue);
}
-int block_processor_finish(block_processor_t *proc)
+int sqfs_block_processor_finish(sqfs_block_processor_t *proc)
{
- block_t *queue, *it;
+ sqfs_block_t *queue, *it;
pthread_mutex_lock(&proc->mtx);
while (proc->backlog > 0)
diff --git a/lib/sqfs/process_block.c b/lib/sqfs/process_block.c
index a20b56b..b0c8a91 100644
--- a/lib/sqfs/process_block.c
+++ b/lib/sqfs/process_block.c
@@ -12,15 +12,15 @@
#include <string.h>
#include <zlib.h>
-int process_block(block_t *block, compressor_t *cmp,
- uint8_t *scratch, size_t scratch_size)
+int sqfs_block_process(sqfs_block_t *block, compressor_t *cmp,
+ uint8_t *scratch, size_t scratch_size)
{
ssize_t ret;
- if (!(block->flags & BLK_DONT_CHECKSUM))
+ if (!(block->flags & SQFS_BLK_DONT_CHECKSUM))
block->checksum = crc32(0, block->data, block->size);
- if (!(block->flags & BLK_DONT_COMPRESS)) {
+ if (!(block->flags & SQFS_BLK_DONT_COMPRESS)) {
ret = cmp->do_block(cmp, block->data, block->size,
scratch, scratch_size);
@@ -30,7 +30,7 @@ int process_block(block_t *block, compressor_t *cmp,
if (ret > 0) {
memcpy(block->data, scratch, ret);
block->size = ret;
- block->flags |= BLK_IS_COMPRESSED;
+ block->flags |= SQFS_BLK_IS_COMPRESSED;
}
}
diff --git a/lib/sqfshelper/data_writer.c b/lib/sqfshelper/data_writer.c
index 6a0ef17..c41088a 100644
--- a/lib/sqfshelper/data_writer.c
+++ b/lib/sqfshelper/data_writer.c
@@ -19,7 +19,7 @@
#include <zlib.h>
struct data_writer_t {
- block_t *frag_block;
+ sqfs_block_t *frag_block;
sqfs_fragment_t *fragments;
size_t num_fragments;
size_t max_fragments;
@@ -28,7 +28,7 @@ struct data_writer_t {
uint64_t bytes_written;
off_t start;
- block_processor_t *proc;
+ sqfs_block_processor_t *proc;
compressor_t *cmp;
file_info_t *list;
sqfs_super_t *super;
@@ -36,10 +36,10 @@ struct data_writer_t {
};
enum {
- BLK_FIRST_BLOCK = BLK_USER,
- BLK_LAST_BLOCK = BLK_USER << 1,
- BLK_ALLIGN = BLK_USER << 2,
- BLK_FRAGMENT_BLOCK = BLK_USER << 3,
+ BLK_FIRST_BLOCK = SQFS_BLK_USER,
+ BLK_LAST_BLOCK = SQFS_BLK_USER << 1,
+ BLK_ALLIGN = SQFS_BLK_USER << 2,
+ BLK_FRAGMENT_BLOCK = SQFS_BLK_USER << 3,
};
static int save_position(data_writer_t *data)
@@ -87,7 +87,7 @@ static int allign_file(data_writer_t *data)
return 0;
}
-static int block_callback(void *user, block_t *blk)
+static int block_callback(void *user, sqfs_block_t *blk)
{
file_info_t *fi = blk->user;
data_writer_t *data = user;
@@ -106,7 +106,7 @@ static int block_callback(void *user, block_t *blk)
if (blk->size != 0) {
out = blk->size;
- if (!(blk->flags & BLK_IS_COMPRESSED))
+ if (!(blk->flags & SQFS_BLK_IS_COMPRESSED))
out |= 1 << 24;
if (blk->flags & BLK_FRAGMENT_BLOCK) {
@@ -172,12 +172,12 @@ static int flush_fragment_block(data_writer_t *data)
data->frag_block->index = data->num_fragments++;
- ret = block_processor_enqueue(data->proc, data->frag_block);
+ ret = sqfs_block_processor_enqueue(data->proc, data->frag_block);
data->frag_block = NULL;
return ret;
}
-static int store_fragment(data_writer_t *data, block_t *frag)
+static int store_fragment(data_writer_t *data, sqfs_block_t *frag)
{
file_info_t *fi = frag->user;
size_t size;
@@ -192,7 +192,7 @@ static int store_fragment(data_writer_t *data, block_t *frag)
}
if (data->frag_block == NULL) {
- size = sizeof(block_t) + data->super->block_size;
+ size = sizeof(sqfs_block_t) + data->super->block_size;
data->frag_block = calloc(1, size);
if (data->frag_block == NULL) {
@@ -200,14 +200,14 @@ static int store_fragment(data_writer_t *data, block_t *frag)
goto fail;
}
- data->frag_block->flags = BLK_DONT_CHECKSUM;
+ data->frag_block->flags = SQFS_BLK_DONT_CHECKSUM;
data->frag_block->flags |= BLK_FRAGMENT_BLOCK;
}
fi->fragment_offset = data->frag_block->size;
fi->fragment = data->num_fragments;
- data->frag_block->flags |= (frag->flags & BLK_DONT_COMPRESS);
+ data->frag_block->flags |= (frag->flags & SQFS_BLK_DONT_COMPRESS);
memcpy(data->frag_block->data + data->frag_block->size,
frag->data, frag->size);
@@ -224,7 +224,7 @@ static bool is_zero_block(unsigned char *ptr, size_t size)
return ptr[0] == 0 && memcmp(ptr, ptr + 1, size - 1) == 0;
}
-static int handle_fragment(data_writer_t *data, block_t *blk)
+static int handle_fragment(data_writer_t *data, sqfs_block_t *blk)
{
file_info_t *fi = blk->user, *ref;
@@ -247,7 +247,7 @@ static int handle_fragment(data_writer_t *data, block_t *blk)
static int add_sentinel_block(data_writer_t *data, file_info_t *fi,
uint32_t flags)
{
- block_t *blk = calloc(1, sizeof(*blk));
+ sqfs_block_t *blk = calloc(1, sizeof(*blk));
if (blk == NULL) {
perror("creating sentinel block");
@@ -255,15 +255,15 @@ static int add_sentinel_block(data_writer_t *data, file_info_t *fi,
}
blk->user = fi;
- blk->flags = BLK_DONT_COMPRESS | BLK_DONT_CHECKSUM | flags;
+ blk->flags = SQFS_BLK_DONT_COMPRESS | SQFS_BLK_DONT_CHECKSUM | flags;
- return block_processor_enqueue(data->proc, blk);
+ return sqfs_block_processor_enqueue(data->proc, blk);
}
-static block_t *create_block(file_info_t *fi, int fd, size_t size,
- uint32_t flags)
+static sqfs_block_t *create_block(file_info_t *fi, int fd, size_t size,
+ uint32_t flags)
{
- block_t *blk = alloc_flex(sizeof(*blk), 1, size);
+ sqfs_block_t *blk = alloc_flex(sizeof(*blk), 1, size);
if (blk == NULL) {
perror(fi->input_file);
@@ -289,10 +289,10 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi,
uint32_t blk_flags = BLK_FIRST_BLOCK;
uint64_t file_size = fi->size;
size_t diff, i = 0;
- block_t *blk;
+ sqfs_block_t *blk;
if (flags & DW_DONT_COMPRESS)
- blk_flags |= BLK_DONT_COMPRESS;
+ blk_flags |= SQFS_BLK_DONT_COMPRESS;
if (flags & DW_ALLIGN_DEVBLK)
blk_flags |= BLK_ALLIGN;
@@ -336,7 +336,7 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi,
if (handle_fragment(data, blk))
return -1;
} else {
- if (block_processor_enqueue(data->proc, blk))
+ if (sqfs_block_processor_enqueue(data->proc, blk))
return -1;
blk_flags &= ~BLK_FIRST_BLOCK;
@@ -383,7 +383,7 @@ fail_map:
return -1;
}
-static int get_sparse_block(block_t *blk, file_info_t *fi, int infd,
+static int get_sparse_block(sqfs_block_t *blk, file_info_t *fi, int infd,
sparse_map_t **sparse_map, uint64_t offset,
size_t diff)
{
@@ -418,14 +418,14 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi,
{
uint32_t blk_flags = BLK_FIRST_BLOCK;
size_t diff, i = 0;
+ sqfs_block_t *blk;
uint64_t offset;
- block_t *blk;
if (check_map_valid(map, fi))
return -1;
if (flags & DW_DONT_COMPRESS)
- blk_flags |= BLK_DONT_COMPRESS;
+ blk_flags |= SQFS_BLK_DONT_COMPRESS;
if (flags & DW_ALLIGN_DEVBLK)
blk_flags |= BLK_ALLIGN;
@@ -471,7 +471,7 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi,
if (handle_fragment(data, blk))
return -1;
} else {
- if (block_processor_enqueue(data->proc, blk))
+ if (sqfs_block_processor_enqueue(data->proc, blk))
return -1;
blk_flags &= ~BLK_FIRST_BLOCK;
@@ -499,8 +499,9 @@ data_writer_t *data_writer_create(sqfs_super_t *super, compressor_t *cmp,
return NULL;
}
- data->proc = block_processor_create(super->block_size, cmp, num_jobs,
- data, block_callback);
+ data->proc = sqfs_block_processor_create(super->block_size, cmp,
+ num_jobs, data,
+ block_callback);
data->cmp = cmp;
data->super = super;
data->outfd = outfd;
@@ -510,7 +511,7 @@ data_writer_t *data_writer_create(sqfs_super_t *super, compressor_t *cmp,
void data_writer_destroy(data_writer_t *data)
{
- block_processor_destroy(data->proc);
+ sqfs_block_processor_destroy(data->proc);
free(data->fragments);
free(data);
}
@@ -545,5 +546,5 @@ int data_writer_sync(data_writer_t *data)
return -1;
}
- return block_processor_finish(data->proc);
+ return sqfs_block_processor_finish(data->proc);
}