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/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/inode.c')
-rw-r--r-- | lib/sqfs/inode.c | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/lib/sqfs/inode.c b/lib/sqfs/inode.c index 815cc0f..bda244b 100644 --- a/lib/sqfs/inode.c +++ b/lib/sqfs/inode.c @@ -36,38 +36,9 @@ static int inverse_type[] = { int sqfs_inode_copy(const sqfs_inode_generic_t *src, sqfs_inode_generic_t **out) { - sqfs_inode_generic_t *copy; - size_t size = sizeof(*src); + size_t size = sizeof(*src) + src->payload_bytes_used; + sqfs_inode_generic_t *copy = calloc(1, size); - switch (src->base.type) { - case SQFS_INODE_FILE: - case SQFS_INODE_EXT_FILE: - size += src->num_file_blocks; - break; - case SQFS_INODE_DIR: - case SQFS_INODE_EXT_DIR: - size += src->num_dir_idx_bytes; - break; - case SQFS_INODE_SLINK: - size += src->data.slink.target_size; - break; - case SQFS_INODE_EXT_SLINK: - size += src->data.slink_ext.target_size; - break; - case SQFS_INODE_BDEV: - case SQFS_INODE_CDEV: - case SQFS_INODE_FIFO: - case SQFS_INODE_SOCKET: - case SQFS_INODE_EXT_BDEV: - case SQFS_INODE_EXT_CDEV: - case SQFS_INODE_EXT_FIFO: - case SQFS_INODE_EXT_SOCKET: - break; - default: - return SQFS_ERROR_CORRUPTED; - } - - copy = calloc(1, size); if (copy == NULL) return SQFS_ERROR_ALLOC; @@ -406,7 +377,7 @@ int sqfs_inode_unpack_dir_index_entry(const sqfs_inode_generic_t *inode, ptr = (char *)inode->extra; for (;;) { - if (offset >= inode->num_dir_idx_bytes) + if (offset >= inode->payload_bytes_used) return SQFS_ERROR_OUT_OF_BOUNDS; if (index == 0) |