summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-09 01:05:00 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-09 01:13:37 +0100
commitda3add97f8d4a1bb4d14989f5bd0b6f5f7bc9891 (patch)
treeafe96571227a40562a60245a7f521b131b540b50
parent940c3e3333ba0063f536dfbecbb77d070dbcc87a (diff)
Move block writer and fragment table management out of block processor
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--include/common.h3
-rw-r--r--include/sqfs/block_processor.h28
-rw-r--r--lib/common/writer.c28
-rw-r--r--lib/sqfs/block_processor/common.c25
-rw-r--r--lib/sqfs/block_processor/internal.h7
-rw-r--r--lib/sqfs/block_processor/serial.c6
-rw-r--r--lib/sqfs/block_processor/winpthread.c12
7 files changed, 46 insertions, 63 deletions
diff --git a/include/common.h b/include/common.h
index bf4bc33..f906c27 100644
--- a/include/common.h
+++ b/include/common.h
@@ -20,6 +20,7 @@
#include "sqfs/data_reader.h"
#include "sqfs/block_processor.h"
#include "sqfs/block_writer.h"
+#include "sqfs/frag_table.h"
#include "sqfs/dir_writer.h"
#include "sqfs/dir_reader.h"
#include "sqfs/block.h"
@@ -46,6 +47,8 @@ typedef struct {
} block_processor_stats_t;
typedef struct {
+ sqfs_block_writer_t *blkwr;
+ sqfs_frag_table_t *fragtbl;
sqfs_block_processor_t *data;
sqfs_dir_writer_t *dirwr;
sqfs_meta_writer_t *dm;
diff --git a/include/sqfs/block_processor.h b/include/sqfs/block_processor.h
index a1e6f2b..68d1c23 100644
--- a/include/sqfs/block_processor.h
+++ b/include/sqfs/block_processor.h
@@ -61,9 +61,9 @@ extern "C" {
* @param max_backlog The maximum number of blocks currently in flight. When
* trying to add more, enqueueing blocks until the in-flight
* block count drops below the threshold.
- * @param devblksz File can optionally be allgined to device block size. This
- * specifies the desired alignment.
- * @param file The output file to write the finished blocks to.
+ * @param wr A block writer to send to finished blocks to.
+ * @param tbl A fragment table to use for storing fragment and fragment block
+ * locations.
*
* @return A pointer to a data writer object on success, NULL on allocation
* failure or on failure to create and initialize the worker threads.
@@ -73,8 +73,8 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
sqfs_compressor_t *cmp,
unsigned int num_workers,
size_t max_backlog,
- size_t devblksz,
- sqfs_file_t *file);
+ sqfs_block_writer_t *wr,
+ sqfs_frag_table_t *tbl);
/**
* @brief Destroy a data writer and free all memory used by it.
@@ -166,24 +166,6 @@ SQFS_API int sqfs_block_processor_end_file(sqfs_block_processor_t *proc);
SQFS_API int sqfs_block_processor_finish(sqfs_block_processor_t *proc);
/**
- * @brief Write the completed fragment table to disk.
- *
- * @memberof sqfs_block_processor_t
- *
- * Call this after producing the inode and directory table to generate
- * the fragment table for the squashfs image.
- *
- * @param proc A pointer to a data writer object.
- * @param super A pointer to a super block to write information about the
- * fragment table to.
- *
- * @return Zero on success, an @ref E_SQFS_ERROR value on failure.
- */
-SQFS_API
-int sqfs_block_processor_write_fragment_table(sqfs_block_processor_t *proc,
- sqfs_super_t *super);
-
-/**
* @brief Register a set of hooks to be invoked when writing blocks to disk.
*
* @memberof sqfs_block_processor_t
diff --git a/lib/common/writer.c b/lib/common/writer.c
index ed3ebbd..7f69752 100644
--- a/lib/common/writer.c
+++ b/lib/common/writer.c
@@ -123,14 +123,26 @@ int sqfs_writer_init(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *wrcfg)
if (ret > 0)
sqfs->super.flags |= SQFS_FLAG_COMPRESSOR_OPTIONS;
+ sqfs->blkwr = sqfs_block_writer_create(sqfs->outfile,
+ wrcfg->devblksize, 0);
+ if (sqfs->blkwr == NULL) {
+ perror("creating block writer");
+ goto fail_cmp;
+ }
+
+ sqfs->fragtbl = sqfs_frag_table_create(0);
+ if (sqfs->fragtbl == NULL) {
+ perror("creating fragment table");
+ goto fail_blkwr;
+ }
+
sqfs->data = sqfs_block_processor_create(sqfs->super.block_size,
sqfs->cmp, wrcfg->num_jobs,
wrcfg->max_backlog,
- wrcfg->devblksize,
- sqfs->outfile);
+ sqfs->blkwr, sqfs->fragtbl);
if (sqfs->data == NULL) {
perror("creating data block processor");
- goto fail_cmp;
+ goto fail_fragtbl;
}
memset(&sqfs->stats, 0, sizeof(sqfs->stats));
@@ -188,6 +200,10 @@ fail_id:
sqfs_id_table_destroy(sqfs->idtbl);
fail_data:
sqfs_block_processor_destroy(sqfs->data);
+fail_fragtbl:
+ sqfs_frag_table_destroy(sqfs->fragtbl);
+fail_blkwr:
+ sqfs_block_writer_destroy(sqfs->blkwr);
fail_cmp:
sqfs->cmp->destroy(sqfs->cmp);
fail_fs:
@@ -221,8 +237,8 @@ int sqfs_writer_finish(sqfs_writer_t *sqfs, const sqfs_writer_cfg_t *cfg)
if (!cfg->quiet)
fputs("Writing fragment table...\n", stdout);
- ret = sqfs_block_processor_write_fragment_table(sqfs->data,
- &sqfs->super);
+ ret = sqfs_frag_table_write(sqfs->fragtbl, sqfs->outfile,
+ &sqfs->super, sqfs->cmp);
if (ret) {
sqfs_perror(cfg->filename, "writing fragment table", ret);
return -1;
@@ -293,6 +309,8 @@ void sqfs_writer_cleanup(sqfs_writer_t *sqfs)
sqfs_meta_writer_destroy(sqfs->im);
sqfs_id_table_destroy(sqfs->idtbl);
sqfs_block_processor_destroy(sqfs->data);
+ sqfs_block_writer_destroy(sqfs->blkwr);
+ sqfs_frag_table_destroy(sqfs->fragtbl);
sqfs->cmp->destroy(sqfs->cmp);
fstree_cleanup(&sqfs->fs);
sqfs->outfile->destroy(sqfs->outfile);
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c
index 806a595..23991ea 100644
--- a/lib/sqfs/block_processor/common.c
+++ b/lib/sqfs/block_processor/common.c
@@ -20,30 +20,20 @@ void free_blk_list(sqfs_block_t *list)
int block_processor_init(sqfs_block_processor_t *proc, size_t max_block_size,
sqfs_compressor_t *cmp, unsigned int num_workers,
- size_t max_backlog, size_t devblksz, sqfs_file_t *file)
+ size_t max_backlog, sqfs_block_writer_t *wr,
+ sqfs_frag_table_t *tbl)
{
proc->max_block_size = max_block_size;
proc->num_workers = num_workers;
proc->max_backlog = max_backlog;
proc->cmp = cmp;
- proc->file = file;
-
- proc->frag_tbl = sqfs_frag_table_create(0);
- if (proc->frag_tbl == NULL)
- return -1;
-
- proc->wr = sqfs_block_writer_create(file, devblksz, 0);
- if (proc->wr == NULL)
- return -1;
+ proc->frag_tbl = tbl;
+ proc->wr = wr;
return 0;
}
void block_processor_cleanup(sqfs_block_processor_t *proc)
{
- if (proc->frag_tbl != NULL)
- sqfs_frag_table_destroy(proc->frag_tbl);
- if (proc->wr != NULL)
- sqfs_block_writer_destroy(proc->wr);
free_blk_list(proc->queue);
free_blk_list(proc->done);
free(proc->blk_current);
@@ -51,13 +41,6 @@ void block_processor_cleanup(sqfs_block_processor_t *proc)
free(proc);
}
-int sqfs_block_processor_write_fragment_table(sqfs_block_processor_t *proc,
- sqfs_super_t *super)
-{
- return sqfs_frag_table_write(proc->frag_tbl, proc->file,
- super, proc->cmp);
-}
-
int sqfs_block_processor_set_hooks(sqfs_block_processor_t *proc, void *user_ptr,
const sqfs_block_hooks_t *hooks)
{
diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h
index 16f0edb..09e879b 100644
--- a/lib/sqfs/block_processor/internal.h
+++ b/lib/sqfs/block_processor/internal.h
@@ -61,10 +61,7 @@ struct sqfs_block_processor_t {
unsigned int num_workers;
size_t max_backlog;
- sqfs_file_t *file;
-
sqfs_frag_table_t *frag_tbl;
-
sqfs_compressor_t *cmp;
sqfs_block_t *frag_block;
@@ -102,8 +99,8 @@ SQFS_INTERNAL void free_blk_list(sqfs_block_t *list);
SQFS_INTERNAL
int block_processor_init(sqfs_block_processor_t *proc, size_t max_block_size,
sqfs_compressor_t *cmp, unsigned int num_workers,
- size_t max_backlog, size_t devblksz,
- sqfs_file_t *file);
+ size_t max_backlog, sqfs_block_writer_t *wr,
+ sqfs_frag_table_t *tbl);
SQFS_INTERNAL void block_processor_cleanup(sqfs_block_processor_t *proc);
diff --git a/lib/sqfs/block_processor/serial.c b/lib/sqfs/block_processor/serial.c
index eedb19c..e18b67e 100644
--- a/lib/sqfs/block_processor/serial.c
+++ b/lib/sqfs/block_processor/serial.c
@@ -11,8 +11,8 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
sqfs_compressor_t *cmp,
unsigned int num_workers,
size_t max_backlog,
- size_t devblksz,
- sqfs_file_t *file)
+ sqfs_block_writer_t *wr,
+ sqfs_frag_table_t *tbl)
{
sqfs_block_processor_t *proc;
@@ -22,7 +22,7 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
return NULL;
if (block_processor_init(proc, max_block_size, cmp, num_workers,
- max_backlog, devblksz, file)) {
+ max_backlog, wr, tbl)) {
block_processor_cleanup(proc);
return NULL;
}
diff --git a/lib/sqfs/block_processor/winpthread.c b/lib/sqfs/block_processor/winpthread.c
index b16a17c..85416ab 100644
--- a/lib/sqfs/block_processor/winpthread.c
+++ b/lib/sqfs/block_processor/winpthread.c
@@ -98,8 +98,8 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
sqfs_compressor_t *cmp,
unsigned int num_workers,
size_t max_backlog,
- size_t devblksz,
- sqfs_file_t *file)
+ sqfs_block_writer_t *wr,
+ sqfs_frag_table_t *tbl)
{
sqfs_block_processor_t *proc;
unsigned int i;
@@ -117,7 +117,7 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
InitializeConditionVariable(&proc->done_cond);
if (block_processor_init(proc, max_block_size, cmp, num_workers,
- max_backlog, devblksz, file)) {
+ max_backlog, wr, tbl)) {
goto fail;
}
@@ -178,8 +178,8 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
sqfs_compressor_t *cmp,
unsigned int num_workers,
size_t max_backlog,
- size_t devblksz,
- sqfs_file_t *file)
+ sqfs_block_writer_t *wr,
+ sqfs_frag_table_t *tbl)
{
sqfs_block_processor_t *proc;
sigset_t set, oldset;
@@ -199,7 +199,7 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
proc->done_cond = (pthread_cond_t)PTHREAD_COND_INITIALIZER;
if (block_processor_init(proc, max_block_size, cmp, num_workers,
- max_backlog, devblksz, file)) {
+ max_backlog, wr, tbl)) {
goto fail_init;
}