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 CCFE1C6FD1D for ; Fri, 17 Mar 2023 08:50:59 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4PdHsZ2plVz3f3M for ; Fri, 17 Mar 2023 19:50:58 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.alibaba.com (client-ip=115.124.30.124; helo=out30-124.freemail.mail.aliyun.com; envelope-from=hsiangkao@linux.alibaba.com; receiver=) Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) (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 4PdHsT1szWz3cg0 for ; Fri, 17 Mar 2023 19:50:52 +1100 (AEDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;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=2;SR=0;TI=SMTPD_---0Ve2QyR8_1679043047; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0Ve2QyR8_1679043047) by smtp.aliyun-inc.com; Fri, 17 Mar 2023 16:50:49 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Subject: [PATCH 2/2] erofs-utils: fix up nlink for d_type unsupported fses Date: Fri, 17 Mar 2023 16:50:45 +0800 Message-Id: <20230317085045.16263-2-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 In-Reply-To: <20230317085045.16263-1-hsiangkao@linux.alibaba.com> References: <20230317085045.16263-1-hsiangkao@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Cc: Gao Xiang Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" i_mode should be used instead for some old random fs. Signed-off-by: Gao Xiang --- lib/inode.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/inode.c b/lib/inode.c index 0f49f6e..ff17295 100644 --- a/lib/inode.c +++ b/lib/inode.c @@ -182,7 +182,7 @@ static int comp_subdir(const void *a, const void *b) int erofs_prepare_dir_file(struct erofs_inode *dir, unsigned int nr_subdirs) { struct erofs_dentry *d, *n, **sorted_d; - unsigned int d_size, i_nlink, i; + unsigned int d_size, i; /* dot is pointed to the current dir inode */ d = erofs_d_alloc(dir, "."); @@ -216,26 +216,14 @@ int erofs_prepare_dir_file(struct erofs_inode *dir, unsigned int nr_subdirs) /* let's calculate dir size and update i_nlink */ d_size = 0; - i_nlink = 0; list_for_each_entry(d, &dir->i_subdirs, d_child) { int len = strlen(d->name) + sizeof(struct erofs_dirent); if ((d_size & (erofs_blksiz() - 1)) + len > erofs_blksiz()) d_size = round_up(d_size, erofs_blksiz()); d_size += len; - - i_nlink += (d->type == EROFS_FT_DIR); } dir->i_size = d_size; - /* - * if there're too many subdirs as compact form, set nlink=1 - * rather than upgrade to use extented form instead. - */ - if (i_nlink > USHRT_MAX && - dir->inode_isize == sizeof(struct erofs_inode_compact)) - dir->i_nlink = 1; - else - dir->i_nlink = i_nlink; /* no compression for all dirs */ dir->datalayout = EROFS_INODE_FLAT_INLINE; @@ -1039,7 +1027,7 @@ static int erofs_mkfs_build_tree(struct erofs_inode *dir, struct list_head *dirs DIR *_dir; struct dirent *dp; struct erofs_dentry *d; - unsigned int nr_subdirs; + unsigned int nr_subdirs, i_nlink; ret = erofs_prepare_xattr_ibody(dir); if (ret < 0) @@ -1100,10 +1088,6 @@ static int erofs_mkfs_build_tree(struct erofs_inode *dir, struct list_head *dirs goto err_closedir; } nr_subdirs++; - - /* to count i_nlink for directories */ - d->type = (dp->d_type == DT_DIR ? - EROFS_FT_DIR : EROFS_FT_UNKNOWN); } if (errno) { @@ -1124,6 +1108,7 @@ static int erofs_mkfs_build_tree(struct erofs_inode *dir, struct list_head *dirs if (IS_ROOT(dir)) erofs_fixup_meta_blkaddr(dir); + i_nlink = 0; list_for_each_entry(d, &dir->i_subdirs, d_child) { char buf[PATH_MAX]; unsigned char ftype; @@ -1159,12 +1144,21 @@ fail: ++dir->subdirs_queued; } ftype = erofs_mode_to_ftype(inode->i_mode); - DBG_BUGON(ftype == EROFS_FT_DIR && d->type != ftype); + i_nlink += (ftype == EROFS_FT_DIR); d->inode = inode; d->type = ftype; erofs_info("file %s/%s dumped (type %u)", dir->i_srcpath, d->name, d->type); } + /* + * if there're too many subdirs as compact form, set nlink=1 + * rather than upgrade to use extented form instead. + */ + if (i_nlink > USHRT_MAX && + dir->inode_isize == sizeof(struct erofs_inode_compact)) + dir->i_nlink = 1; + else + dir->i_nlink = i_nlink; return 0; err_closedir: -- 2.24.4