diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-02-23 03:44:33 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-02-23 04:02:49 +0100 |
commit | c924d87a4cbbeb93825f34f997add1ca4573a368 (patch) | |
tree | a2497b2954e0f6538cfa669062ab409f16518fc7 /lib/sqfs/write_inode.c | |
parent | 7350bebc4ceee0bf065e73f392edb725f8d0cd14 (diff) |
Unify the payload counters in the sqfs_inode_generic_t
Instead of having seperate counters for blocks, dir index bytes
and having to fiddle out the link target size, simply use a single
value that stores the number of payload bytes used.
A seperate "payload bytes available" is used for dynamically
growing inodes during processing.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/write_inode.c')
-rw-r--r-- | lib/sqfs/write_inode.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/sqfs/write_inode.c b/lib/sqfs/write_inode.c index b5ba905..86ed146 100644 --- a/lib/sqfs/write_inode.c +++ b/lib/sqfs/write_inode.c @@ -14,18 +14,26 @@ #include "compat.h" #include <string.h> +#include <alloca.h> static int write_block_sizes(sqfs_meta_writer_t *ir, const sqfs_inode_generic_t *n) { - sqfs_u32 sizes[n->num_file_blocks]; + sqfs_u32 *sizes; size_t i; - for (i = 0; i < n->num_file_blocks; ++i) + if (n->payload_bytes_used < sizeof(sizes[0])) + return 0; + + if ((n->payload_bytes_used % sizeof(sizes[0])) != 0) + return SQFS_ERROR_CORRUPTED; + + sizes = alloca(n->payload_bytes_used); + + for (i = 0; i < (n->payload_bytes_used / sizeof(sizes[0])); ++i) sizes[i] = htole32(n->extra[i]); - return sqfs_meta_writer_append(ir, sizes, - sizeof(sqfs_u32) * n->num_file_blocks); + return sqfs_meta_writer_append(ir, sizes, n->payload_bytes_used); } static int write_dir_index(sqfs_meta_writer_t *ir, const sqfs_u8 *data, @@ -102,7 +110,7 @@ int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir, ret = sqfs_meta_writer_append(ir, &file, sizeof(file)); if (ret) return ret; - return n->num_file_blocks ? write_block_sizes(ir, n) : 0; + return write_block_sizes(ir, n); } case SQFS_INODE_SLINK: { sqfs_inode_slink_t slink = { @@ -144,7 +152,7 @@ int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir, if (ret) return ret; return write_dir_index(ir, (const sqfs_u8 *)n->extra, - n->num_dir_idx_bytes); + n->payload_bytes_used); } case SQFS_INODE_EXT_FILE: { sqfs_inode_file_ext_t file = { @@ -160,7 +168,7 @@ int sqfs_meta_writer_write_inode(sqfs_meta_writer_t *ir, ret = sqfs_meta_writer_append(ir, &file, sizeof(file)); if (ret) return ret; - return n->num_file_blocks ? write_block_sizes(ir, n) : 0; + return write_block_sizes(ir, n); } case SQFS_INODE_EXT_SLINK: { sqfs_inode_slink_t slink = { |