From 8a5e9a4b25dec19ee707ddbb93240c94ef7f480b Mon Sep 17 00:00:00 2001 From: Gao Xiang Date: Thu, 13 Jun 2024 00:18:22 +0800 Subject: [PATCH] erofs-utils: lib: get rid of erofs_prepare_dir_layout() Just open-code the previous erofs_prepare_dir_file() and rename `erofs_prepare_dir_layout()` to `erofs_prepare_dir_file()`. No logic changes. Signed-off-by: Gao Xiang Link: https://lore.kernel.org/r/20240612161826.711279-1-hsiangkao@linux.alibaba.com --- lib/inode.c | 69 +++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/lib/inode.c b/lib/inode.c index 9219759..e4ec95f 100644 --- a/lib/inode.c +++ b/lib/inode.c @@ -208,8 +208,30 @@ static int comp_subdir(const void *a, const void *b) return strcmp(da->name, db->name); } -static int erofs_prepare_dir_layout(struct erofs_inode *dir, - unsigned int nr_subdirs) +int erofs_init_empty_dir(struct erofs_inode *dir) +{ + struct erofs_dentry *d; + + /* dot is pointed to the current dir inode */ + d = erofs_d_alloc(dir, "."); + if (IS_ERR(d)) + return PTR_ERR(d); + d->inode = erofs_igrab(dir); + d->type = EROFS_FT_DIR; + + /* dotdot is pointed to the parent dir */ + d = erofs_d_alloc(dir, ".."); + if (IS_ERR(d)) + return PTR_ERR(d); + d->inode = erofs_igrab(erofs_parent_inode(dir)); + d->type = EROFS_FT_DIR; + + dir->i_nlink = 2; + return 0; +} + +static int erofs_prepare_dir_file(struct erofs_inode *dir, + unsigned int nr_subdirs) { struct erofs_sb_info *sbi = dir->sbi; struct erofs_dentry *d, *n, **sorted_d; @@ -248,41 +270,6 @@ static int erofs_prepare_dir_layout(struct erofs_inode *dir, return 0; } -int erofs_init_empty_dir(struct erofs_inode *dir) -{ - struct erofs_dentry *d; - - /* dot is pointed to the current dir inode */ - d = erofs_d_alloc(dir, "."); - if (IS_ERR(d)) - return PTR_ERR(d); - d->inode = erofs_igrab(dir); - d->type = EROFS_FT_DIR; - - /* dotdot is pointed to the parent dir */ - d = erofs_d_alloc(dir, ".."); - if (IS_ERR(d)) - return PTR_ERR(d); - d->inode = erofs_igrab(erofs_parent_inode(dir)); - d->type = EROFS_FT_DIR; - - dir->i_nlink = 2; - return 0; -} - -int erofs_prepare_dir_file(struct erofs_inode *dir, unsigned int nr_subdirs) -{ - int ret; - - ret = erofs_init_empty_dir(dir); - if (ret) - return ret; - - /* sort subdirs */ - nr_subdirs += 2; - return erofs_prepare_dir_layout(dir, nr_subdirs); -} - static void fill_dirblock(char *buf, unsigned int size, unsigned int q, struct erofs_dentry *head, struct erofs_dentry *end) { @@ -1358,7 +1345,11 @@ static int erofs_mkfs_handle_directory(struct erofs_inode *dir) } closedir(_dir); - ret = erofs_prepare_dir_file(dir, nr_subdirs); + ret = erofs_init_empty_dir(dir); + if (ret) + return ret; + + ret = erofs_prepare_dir_file(dir, nr_subdirs + 2); /* sort subdirs */ if (ret) return ret; @@ -1401,7 +1392,7 @@ static int erofs_rebuild_handle_directory(struct erofs_inode *dir) DBG_BUGON(i_nlink < 2); /* should have `.` and `..` */ DBG_BUGON(nr_subdirs < i_nlink); - ret = erofs_prepare_dir_layout(dir, nr_subdirs); + ret = erofs_prepare_dir_file(dir, nr_subdirs); if (ret) return ret; -- 2.34.1