summaryrefslogtreecommitdiff
path: root/lib
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
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')
-rw-r--r--lib/fstree/deduplicate.c12
-rw-r--r--lib/sqfs/data_writer.c34
2 files changed, 22 insertions, 24 deletions
diff --git a/lib/fstree/deduplicate.c b/lib/fstree/deduplicate.c
index 7390a2c..00815a6 100644
--- a/lib/fstree/deduplicate.c
+++ b/lib/fstree/deduplicate.c
@@ -16,10 +16,8 @@ file_info_t *fragment_by_chksum(file_info_t *fi, uint32_t chksum,
file_info_t *it;
for (it = list; it != NULL; it = it->next) {
- if (it == fi) {
- it = NULL;
- break;
- }
+ if (it == fi)
+ continue;
if (!(it->flags & FILE_FLAG_HAS_FRAGMENT))
continue;
@@ -82,10 +80,8 @@ uint64_t find_equal_blocks(file_info_t *file, file_info_t *list,
}
for (it = list; it != NULL; it = it->next) {
- if (it == file) {
- it = NULL;
- break;
- }
+ if (it == file)
+ continue;
if (it->flags & FILE_FLAG_BLOCKS_ARE_DUPLICATE)
continue;
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);