From c924d87a4cbbeb93825f34f997add1ca4573a368 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 23 Feb 2020 03:44:33 +0100 Subject: 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 --- include/sqfs/inode.h | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'include/sqfs') diff --git a/include/sqfs/inode.h b/include/sqfs/inode.h index 17df022..0323bef 100644 --- a/include/sqfs/inode.h +++ b/include/sqfs/inode.h @@ -483,15 +483,21 @@ struct sqfs_inode_generic_t { sqfs_inode_t base; /** - * @brief For file inodes, stores the number of blocks used. + * @brief Maximum number of available data bytes in the payload. + * + * This is used for dynamically growing an inode. The actual number + * of used payload bytes is stored in @ref payload_bytes_used. */ - size_t num_file_blocks; + sqfs_u32 payload_bytes_available; /** - * @brief For extended directory inodes, stores the number of payload - * bytes following for the directory index. + * @brief Number of used data bytes in the payload. + * + * For file inodes, stores the number of blocks used. For extended + * directory inodes, stores the number of payload bytes following + * for the directory index. */ - size_t num_dir_idx_bytes; + sqfs_u32 payload_bytes_used; /** * @brief Type specific inode data. @@ -524,6 +530,19 @@ struct sqfs_inode_generic_t { extern "C" { #endif +/** + * @brief Get the number of file blocks in a regular file inode. + * + * @param inode A pointer to an inode. + * + * @return The number of blocks. + */ +static SQFS_INLINE +size_t sqfs_inode_get_file_block_count(const sqfs_inode_generic_t *inode) +{ + return inode->payload_bytes_used / sizeof(sqfs_u32); +} + /** * @brief Create a deep copy of a generic inode. * -- cgit v1.2.3