Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02166EB64DD for ; Wed, 16 Aug 2023 03:58:51 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RQZBL3nTnz3cR1 for ; Wed, 16 Aug 2023 13:58:50 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.132; helo=out30-132.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=lists.ozlabs.org) Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4RQZBG0KpFz2yW8 for ; Wed, 16 Aug 2023 13:58:44 +1000 (AEST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R691e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046051;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0VpuLhpC_1692158318; Received: from 30.221.134.59(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VpuLhpC_1692158318) by smtp.aliyun-inc.com; Wed, 16 Aug 2023 11:58:39 +0800 Message-ID: <9909fa9c-6526-d0d0-550f-d31157923a69@linux.alibaba.com> Date: Wed, 16 Aug 2023 11:58:36 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v2 3/4] erofs-utils: add erofs_read_metadata() helper To: Jingbo Xu , xiang@kernel.org, linux-erofs@lists.ozlabs.org References: <20230816034941.126866-1-jefflexu@linux.alibaba.com> <20230816034941.126866-4-jefflexu@linux.alibaba.com> From: Gao Xiang In-Reply-To: <20230816034941.126866-4-jefflexu@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" 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 > --- > 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