[PATCH v2 3/4] erofs-utils: add erofs_read_metadata() helper
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Aug 16 13:58:36 AEST 2023
On 2023/8/16 11:49, Jingbo Xu wrote:
> Add erofs_read_metadata() helper reading variable-sized metadata from
> inode specified by @nid. Read from meta inode if @nid is 0.
>
> Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
> ---
> include/erofs/internal.h | 2 +
> lib/data.c | 84 ++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 86 insertions(+)
>
> diff --git a/include/erofs/internal.h b/include/erofs/internal.h
> index a04e6a6..3e7319d 100644
> --- a/include/erofs/internal.h
> +++ b/include/erofs/internal.h
> @@ -364,6 +364,8 @@ int erofs_read_one_data(struct erofs_inode *inode, struct erofs_map_blocks *map,
> int z_erofs_read_one_data(struct erofs_inode *inode,
> struct erofs_map_blocks *map, char *raw, char *buffer,
> erofs_off_t skip, erofs_off_t length, bool trimmed);
> +void *erofs_read_metadata(struct erofs_sb_info *sbi, erofs_nid_t nid,
> + erofs_off_t *offset, int *lengthp);
>
> static inline int erofs_get_occupied_size(const struct erofs_inode *inode,
> erofs_off_t *size)
> diff --git a/lib/data.c b/lib/data.c
> index a172bb5..3ec5330 100644
> --- a/lib/data.c
> +++ b/lib/data.c
> @@ -372,3 +372,87 @@ int erofs_pread(struct erofs_inode *inode, char *buf,
> }
> return -EINVAL;
> }
> +
> +static void *erofs_read_meta(struct erofs_sb_info *sbi, erofs_nid_t nid,
> + erofs_off_t *offset, int *lengthp)
erofs_read_metadata_nid?
> +{
> + struct erofs_inode vi = { .sbi = sbi, .nid = nid };
> + __le16 __len;
> + int ret, len;
> + char *buffer;
> +
> + ret = erofs_read_inode_from_disk(&vi);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + *offset = round_up(*offset, 4);
> + ret = erofs_pread(&vi, (void *)&__len, sizeof(__le16), *offset);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + len = le16_to_cpu(__len);
> + if (!len)
> + return ERR_PTR(-EFSCORRUPTED);
> +
> + buffer = malloc(len);
> + if (!buffer)
> + return ERR_PTR(-ENOMEM);
> + *offset += sizeof(__le16);
> + *lengthp = len;
> +
> + ret = erofs_pread(&vi, buffer, len, *offset);
> + if (ret) {
> + free(buffer);
> + return ERR_PTR(ret);
> + }
> + *offset += len;
> + return buffer;
> +}
> +
> +static void *erofs_read_metainode(struct erofs_sb_info *sbi,
> + erofs_off_t *offset, int *lengthp)
erofs_read_metadata_bdi?
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list