summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-12 12:34:23 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-12 15:45:00 +0200
commit3038bf18d12b9d97d13b4846fed301c054cd793f (patch)
tree0e17a686df213609134d69030ebced034cdc3bef
parente4dd1ed8c9cea1761092e8206d572f60a9d95a58 (diff)
Simplify writer code for files without a fragment
The data writer sparse block code can take advantage that it can add a block size instead of a fragment and doesn't have to initialize the framgent location. In return, the tree node to inode serialization code doesn't need a special case for sparse file anymore and can now also handle files that are forced to not have a fragment. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/sqfs/data_writer.c8
-rw-r--r--lib/sqfs/write_inode.c15
2 files changed, 7 insertions, 16 deletions
diff --git a/lib/sqfs/data_writer.c b/lib/sqfs/data_writer.c
index 8492c98..557b85b 100644
--- a/lib/sqfs/data_writer.c
+++ b/lib/sqfs/data_writer.c
@@ -118,13 +118,7 @@ static int flush_data_block(data_writer_t *data, size_t size, file_info_t *fi)
uint32_t out;
if (is_zero_block(data->block, size)) {
- if (size < data->super->block_size) {
- fi->fragment_offset = 0xFFFFFFFF;
- fi->fragment = 0xFFFFFFFF;
- } else {
- fi->blocksizes[data->block_idx++] = 0;
- }
-
+ fi->blocksizes[data->block_idx++] = 0;
fi->sparse += size;
return 0;
}
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c
index ac33b60..611b0e1 100644
--- a/lib/sqfs/write_inode.c
+++ b/lib/sqfs/write_inode.c
@@ -77,19 +77,16 @@ static int get_type(tree_node_t *node)
static int write_file_blocks(fstree_t *fs, file_info_t *fi, meta_writer_t *im)
{
+ uint64_t i, count = fi->size / fs->block_size;
uint32_t bs;
- uint64_t i;
-
- for (i = 0; i < fi->size / fs->block_size; ++i) {
- bs = htole32(fi->blocksizes[i]);
-
- if (meta_writer_append(im, &bs, sizeof(bs)))
- return -1;
- }
if ((fi->size % fs->block_size) != 0 &&
(fi->fragment == 0xFFFFFFFF || fi->fragment_offset == 0xFFFFFFFF)) {
- bs = htole32(0);
+ ++count;
+ }
+
+ for (i = 0; i < count; ++i) {
+ bs = htole32(fi->blocksizes[i]);
if (meta_writer_append(im, &bs, sizeof(bs)))
return -1;