From 2dc83ca9b892fe082b5b4400a93e5a4af3a4ec56 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 19 May 2025 22:33:12 -0400 Subject: [PATCH] create_inode: pass no_copy_xattr via a flag instead of using a global variable 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 --- debugfs/debugfs.c | 1 - misc/create_inode.c | 56 +++++++++++++++++++++------------- misc/create_inode.h | 10 ++++-- misc/create_inode_libarchive.c | 17 ++++++----- misc/create_inode_libarchive.h | 1 + misc/mke2fs.c | 8 ++--- 6 files changed, 55 insertions(+), 38 deletions(-) diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index 46ff517e..9fbf1f31 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -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) diff --git a/misc/create_inode.c b/misc/create_inode.c index 4e292a2d..b83b2f5b 100644 --- a/misc/create_inode.c +++ b/misc/create_inode.c @@ -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); } diff --git a/misc/create_inode.h b/misc/create_inode.h index c75d6855..186c3d0c 100644 --- a/misc/create_inode.h +++ b/misc/create_inode.h @@ -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); diff --git a/misc/create_inode_libarchive.c b/misc/create_inode_libarchive.c index f2d4ba00..d109ca28 100644 --- a/misc/create_inode_libarchive.c +++ b/misc/create_inode_libarchive.c @@ -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) { diff --git a/misc/create_inode_libarchive.h b/misc/create_inode_libarchive.h index 78c454e3..21bcebf5 100644 --- a/misc/create_inode_libarchive.h +++ b/misc/create_inode_libarchive.h @@ -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 */ diff --git a/misc/mke2fs.c b/misc/mke2fs.c index f7ca7803..71e3704b 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -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")); -- 2.47.2