]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
create_inode: pass no_copy_xattr via a flag instead of using a global variable
authorTheodore Ts'o <tytso@mit.edu>
Tue, 20 May 2025 02:33:12 +0000 (22:33 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 21 May 2025 14:47:15 +0000 (10:47 -0400)
Add a new function, populate_fs3(), which takes a new flags parameter,
with the first flag being POPULATE_FS_NO_COPY_XATTRS.

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
misc/create_inode_libarchive.h
misc/mke2fs.c

index 46ff517e0515732d1afde400c0c0ebc33265a451..9fbf1f3187327f786aa00a7ff6e9617395c4cc81 100644 (file)
@@ -62,7 +62,6 @@ int ss_sci_idx;
 ext2_filsys    current_fs;
 quota_ctx_t    current_qctx;
 ext2_ino_t     root, cwd;
-int            no_copy_xattrs;
 
 static int debugfs_setup_tdb(const char *device_name, char *undo_file,
                             io_manager *io_ptr)
index 4e292a2d2ef39b50492fbfa29540e5983cdabb5a..b83b2f5b0e2ae6d85cec3e680de3312f2d50635e 100644 (file)
@@ -153,9 +153,6 @@ static errcode_t set_inode_xattr(ext2_filsys fs, ext2_ino_t ino,
        char                            *list = NULL;
        int                             i;
 
-       if (no_copy_xattrs)
-               return 0;
-
        size = llistxattr(filename, NULL, 0);
        if (size == -1) {
                if (errno == ENOTSUP)
@@ -812,6 +809,7 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
                               const char *source_dir, ext2_ino_t root,
                               struct hdlinks_s *hdlinks,
                               struct file_info *target,
+                              int flags,
                               struct fs_ops_callbacks *fs_callbacks)
 {
        const char      *name;
@@ -972,7 +970,7 @@ find_lnf:
                        }
                        /* Populate the dir recursively*/
                        retval = __populate_fs(fs, ino, name, root, hdlinks,
-                                              target, fs_callbacks);
+                                              target, flags, fs_callbacks);
                        if (retval)
                                goto out;
                        if (chdir("..")) {
@@ -1001,11 +999,14 @@ find_lnf:
                        goto out;
                }
 
-               retval = set_inode_xattr(fs, ino, name);
-               if (retval) {
-                       com_err(__func__, retval,
-                               _("while setting xattrs for \"%s\""), name);
-                       goto out;
+               if ((flags & POPULATE_FS_NO_COPY_XATTRS) == 0) {
+                       retval = set_inode_xattr(fs, ino, name);
+                       if (retval) {
+                               com_err(__func__, retval,
+                                       _("while setting xattrs for \"%s\""),
+                                       name);
+                               goto out;
+                       }
                }
 
                if (fs_callbacks && fs_callbacks->end_create_new_inode) {
@@ -1051,8 +1052,8 @@ out:
        return retval;
 }
 
-errcode_t populate_fs2(ext2_filsys fs, ext2_ino_t parent_ino,
-                      const char *source, ext2_ino_t root,
+errcode_t populate_fs3(ext2_filsys fs, ext2_ino_t parent_ino,
+                      const char *source, ext2_ino_t root, int flags,
                       struct fs_ops_callbacks *fs_callbacks)
 {
        struct file_info file_info;
@@ -1081,8 +1082,9 @@ errcode_t populate_fs2(ext2_filsys fs, ext2_ino_t parent_ino,
         * a regular file (or a symlink pointing to a regular file)
         */
        if (strcmp(source, "-") == 0) {
-               retval = __populate_fs_from_tar(fs, parent_ino, NULL, root, &hdlinks,
-                                          &file_info, fs_callbacks);
+               retval = __populate_fs_from_tar(fs, parent_ino, NULL, root,
+                                               &hdlinks, &file_info, flags,
+                                               fs_callbacks);
                goto out;
        }
 
@@ -1093,20 +1095,23 @@ errcode_t populate_fs2(ext2_filsys fs, ext2_ino_t parent_ino,
                return retval;
        }
        if (S_ISREG(st.st_mode)) {
-               retval = __populate_fs_from_tar(fs, parent_ino, source, root, &hdlinks,
-                                          &file_info, fs_callbacks);
+               retval = __populate_fs_from_tar(fs, parent_ino, source, root,
+                                               &hdlinks, &file_info, flags,
+                                               fs_callbacks);
                goto out;
        }
 
-       retval = set_inode_xattr(fs, root, source);
-       if (retval) {
-               com_err(__func__, retval,
-                       _("while copying xattrs on root directory"));
-               goto out;
+       if ((flags & POPULATE_FS_NO_COPY_XATTRS) == 0) {
+               retval = set_inode_xattr(fs, root, source);
+               if (retval) {
+                       com_err(__func__, retval,
+                               _("while copying xattrs on root directory"));
+                       goto out;
+               }
        }
 
        retval = __populate_fs(fs, parent_ino, source, root, &hdlinks,
-                              &file_info, fs_callbacks);
+                              &file_info, flags, fs_callbacks);
 
 out:
        free(file_info.path);
@@ -1114,8 +1119,15 @@ out:
        return retval;
 }
 
+errcode_t populate_fs2(ext2_filsys fs, ext2_ino_t parent_ino,
+                      const char *source, ext2_ino_t root,
+                      struct fs_ops_callbacks *fs_callbacks)
+{
+       return populate_fs3(fs, parent_ino, source, root, 0, fs_callbacks);
+}
+
 errcode_t populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
                      const char *source, ext2_ino_t root)
 {
-       return populate_fs2(fs, parent_ino, source, root, NULL);
+       return populate_fs3(fs, parent_ino, source, root, 0, NULL);
 }
index c75d68553648d8f0dc6f1d603fe89c94d5324e08..186c3d0cfc5867b121a72dfb8f459acbcdda17fb 100644 (file)
@@ -30,6 +30,9 @@ struct file_info {
 
 #define HDLINK_CNT     (4)
 
+/* flags for populate_fs3 */
+#define POPULATE_FS_NO_COPY_XATTRS     0x0001
+
 struct fs_ops_callbacks {
        errcode_t (* create_new_inode)(ext2_filsys fs, const char *target_path,
                const char *name, ext2_ino_t parent_ino, ext2_ino_t root,
@@ -39,15 +42,16 @@ struct fs_ops_callbacks {
                ext2_ino_t parent_ino, ext2_ino_t root, mode_t mode);
 };
 
-extern int no_copy_xattrs;     /* this should eventually be a flag
-                                  passed to populate_fs3() */
-
 /* For populating the filesystem */
 extern errcode_t populate_fs(ext2_filsys fs, ext2_ino_t parent_ino,
                             const char *source_dir, ext2_ino_t root);
 extern errcode_t populate_fs2(ext2_filsys fs, ext2_ino_t parent_ino,
                              const char *source_dir, ext2_ino_t root,
                              struct fs_ops_callbacks *fs_callbacks);
+extern errcode_t populate_fs3(ext2_filsys fs, ext2_ino_t parent_ino,
+                             const char *source_dir, ext2_ino_t root,
+                             int flags,
+                             struct fs_ops_callbacks *fs_callbacks);
 extern errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd,
                                   const char *name, unsigned int st_mode,
                                   unsigned int st_rdev);
index f2d4ba00e52cf91b8da829c493503b6536e5b8ae..d109ca289e9be9bcd3ca96996302dc83bb00de0a 100644 (file)
@@ -448,9 +448,6 @@ static errcode_t set_inode_xattr_tar(ext2_filsys fs, ext2_ino_t ino,
        const void *value;
        size_t value_size;
 
-       if (no_copy_xattrs)
-               return 0;
-
        size = dl_archive_entry_xattr_count(entry);
        if (size == 0)
                return 0;
@@ -577,6 +574,7 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino,
                                 const char *source_tar, ext2_ino_t root,
                                 struct hdlinks_s *hdlinks EXT2FS_ATTR((unused)),
                                 struct file_info *target,
+                                int flags,
                                 struct fs_ops_callbacks *fs_callbacks)
 {
        char *path2=NULL, *path3=NULL, *dir, *name;
@@ -699,11 +697,14 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino,
                        goto out;
                }
 
-               retval = set_inode_xattr_tar(fs, tmpino, entry);
-               if (retval) {
-                       com_err(__func__, retval,
-                               _("while setting xattrs for \"%s\""), name);
-                       goto out;
+               if ((flags & POPULATE_FS_NO_COPY_XATTRS) == 0) {
+                       retval = set_inode_xattr_tar(fs, tmpino, entry);
+                       if (retval) {
+                               com_err(__func__, retval,
+                                       _("while setting xattrs for \"%s\""),
+                                       name);
+                               goto out;
+                       }
                }
 
                if (fs_callbacks && fs_callbacks->end_create_new_inode) {
index 78c454e3c5c274c46940e5a2faefa3ad4846dfec..21bcebf5f3f3b24ff7ed114cb5429c3d6dee6cc9 100644 (file)
@@ -5,6 +5,7 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino,
                                 const char *source_tar, ext2_ino_t root,
                                 struct hdlinks_s *hdlinks,
                                 struct file_info *target,
+                                int flags,
                                 struct fs_ops_callbacks *fs_callbacks);
 
 #endif /* _CREATE_INODE_LIBARCHIVE_H */
index f7ca7803d77adb3d73ce7793b11ceee0539c43bb..71e3704bad79c3082b9d6fa5b4e3cccd5c1ea360 100644 (file)
@@ -102,7 +102,7 @@ static e2_blkcnt_t  orphan_file_blocks;
 static int     lazy_itable_init;
 static int     assume_storage_prezeroed;
 static int     packed_meta_blocks;
-int            no_copy_xattrs;
+static int     populate_flags;
 static char    *bad_blocks_filename = NULL;
 static __u32   fs_stride;
 /* Initialize usr/grp quotas by default */
@@ -913,7 +913,7 @@ static void parse_extended_opts(struct ext2_super_block *param,
                                continue;
                        }
                } else if (strcmp(token, "no_copy_xattrs") == 0) {
-                       no_copy_xattrs = 1;
+                       populate_flags |= POPULATE_FS_NO_COPY_XATTRS;
                        continue;
                } else if (strcmp(token, "num_backup_sb") == 0) {
                        if (!arg) {
@@ -3668,8 +3668,8 @@ no_journal:
                if (!quiet)
                        printf("%s", _("Copying files into the device: "));
 
-               retval = populate_fs(fs, EXT2_ROOT_INO, src_root,
-                                    EXT2_ROOT_INO);
+               retval = populate_fs3(fs, EXT2_ROOT_INO, src_root,
+                                     EXT2_ROOT_INO, populate_flags, NULL);
                if (retval) {
                        com_err(program_name, retval, "%s",
                                _("while populating file system"));