From: Theodore Ts'o Date: Sun, 25 May 2025 05:11:54 +0000 (-0400) Subject: libext2fs: add new function ext2fs_mkdir2() X-Git-Tag: v1.47.3-rc1~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b107c3a2b8e857bc75af61e3741edcb4ed2b9d4f;p=thirdparty%2Fe2fsprogs.git libext2fs: add new function ext2fs_mkdir2() Add a new function which allows caller to specify the flags passed to ext2fs_link and to set flags in the newly created directory. Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index fd2901b9..301312e4 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -1763,6 +1763,10 @@ extern int ext2fs_casefold_cmp(const struct ext2fs_nls_table *table, /* mkdir.c */ extern errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, const char *name); +extern errcode_t ext2fs_mkdir2(ext2_filsys fs, ext2_ino_t parent, + ext2_ino_t ino, unsigned long flags, + int link_flags, const char *name, + ext2_ino_t *ret_ino); /* mkjournal.c */ struct ext2fs_journal_params { diff --git a/lib/ext2fs/mkdir.c b/lib/ext2fs/mkdir.c index 437c8ffc..45f6e9e2 100644 --- a/lib/ext2fs/mkdir.c +++ b/lib/ext2fs/mkdir.c @@ -32,13 +32,13 @@ #define EXT2_FT_DIR 2 #endif -errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, - const char *name) +errcode_t ext2fs_mkdir2(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, + unsigned long flags, int link_flags, const char *name, + ext2_ino_t *ret_ino) { ext2_extent_handle_t handle; errcode_t retval; struct ext2_inode parent_inode, inode; - ext2_ino_t ino = inum; ext2_ino_t scratch_ino; blk64_t blk; char *block = 0; @@ -64,6 +64,8 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, if (retval) goto cleanup; } + if (ret_ino) + *ret_ino = ino; /* * Allocate a data block for the directory @@ -115,6 +117,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, inode.i_size = fs->blocksize; ext2fs_iblk_set(fs, &inode, 1); } + inode.i_flags |= flags & (EXT2_FL_USER_MODIFIABLE & ~EXT4_EXTENTS_FL); inode.i_links_count = 2; /* @@ -165,7 +168,8 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, } if (retval != EXT2_ET_FILE_NOT_FOUND) goto cleanup; - retval = ext2fs_link(fs, parent, name, ino, EXT2_FT_DIR); + retval = ext2fs_link(fs, parent, name, ino, + EXT2_FT_DIR | link_flags); if (retval) goto cleanup; } @@ -197,4 +201,8 @@ cleanup: } - +errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t ino, + const char *name) +{ + return ext2fs_mkdir2(fs, parent, ino, 0, 0, name, NULL); +} diff --git a/misc/create_inode.c b/misc/create_inode.c index bdd1f756..4fc7714b 100644 --- a/misc/create_inode.c +++ b/misc/create_inode.c @@ -388,18 +388,10 @@ errcode_t do_mkdir_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name, } else parent_ino = cwd; - retval = ext2fs_mkdir(fs, parent_ino, 0, name); - if (retval == EXT2_ET_DIR_NO_SPACE) { - retval = ext2fs_expand_dir(fs, parent_ino); - if (retval) { - com_err(__func__, retval, - _("while expanding directory")); - return retval; - } - retval = ext2fs_mkdir(fs, parent_ino, 0, name); - } + retval = ext2fs_mkdir2(fs, parent_ino, 0, 0, + link_append_flag, name, NULL); if (retval) - com_err("ext2fs_mkdir", retval, + com_err("ext2fs_mkdir2", retval, _("while creating directory \"%s\""), name); return retval; } diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index d2793c07..71dbdc1a 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -1209,16 +1209,8 @@ static int op_mkdir(const char *path, mode_t mode) *node_name = a; - err = ext2fs_mkdir(fs, parent, 0, node_name); - if (err == EXT2_ET_DIR_NO_SPACE) { - err = ext2fs_expand_dir(fs, parent); - if (err) { - ret = translate_error(fs, parent, err); - goto out2; - } - - err = ext2fs_mkdir(fs, parent, 0, node_name); - } + err = ext2fs_mkdir2(fs, parent, 0, 0, EXT2FS_LINK_EXPAND, + node_name, NULL); if (err) { ret = translate_error(fs, parent, err); goto out2;