summaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-16 19:52:42 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-18 22:44:39 +0200
commitb45850388ea5505f4fd50cd659abe2f02aeca0b5 (patch)
tree994f878caf990d1569831762f0b0f4d787ab9839 /lib/sqfs
parent1a95478b8d340c8b6b9dbff4f38f9293388fd1a3 (diff)
cleanup: internalize deduplication list in data_writer
This change removes the need for passing a list of files around for deduplication. Also the deduplication code no longer needs to worry about order, since the file being deduplicated is only added after deduplication is done. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/data_writer.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/lib/sqfs/data_writer.c b/lib/sqfs/data_writer.c
index 0eeecc3..ea650bd 100644
--- a/lib/sqfs/data_writer.c
+++ b/lib/sqfs/data_writer.c
@@ -31,6 +31,7 @@ struct data_writer_t {
int block_idx;
+ file_info_t *list;
sqfs_super_t *super;
compressor_t *cmp;
int outfd;
@@ -132,10 +133,10 @@ int data_writer_flush_fragments(data_writer_t *data)
return 0;
}
-static int deduplicate_data(data_writer_t *data, file_info_t *fi,
- file_info_t *list)
+static int deduplicate_data(data_writer_t *data, file_info_t *fi)
{
- uint64_t ref = find_equal_blocks(fi, list, data->super->block_size);
+ uint64_t ref = find_equal_blocks(fi, data->list,
+ data->super->block_size);
if (ref > 0) {
data->super->bytes_used = fi->startblock;
@@ -159,7 +160,7 @@ fail_truncate:
}
static int flush_data_block(data_writer_t *data, size_t size, bool is_last,
- file_info_t *fi, int flags, file_info_t *list)
+ file_info_t *fi, int flags)
{
uint32_t out, chksum;
file_info_t *ref;
@@ -169,7 +170,7 @@ static int flush_data_block(data_writer_t *data, size_t size, bool is_last,
fi->blocks[data->block_idx].chksum = 0;
fi->sparse += size;
data->block_idx++;
- return is_last ? deduplicate_data(data, fi, list) : 0;
+ return is_last ? deduplicate_data(data, fi) : 0;
}
chksum = update_crc32(0, data->block, size);
@@ -177,10 +178,10 @@ static int flush_data_block(data_writer_t *data, size_t size, bool is_last,
if (size < data->super->block_size && !(flags & DW_DONT_FRAGMENT)) {
fi->flags |= FILE_FLAG_HAS_FRAGMENT;
- if (deduplicate_data(data, fi, list))
+ if (deduplicate_data(data, fi))
return -1;
- ref = fragment_by_chksum(fi, chksum, size, list,
+ ref = fragment_by_chksum(chksum, size, data->list,
data->super->block_size);
if (ref != NULL) {
@@ -211,7 +212,7 @@ static int flush_data_block(data_writer_t *data, size_t size, bool is_last,
fi->blocks[data->block_idx].size = out;
data->block_idx++;
- if (is_last && deduplicate_data(data, fi, list) != 0)
+ if (is_last && deduplicate_data(data, fi) != 0)
return -1;
}
@@ -236,16 +237,18 @@ fail_seek:
return -1;
}
-static int end_file(data_writer_t *data, int flags)
+static int end_file(data_writer_t *data, file_info_t *fi, int flags)
{
if ((flags & DW_ALLIGN_DEVBLK) && allign_file(data) != 0)
return -1;
+ fi->next = data->list;
+ data->list = fi;
return 0;
}
int write_data_from_fd(data_writer_t *data, file_info_t *fi,
- int infd, int flags, file_info_t *list)
+ int infd, int flags)
{
uint64_t count;
bool is_last;
@@ -266,16 +269,15 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi,
if (read_data(fi->input_file, infd, data->block, diff))
return -1;
- if (flush_data_block(data, diff, is_last, fi, flags, list))
+ if (flush_data_block(data, diff, is_last, fi, flags))
return -1;
}
- return end_file(data, flags);
+ return end_file(data, fi, flags);
}
int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi,
- int infd, sparse_map_t *map, int flags,
- file_info_t *list)
+ int infd, sparse_map_t *map, int flags)
{
size_t start, count, diff;
sparse_map_t *m;
@@ -330,11 +332,11 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi,
map = map->next;
}
- if (flush_data_block(data, diff, is_last, fi, flags, list))
+ if (flush_data_block(data, diff, is_last, fi, flags))
return -1;
}
- return end_file(data, flags);
+ return end_file(data, fi, flags);
fail_map_size:
fprintf(stderr, "%s: sparse file map spans beyond file size\n",
fi->input_file);