aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/sqfs/read_inode.c2
-rw-r--r--lib/sqfs/write_inode.c16
-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
6 files changed, 27 insertions, 38 deletions
diff --git a/lib/sqfs/read_inode.c b/lib/sqfs/read_inode.c
index 10337a7..6da9653 100644
--- a/lib/sqfs/read_inode.c
+++ b/lib/sqfs/read_inode.c
@@ -100,6 +100,7 @@ static sqfs_inode_generic_t *read_inode_file(meta_reader_t *ir,
out->base = *base;
out->data.file = file;
out->block_sizes = (uint32_t *)out->extra;
+ out->num_file_blocks = count;
if (meta_reader_read(ir, out->block_sizes, count * sizeof(uint32_t))) {
free(out);
@@ -143,6 +144,7 @@ static sqfs_inode_generic_t *read_inode_file_ext(meta_reader_t *ir,
out->base = *base;
out->data.file_ext = file;
out->block_sizes = (uint32_t *)out->extra;
+ out->num_file_blocks = count;
if (meta_reader_read(ir, out->block_sizes, count * sizeof(uint32_t))) {
free(out);
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c
index a2d87f9..258f516 100644
--- a/lib/sqfs/write_inode.c
+++ b/lib/sqfs/write_inode.c
@@ -8,21 +8,19 @@
#include "sqfs/inode.h"
-static int write_block_sizes(meta_writer_t *ir, sqfs_inode_generic_t *n,
- size_t file_num_blocks)
+static int write_block_sizes(meta_writer_t *ir, sqfs_inode_generic_t *n)
{
- uint32_t sizes[file_num_blocks];
+ uint32_t sizes[n->num_file_blocks];
size_t i;
- for (i = 0; i < file_num_blocks; ++i)
+ for (i = 0; i < n->num_file_blocks; ++i)
sizes[i] = htole32(n->block_sizes[i]);
return meta_writer_append(ir, sizes,
- sizeof(uint32_t) * file_num_blocks);
+ sizeof(uint32_t) * n->num_file_blocks);
}
-int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n,
- size_t file_num_blocks)
+int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n)
{
sqfs_inode_t base;
@@ -57,7 +55,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n,
};
if (meta_writer_append(ir, &file, sizeof(file)))
return -1;
- return write_block_sizes(ir, n, file_num_blocks);
+ return write_block_sizes(ir, n);
}
case SQFS_INODE_SLINK: {
sqfs_inode_slink_t slink = {
@@ -109,7 +107,7 @@ int meta_writer_write_inode(meta_writer_t *ir, sqfs_inode_generic_t *n,
};
if (meta_writer_append(ir, &file, sizeof(file)))
return -1;
- return write_block_sizes(ir, n, file_num_blocks);
+ return write_block_sizes(ir, n);
}
case SQFS_INODE_EXT_SLINK: {
sqfs_inode_slink_t slink = {
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);