]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
mke2fs: propagate some chattr flags into the fs image when using mke2fs -d
authorTheodore Ts'o <tytso@mit.edu>
Sun, 25 May 2025 16:51:36 +0000 (12:51 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 25 May 2025 22:09:11 +0000 (18:09 -0400)
When copying files from a source directory, propagate chattr flags
such as the immutable, append-only, nodump, etc. into the files in the
destination file system.  Flags in directory inodes are also propagated.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/debugfs.c
misc/create_inode.c
misc/create_inode.h
misc/create_inode_libarchive.c

index 87ae7463278da340bff86f3498b4d3a91755a55f..b9f248be2c39ea7bb0a490cfa30a66694b108341 100644 (file)
@@ -1834,7 +1834,7 @@ void do_mkdir(int argc, ss_argv_t argv, int sci_idx EXT2FS_ATTR((unused)),
                                "<filename>", CHECK_FS_RW))
                return;
 
-       retval = do_mkdir_internal(current_fs, cwd, argv[1], root);
+       retval = do_mkdir_internal(current_fs, cwd, argv[1], 0, root);
        if (retval)
                com_err(argv[0], retval, 0);
 
index 4fc7714b7dbb4469649a978254c8b8866d26387d..e7917b0eccf3236041f0bc4330c8fc01f28919d8 100644 (file)
 #include <linux/fs.h>
 #endif
 
-#include <ext2fs/ext2fs.h>
-#include <ext2fs/ext2_types.h>
-#include <ext2fs/fiemap.h>
+#include "ext2fs/ext2_fs.h"
+#include "ext2fs/ext2fs.h"
+#include "ext2fs/ext2_types.h"
+#include "ext2fs/fiemap.h"
 
 #include "create_inode.h"
 #include "support/nls-enable.h"
 
 int link_append_flag = EXT2FS_LINK_EXPAND;
 
+#define COPY_FLAGS_MASK        (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL | \
+                        EXT2_SYNC_FL | EXT2_IMMUTABLE_FL | EXT2_APPEND_FL | \
+                        EXT2_NODUMP_FL | EXT2_NOATIME_FL | \
+                        EXT3_JOURNAL_DATA_FL | EXT2_NOTAIL_FL | \
+                        EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL | FS_DAX_FL | \
+                        EXT4_PROJINHERIT_FL | EXT4_CASEFOLD_FL)
+
 static int ext2_file_type(unsigned int mode)
 {
        if (LINUX_S_ISREG(mode))
@@ -368,7 +376,7 @@ errcode_t do_symlink_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
 
 /* Make a directory in the fs */
 errcode_t do_mkdir_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
-                           ext2_ino_t root)
+                           unsigned long flags, ext2_ino_t root)
 {
        char                    *cp;
        ext2_ino_t              parent_ino;
@@ -388,7 +396,7 @@ errcode_t do_mkdir_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name,
        } else
                parent_ino = cwd;
 
-       retval = ext2fs_mkdir2(fs, parent_ino, 0, 0,
+       retval = ext2fs_mkdir2(fs, parent_ino, 0, (flags & COPY_FLAGS_MASK),
                               link_append_flag, name, NULL);
        if (retval)
                com_err("ext2fs_mkdir2", retval,
@@ -830,6 +838,7 @@ errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd, const char *src,
                        goto out;
                ext2fs_extent_free(handle);
        }
+       inode.i_flags |= (flags & COPY_FLAGS_MASK);
 
        retval = ext2fs_write_new_inode(fs, newfile, &inode);
        if (retval)
@@ -1076,7 +1085,7 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
                            strcmp(name, "lost+found") == 0)
                                goto find_lnf;
                        retval = do_mkdir_internal(fs, parent_ino, name,
-                                                  root);
+                                                  fl, root);
                        if (retval) {
                                com_err(__func__, retval,
                                        _("while making dir \"%s\""), name);
index 4472162eb7723dfa8e0f7c33951e24a71f25ff0d..b6f1d9ebe214f3be2cbd31223130fb9988d9ce74 100644 (file)
@@ -60,7 +60,8 @@ extern errcode_t do_symlink_internal(ext2_filsys fs, ext2_ino_t cwd,
                                     const char *name, char *target,
                                     ext2_ino_t root);
 extern errcode_t do_mkdir_internal(ext2_filsys fs, ext2_ino_t cwd,
-                                  const char *name, ext2_ino_t root);
+                                  const char *name, unsigned long flags,
+                                  ext2_ino_t root);
 extern errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd,
                                   const char *src, const char *dest,
                                   unsigned long flags, ext2_ino_t root);
index 118bf4f872e879a16db150ab2149b876272ebd92..7745c038960017e2c391af7f1eee58b76c676760 100644 (file)
@@ -535,7 +535,7 @@ static errcode_t handle_entry(ext2_filsys fs, ext2_ino_t root_ino,
                }
                break;
        case S_IFDIR:
-               retval = do_mkdir_internal(fs, dirinode, name, root);
+               retval = do_mkdir_internal(fs, dirinode, name, 0, root);
                if (retval) {
                        com_err(__func__, retval, _("while making dir \"%s\""),
                                name);