[PATCH 2/9] erofs-utils: initialize i_nlink to 2 in erofs_init_empty_dir()

Jingbo Xu jefflexu at linux.alibaba.com
Thu Jul 27 14:57:05 AEST 2023


Set dir->i_nlink to 2 as "." and ".." are allocated.

tarerofs_init_empty_dir() is removed then.

Signed-off-by: Jingbo Xu <jefflexu at linux.alibaba.com>
---
 lib/inode.c |  2 ++
 lib/tar.c   | 14 ++------------
 mkfs/main.c |  2 +-
 3 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/lib/inode.c b/lib/inode.c
index c4d1476..d54f84f 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -235,6 +235,8 @@ int erofs_init_empty_dir(struct erofs_inode *dir)
 		return PTR_ERR(d);
 	d->inode = erofs_igrab(dir->i_parent);
 	d->type = EROFS_FT_DIR;
+
+	dir->i_nlink = 2;
 	return 0;
 }
 
diff --git a/lib/tar.c b/lib/tar.c
index 76ba69d..3c145e5 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -138,16 +138,6 @@ static long long tarerofs_parsenum(const char *ptr, int len)
 	return tarerofs_otoi(ptr, len);
 }
 
-int tarerofs_init_empty_dir(struct erofs_inode *inode)
-{
-	int ret = erofs_init_empty_dir(inode);
-
-	if (ret)
-		return ret;
-	inode->i_nlink = 2;
-	return 0;
-}
-
 static struct erofs_dentry *tarerofs_mkdir(struct erofs_inode *dir, const char *s)
 {
 	struct erofs_inode *inode;
@@ -163,7 +153,7 @@ static struct erofs_dentry *tarerofs_mkdir(struct erofs_inode *dir, const char *
 	inode->i_gid = getgid();
 	inode->i_mtime = inode->sbi->build_time;
 	inode->i_mtime_nsec = inode->sbi->build_time_nsec;
-	tarerofs_init_empty_dir(inode);
+	erofs_init_empty_dir(inode);
 
 	d = erofs_d_alloc(dir, s);
 	if (!IS_ERR(d)) {
@@ -759,7 +749,7 @@ new_inode:
 		inode->i_nlink++;
 		ret = 0;
 	} else if (!inode->i_nlink)
-		ret = tarerofs_init_empty_dir(inode);
+		ret = erofs_init_empty_dir(inode);
 	else
 		ret = 0;
 out:
diff --git a/mkfs/main.c b/mkfs/main.c
index 92a07fd..bc5ed87 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -928,7 +928,7 @@ int main(int argc, char **argv)
 		root_inode->i_parent = root_inode;
 		root_inode->i_mtime = sbi.build_time;
 		root_inode->i_mtime_nsec = sbi.build_time_nsec;
-		tarerofs_init_empty_dir(root_inode);
+		erofs_init_empty_dir(root_inode);
 
 		while (!(err = tarerofs_parse_tar(root_inode, &erofstar)));
 
-- 
2.19.1.6.gb485710b



More information about the Linux-erofs mailing list