summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sqfs/data_writer/block.c8
-rw-r--r--lib/sqfs/data_writer/common.c32
-rw-r--r--lib/sqfs/data_writer/fragment.c26
-rw-r--r--lib/sqfs/data_writer/internal.h5
4 files changed, 17 insertions, 54 deletions
diff --git a/lib/sqfs/data_writer/block.c b/lib/sqfs/data_writer/block.c
index 5967e59..b45b1ff 100644
--- a/lib/sqfs/data_writer/block.c
+++ b/lib/sqfs/data_writer/block.c
@@ -111,10 +111,10 @@ int process_completed_block(sqfs_data_writer_t *proc, sqfs_block_t *blk)
offset = proc->file->get_size(proc->file);
if (blk->flags & SQFS_BLK_FRAGMENT_BLOCK) {
- offset = htole64(offset);
- proc->fragments[blk->index].start_offset = offset;
- proc->fragments[blk->index].pad0 = 0;
- proc->fragments[blk->index].size = htole32(out);
+ err = sqfs_frag_table_set(proc->frag_tbl, blk->index,
+ offset, out);
+ if (err)
+ return err;
} else {
blk->inode->extra[blk->index] = out;
}
diff --git a/lib/sqfs/data_writer/common.c b/lib/sqfs/data_writer/common.c
index d2bf935..bc6bac4 100644
--- a/lib/sqfs/data_writer/common.c
+++ b/lib/sqfs/data_writer/common.c
@@ -31,6 +31,10 @@ int data_writer_init(sqfs_data_writer_t *proc, size_t max_block_size,
proc->max_blocks = INIT_BLOCK_COUNT;
proc->frag_list_max = INIT_BLOCK_COUNT;
+ proc->frag_tbl = sqfs_frag_table_create(0);
+ if (proc->frag_tbl == NULL)
+ return -1;
+
proc->blocks = alloc_array(sizeof(proc->blocks[0]), proc->max_blocks);
if (proc->blocks == NULL)
return -1;
@@ -45,12 +49,13 @@ int data_writer_init(sqfs_data_writer_t *proc, size_t max_block_size,
void data_writer_cleanup(sqfs_data_writer_t *proc)
{
+ if (proc->frag_tbl != NULL)
+ sqfs_frag_table_destroy(proc->frag_tbl);
free_blk_list(proc->queue);
free_blk_list(proc->done);
free(proc->blk_current);
free(proc->frag_block);
free(proc->frag_list);
- free(proc->fragments);
free(proc->blocks);
free(proc);
}
@@ -58,29 +63,8 @@ void data_writer_cleanup(sqfs_data_writer_t *proc)
int sqfs_data_writer_write_fragment_table(sqfs_data_writer_t *proc,
sqfs_super_t *super)
{
- sqfs_u64 start;
- size_t size;
- int ret;
-
- if (proc->num_fragments == 0) {
- super->fragment_entry_count = 0;
- super->fragment_table_start = 0xFFFFFFFFFFFFFFFFUL;
- super->flags &= ~SQFS_FLAG_ALWAYS_FRAGMENTS;
- super->flags |= SQFS_FLAG_NO_FRAGMENTS;
- return 0;
- }
-
- size = sizeof(proc->fragments[0]) * proc->num_fragments;
- ret = sqfs_write_table(proc->file, proc->cmp,
- proc->fragments, size, &start);
- if (ret)
- return ret;
-
- super->flags &= ~SQFS_FLAG_NO_FRAGMENTS;
- super->flags |= SQFS_FLAG_ALWAYS_FRAGMENTS;
- super->fragment_entry_count = proc->num_fragments;
- super->fragment_table_start = start;
- return 0;
+ return sqfs_frag_table_write(proc->frag_tbl, proc->file,
+ super, proc->cmp);
}
int sqfs_data_writer_set_hooks(sqfs_data_writer_t *proc, void *user_ptr,
diff --git a/lib/sqfs/data_writer/fragment.c b/lib/sqfs/data_writer/fragment.c
index 1957983..70679c9 100644
--- a/lib/sqfs/data_writer/fragment.c
+++ b/lib/sqfs/data_writer/fragment.c
@@ -7,27 +7,6 @@
#define SQFS_BUILDING_DLL
#include "internal.h"
-static int grow_fragment_table(sqfs_data_writer_t *proc)
-{
- size_t newsz;
- void *new;
-
- if (proc->num_fragments >= proc->max_fragments) {
- newsz = proc->max_fragments ? proc->max_fragments * 2 : 16;
-
- 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;
-}
-
static int grow_deduplication_list(sqfs_data_writer_t *proc)
{
size_t new_sz;
@@ -80,6 +59,7 @@ int process_completed_fragment(sqfs_data_writer_t *proc, sqfs_block_t *frag,
sqfs_block_t **blk_out)
{
sqfs_u64 hash;
+ sqfs_u32 index;
size_t i, size;
int err;
@@ -102,7 +82,7 @@ int process_completed_fragment(sqfs_data_writer_t *proc, sqfs_block_t *frag,
if (proc->frag_block == NULL) {
size = sizeof(sqfs_block_t) + proc->max_block_size;
- err = grow_fragment_table(proc);
+ err= sqfs_frag_table_append(proc->frag_tbl, 0, 0, &index);
if (err)
goto fail;
@@ -112,7 +92,7 @@ int process_completed_fragment(sqfs_data_writer_t *proc, sqfs_block_t *frag,
goto fail;
}
- proc->frag_block->index = proc->num_fragments++;
+ proc->frag_block->index = index;
proc->frag_block->flags = SQFS_BLK_FRAGMENT_BLOCK;
}
diff --git a/lib/sqfs/data_writer/internal.h b/lib/sqfs/data_writer/internal.h
index 8a3f4d7..5042f0a 100644
--- a/lib/sqfs/data_writer/internal.h
+++ b/lib/sqfs/data_writer/internal.h
@@ -10,6 +10,7 @@
#include "config.h"
#include "sqfs/data_writer.h"
+#include "sqfs/frag_table.h"
#include "sqfs/compressor.h"
#include "sqfs/inode.h"
#include "sqfs/table.h"
@@ -80,9 +81,7 @@ struct sqfs_data_writer_t {
size_t devblksz;
sqfs_file_t *file;
- sqfs_fragment_t *fragments;
- size_t num_fragments;
- size_t max_fragments;
+ sqfs_frag_table_t *frag_tbl;
sqfs_u64 start;