[PATCH v1 2/2] Add API to get on disk size of an inode

Gao Xiang hsiangkao at linux.alibaba.com
Wed Dec 22 12:46:11 AEDT 2021


On Tue, Dec 21, 2021 at 06:28:29AM -0800, Kelvin Zhang wrote:
> Change-Id: I60fa9346737b14418bd3fa1d12f760aaf0a0cca5
> Signed-off-by: Kelvin Zhang <zhangkelvin at google.com>

The same to the previous patch.

Also could we remove dump_get_occupied_size() entirely?

Thanks,
Gao Xiang

> ---
>  dump/main.c              |  4 ++--
>  include/erofs/internal.h |  2 ++
>  lib/data.c               | 21 +++++++++++++++++++++
>  3 files changed, 25 insertions(+), 2 deletions(-)
> 
> diff --git a/dump/main.c b/dump/main.c
> index 71b44b4..cdde561 100644
> --- a/dump/main.c
> +++ b/dump/main.c
> @@ -175,7 +175,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 dump_get_occupied_size(struct erofs_inode *inode,
>  		erofs_off_t *size)
>  {
>  	*size = 0;
> @@ -291,7 +291,7 @@ static int erofs_read_dirent(struct erofs_dirent *de,
>  		return err;
>  	}
>  
> -	err = erofs_get_occupied_size(&inode, &occupied_size);
> +	err = dump_get_occupied_size(&inode, &occupied_size);
>  	if (err) {
>  		erofs_err("get file size failed\n");
>  		return err;
> diff --git a/include/erofs/internal.h b/include/erofs/internal.h
> index 947304f..8f13e69 100644
> --- a/include/erofs/internal.h
> +++ b/include/erofs/internal.h
> @@ -320,6 +320,8 @@ 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);
> +int erofs_get_occupied_size(const struct erofs_inode *inode,
> +			    erofs_off_t *size);
>  /* zmap.c */
>  int z_erofs_fill_inode(struct erofs_inode *vi);
>  int z_erofs_map_blocks_iter(struct erofs_inode *vi,
> diff --git a/lib/data.c b/lib/data.c
> index 27710f9..92e54b5 100644
> --- a/lib/data.c
> +++ b/lib/data.c
> @@ -320,3 +320,24 @@ int erofs_pread(struct erofs_inode *inode, char *buf,
>  	}
>  	return -EINVAL;
>  }
> +
> +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:
> +		erofs_err("unknown datalayout");
> +		return -1;
> +	}
> +	return 0;
> +}
> -- 
> 2.34.1.307.g9b7440fafd-goog


More information about the Linux-erofs mailing list