summaryrefslogtreecommitdiff
path: root/lib/sqfshelper
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfshelper')
-rw-r--r--lib/sqfshelper/deserialize_fstree.c4
-rw-r--r--lib/sqfshelper/serialize_fstree.c7
-rw-r--r--lib/sqfshelper/tree_node_from_inode.c31
-rw-r--r--lib/sqfshelper/tree_node_to_inode.c5
4 files changed, 18 insertions, 29 deletions
diff --git a/lib/sqfshelper/deserialize_fstree.c b/lib/sqfshelper/deserialize_fstree.c
index 98c59fb..47410b0 100644
--- a/lib/sqfshelper/deserialize_fstree.c
+++ b/lib/sqfshelper/deserialize_fstree.c
@@ -133,7 +133,7 @@ static int fill_dir(meta_reader_t *ir, meta_reader_t *dr, tree_node_t *root,
n = tree_node_from_inode(inode, idtbl,
(char *)ent->name,
- super->block_size);
+ fs->block_size);
if (n == NULL) {
free(ent);
@@ -257,7 +257,7 @@ int deserialize_fstree(fstree_t *out, sqfs_super_t *super, compressor_t *cmp,
out->defaults.st_mode = 0755;
out->defaults.st_mtime = super->modification_time;
- out->root = tree_node_from_inode(root, idtbl, "", super->block_size);
+ out->root = tree_node_from_inode(root, idtbl, "", out->block_size);
if (out->root == NULL) {
free(root);
diff --git a/lib/sqfshelper/serialize_fstree.c b/lib/sqfshelper/serialize_fstree.c
index f8f3913..8e87354 100644
--- a/lib/sqfshelper/serialize_fstree.c
+++ b/lib/sqfshelper/serialize_fstree.c
@@ -47,10 +47,10 @@ int sqfs_serialize_fstree(int outfd, sqfs_super_t *super, fstree_t *fs,
sqfs_inode_generic_t *inode;
sqfs_dir_writer_t *dirwr;
meta_writer_t *im, *dm;
- size_t i, count;
uint32_t offset;
uint64_t block;
int ret = -1;
+ size_t i;
im = meta_writer_create(outfd, cmp, false);
if (im == NULL)
@@ -70,8 +70,7 @@ int sqfs_serialize_fstree(int outfd, sqfs_super_t *super, fstree_t *fs,
goto out;
}
- inode = tree_node_to_inode(fs, idtbl, fs->inode_table[i],
- &count);
+ inode = tree_node_to_inode(fs, idtbl, fs->inode_table[i]);
if (inode == NULL)
goto out;
@@ -83,7 +82,7 @@ int sqfs_serialize_fstree(int outfd, sqfs_super_t *super, fstree_t *fs,
meta_writer_get_position(im, &block, &offset);
fs->inode_table[i]->inode_ref = (block << 16) | offset;
- if (meta_writer_write_inode(im, inode, count)) {
+ if (meta_writer_write_inode(im, inode)) {
free(inode);
goto out;
}
diff --git a/lib/sqfshelper/tree_node_from_inode.c b/lib/sqfshelper/tree_node_from_inode.c
index e77266a..d8b3361 100644
--- a/lib/sqfshelper/tree_node_from_inode.c
+++ b/lib/sqfshelper/tree_node_from_inode.c
@@ -12,11 +12,9 @@
#include <string.h>
#include <stdio.h>
-static size_t compute_size(sqfs_inode_generic_t *inode, const char *name,
- size_t block_size)
+static size_t compute_size(sqfs_inode_generic_t *inode, const char *name)
{
size_t size = sizeof(tree_node_t) + strlen(name) + 1;
- size_t block_count = 0;
switch (inode->base.type) {
case SQFS_INODE_DIR:
@@ -24,16 +22,10 @@ static size_t compute_size(sqfs_inode_generic_t *inode, const char *name,
size += sizeof(dir_info_t);
break;
case SQFS_INODE_FILE:
- size += sizeof(file_info_t);
- block_count = inode->data.file.file_size / block_size;
- if ((inode->data.file.file_size % block_size) != 0)
- ++block_count;
- break;
case SQFS_INODE_EXT_FILE:
size += sizeof(file_info_t);
- block_count = inode->data.file_ext.file_size / block_size;
- if ((inode->data.file_ext.file_size % block_size) != 0)
- ++block_count;
+ size += inode->num_file_blocks *
+ sizeof(((file_info_t *)0)->blocks[0]);
break;
case SQFS_INODE_SLINK:
case SQFS_INODE_EXT_SLINK:
@@ -43,26 +35,25 @@ static size_t compute_size(sqfs_inode_generic_t *inode, const char *name,
break;
}
- return size + block_count * sizeof(((file_info_t *)0)->blocks[0]);
+ return size;
}
static void copy_block_sizes(sqfs_inode_generic_t *inode, tree_node_t *out,
size_t block_size)
{
- size_t i, block_count = out->data.file->size / block_size;
+ size_t i;
if ((out->data.file->size % block_size) != 0) {
- if (out->data.file->fragment == 0xFFFFFFFF ||
- out->data.file->fragment_offset == 0xFFFFFFFF) {
- ++block_count;
- } else {
+ if (out->data.file->fragment != 0xFFFFFFFF &&
+ out->data.file->fragment_offset != 0xFFFFFFFF) {
out->data.file->flags |= FILE_FLAG_HAS_FRAGMENT;
}
}
- out->name += block_count * sizeof(out->data.file->blocks[0]);
+ out->name += inode->num_file_blocks *
+ sizeof(out->data.file->blocks[0]);
- for (i = 0; i < block_count; ++i)
+ for (i = 0; i < inode->num_file_blocks; ++i)
out->data.file->blocks[i].size = inode->block_sizes[i];
}
@@ -73,7 +64,7 @@ tree_node_t *tree_node_from_inode(sqfs_inode_generic_t *inode,
{
tree_node_t *out;
- out = calloc(1, compute_size(inode, name, block_size));
+ out = calloc(1, compute_size(inode, name));
if (out == NULL) {
perror("converting inode to fs tree node");
return NULL;
diff --git a/lib/sqfshelper/tree_node_to_inode.c b/lib/sqfshelper/tree_node_to_inode.c
index 21e30dd..d3346e2 100644
--- a/lib/sqfshelper/tree_node_to_inode.c
+++ b/lib/sqfshelper/tree_node_to_inode.c
@@ -82,8 +82,7 @@ static int get_type(tree_node_t *node)
}
sqfs_inode_generic_t *tree_node_to_inode(fstree_t *fs, id_table_t *idtbl,
- tree_node_t *node,
- size_t *file_num_blocks)
+ tree_node_t *node)
{
size_t i, extra = 0, block_count = 0;
sqfs_inode_generic_t *inode;
@@ -220,7 +219,7 @@ sqfs_inode_generic_t *tree_node_to_inode(fstree_t *fs, id_table_t *idtbl,
goto fail;
}
- *file_num_blocks = block_count;
+ inode->num_file_blocks = block_count;
return inode;
fail:
free(inode);