]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: add new function ext2fs_mkdir2()
authorTheodore Ts'o <tytso@mit.edu>
Sun, 25 May 2025 05:11:54 +0000 (01:11 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 25 May 2025 21:59:17 +0000 (17:59 -0400)
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 <tytso@mit.edu>
lib/ext2fs/ext2fs.h
lib/ext2fs/mkdir.c
misc/create_inode.c
misc/fuse2fs.c

index fd2901b99df0d53ee34e0932375887bdefaa82a3..301312e4f23ad9976f394d90d7879fd33e96778f 100644 (file)
@@ -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 {
index 437c8ffccaa62dd84d49ecb08f7519999e9dad69..45f6e9e27164d21578c8428897a3c381ce824b26 100644 (file)
 #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);
+}
index bdd1f756f45dd8c875ed825be24584b83bb531bb..4fc7714b7dbb4469649a978254c8b8866d26387d 100644 (file)
@@ -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;
 }
index d2793c07de73ffc9b0aac2c7467d68f894fe4419..71dbdc1a17368c780a5a633373b5c499fd77e205 100644 (file)
@@ -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;