erofs-utils: lib: Add API to get on disk size of an inode
PATCH v4 1/1 erofs-utils: lib: Add API to get on disk size of an inode
From: Kelvin Zhang <[email protected]>
Marginally improve code re-use. It's quite common for users to query for compressed size of an inode.
Signed-off-by Kelvin Zhang <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
---
Hi Kelvin,
I've removed the print message of API, and return -ENOTSUP instead. Please check out if it's fine with you.
Thanks,
Gao Xiang
dump/main.c | 6 +++--- include/erofs/internal.h | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-)
dump/main.c +3 -3
@@ -176,7 +176,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)return 0 ; } -static int erofs_get_occupied_size (struct erofs_inode *inode, +static int erofsdump_get_occupied_size (struct erofs_inode *inode,erofs_off_t *size) { *size =0 ;
@@ -194,7 +194,7 @@ static int erofs_get_occupied_size(struct erofs_inode *inode,break ;default :erofs_err ("unknown datalayout" ); -return -1 ; +return -ENOTSUP ; }return 0 ; }
@@ -270,7 +270,7 @@ static int erofsdump_readdir(struct erofs_dir_context *ctx) stats.files++; stats.file_category_stat[erofs_mode_to_ftype (vi.i_mode)]++; - err =erofs_get_occupied_size (&vi, &occupied_size); + err =erofsdump_get_occupied_size (&vi, &occupied_size);if (err) {erofs_err ("get file size failed" );return err;
include/erofs/internal.h +21 -0
@@ -320,6 +320,27 @@ int erofs_pread(struct erofs_inode *inode, char *buf,int erofs_map_blocks (struct erofs_inode *inode,struct erofs_map_blocks *map,int flags);int erofs_map_dev (struct erofs_sb_info *sbi,struct erofs_map_dev *map); + +static inline int erofs_get_occupied_size (const struct erofs_inode *inode, +erofs_off_t *size) +{ + *size =0 ; +switch (inode->datalayout) { +case EROFS_INODE_FLAT_INLINE : +case EROFS_INODE_FLAT_PLAIN : +case EROFS_INODE_CHUNK_BASED : + *size = inode->i_size; +break ; +case EROFS_INODE_FLAT_COMPRESSION_LEGACY : +case EROFS_INODE_FLAT_COMPRESSION : + *size = inode->u.i_blocks *EROFS_BLKSIZ ; +break ; +default : +return -ENOTSUP ; + } +return 0 ; +} +/* zmap.c */ int z_erofs_fill_inode (struct erofs_inode *vi); int z_erofs_map_blocks_iter(struct erofs_inode *vi,
Signature · 1 line
2.20.1