aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-22 23:37:18 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-22 23:37:18 +0100
commitaecc6dc5a9971eb4f1309f0754b0f213347c4d11 (patch)
tree08de6320e3dbdfff50df2d240b4b0031f428a6d3
parentf1468f6da2dab9c1449f9f5e500159bcf733045e (diff)
Move inode size accounting completely to the block processor
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/common/data_writer.c2
-rw-r--r--lib/sqfs/block_processor/common.c31
-rw-r--r--mkfs/mkfs.c3
-rw-r--r--tar/tar2sqfs.c3
4 files changed, 20 insertions, 19 deletions
diff --git a/lib/common/data_writer.c b/lib/common/data_writer.c
index 8ebd868..0b4dc07 100644
--- a/lib/common/data_writer.c
+++ b/lib/common/data_writer.c
@@ -22,7 +22,7 @@ int write_data_from_file(const char *filename, sqfs_block_processor_t *data,
return -1;
}
- sqfs_inode_get_file_size(inode, &filesz);
+ filesz = file->get_size(file);
for (offset = 0; offset < filesz; offset += diff) {
if (filesz - offset > sizeof(buffer)) {
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c
index ab5d1bc..d855b51 100644
--- a/lib/sqfs/block_processor/common.c
+++ b/lib/sqfs/block_processor/common.c
@@ -7,6 +7,15 @@
#define SQFS_BUILDING_DLL
#include "internal.h"
+static void set_block_size(sqfs_inode_generic_t *inode,
+ sqfs_u32 index, sqfs_u32 size)
+{
+ inode->extra[index] = size;
+
+ if (index >= inode->num_file_blocks)
+ inode->num_file_blocks = index + 1;
+}
+
int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
{
sqfs_u64 location;
@@ -21,10 +30,8 @@ int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
if (blk->flags & SQFS_BLK_IS_SPARSE) {
sqfs_inode_make_extended(blk->inode);
blk->inode->data.file_ext.sparse += blk->size;
- blk->inode->extra[blk->index] = 0;
- if (blk->index >= blk->inode->num_file_blocks)
- blk->inode->num_file_blocks = blk->index + 1;
+ set_block_size(blk->inode, blk->index, 0);
proc->stats.sparse_block_count += 1;
} else if (blk->size != 0) {
@@ -38,11 +45,7 @@ int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
if (err)
return err;
} else {
- blk->inode->extra[blk->index] = size;
-
- if (blk->index >= blk->inode->num_file_blocks)
- blk->inode->num_file_blocks = blk->index + 1;
-
+ set_block_size(blk->inode, blk->index, size);
proc->stats.data_block_count += 1;
}
}
@@ -98,11 +101,8 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
if (frag->flags & SQFS_BLK_IS_SPARSE) {
sqfs_inode_make_extended(frag->inode);
+ set_block_size(frag->inode, frag->index, 0);
frag->inode->data.file_ext.sparse += frag->size;
- frag->inode->extra[frag->index] = 0;
-
- if (frag->index >= frag->inode->num_file_blocks)
- frag->inode->num_file_blocks = frag->index + 1;
proc->stats.sparse_block_count += 1;
return 0;
@@ -206,6 +206,9 @@ int sqfs_block_processor_begin_file(sqfs_block_processor_t *proc,
if (flags & ~SQFS_BLK_USER_SETTABLE_FLAGS)
return SQFS_ERROR_UNSUPPORTED;
+ sqfs_inode_set_file_size(inode, 0);
+ sqfs_inode_set_frag_location(inode, 0xFFFFFFFF, 0xFFFFFFFF);
+
proc->inode = inode;
proc->blk_flags = flags | SQFS_BLK_FIRST_BLOCK;
proc->blk_index = 0;
@@ -216,9 +219,13 @@ int sqfs_block_processor_append(sqfs_block_processor_t *proc, const void *data,
size_t size)
{
sqfs_block_t *new;
+ sqfs_u64 filesize;
size_t diff;
int err;
+ sqfs_inode_get_file_size(proc->inode, &filesize);
+ sqfs_inode_set_file_size(proc->inode, filesize + size);
+
while (size > 0) {
if (proc->blk_current == NULL) {
new = alloc_flex(sizeof(*new), 1, proc->max_block_size);
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index 357dad7..691c754 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -110,9 +110,6 @@ static int pack_files(sqfs_block_processor_t *data, fstree_t *fs,
}
inode->base.type = SQFS_INODE_FILE;
- sqfs_inode_set_file_size(inode, filesize);
- sqfs_inode_set_frag_location(inode, 0xFFFFFFFF, 0xFFFFFFFF);
-
fi->user_ptr = inode;
flags = 0;
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index 51987fe..f505f6b 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -276,9 +276,6 @@ static int write_file(tar_header_decoded_t *hdr, file_info_t *fi,
}
inode->base.type = SQFS_INODE_FILE;
- sqfs_inode_set_file_size(inode, filesize);
- sqfs_inode_set_frag_location(inode, 0xFFFFFFFF, 0xFFFFFFFF);
-
fi->user_ptr = inode;
if (hdr->sparse != NULL) {