]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
copy: Make copy_xattr() more generic
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 13 Feb 2023 20:51:11 +0000 (21:51 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 14 Feb 2023 11:51:40 +0000 (12:51 +0100)
Let's make copy_xattr() a little more generic in preparation for
copying symlink xattrs.

src/dissect/dissect.c
src/import/export-raw.c
src/import/import-raw.c
src/import/pull-raw.c
src/locale/localed-util.c
src/partition/repart.c
src/shared/copy.c
src/shared/copy.h

index f435932815d10f98f06695db1550f1f2826fd109..8d3d3712d7e3346338a2c818ed3fff237b55bb8e 100644 (file)
@@ -1105,7 +1105,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
                 if (r < 0)
                         return log_error_errno(r, "Failed to copy bytes from %s in mage '%s' to '%s': %m", arg_source, arg_image, arg_target);
 
-                (void) copy_xattr(source_fd, target_fd, 0);
+                (void) copy_xattr(source_fd, NULL, target_fd, NULL, 0);
                 (void) copy_access(source_fd, target_fd);
                 (void) copy_times(source_fd, target_fd, 0);
 
@@ -1182,7 +1182,7 @@ static int action_list_or_mtree_or_copy(DissectedImage *m, LoopDevice *d) {
                 if (r < 0)
                         return log_error_errno(r, "Failed to copy bytes from '%s' to '%s' in image '%s': %m", arg_source, arg_target, arg_image);
 
-                (void) copy_xattr(source_fd, target_fd, 0);
+                (void) copy_xattr(source_fd, NULL, target_fd, NULL, 0);
                 (void) copy_access(source_fd, target_fd);
                 (void) copy_times(source_fd, target_fd, 0);
 
index 7c61aef3b68f15149e6df08d994c8e9cc3358804..44181fd9b2fa8fe4c4f746bfa21a5b97dbfd75d5 100644 (file)
@@ -216,7 +216,7 @@ static int raw_export_process(RawExport *e) {
 finish:
         if (r >= 0) {
                 (void) copy_times(e->input_fd, e->output_fd, COPY_CRTIME);
-                (void) copy_xattr(e->input_fd, e->output_fd, 0);
+                (void) copy_xattr(e->input_fd, NULL, e->output_fd, NULL, 0);
         }
 
         if (e->on_finished)
index 5d4dedf66d609b1c52e3d0b75e262e7fa33e6460..3765b514bb373f9c4e176bc5133271b886559efc 100644 (file)
@@ -234,7 +234,7 @@ static int raw_import_finish(RawImport *i) {
 
                 if (S_ISREG(i->input_stat.st_mode)) {
                         (void) copy_times(i->input_fd, i->output_fd, COPY_CRTIME);
-                        (void) copy_xattr(i->input_fd, i->output_fd, 0);
+                        (void) copy_xattr(i->input_fd, NULL, i->output_fd, NULL, 0);
                 }
         }
 
index a4a844bf0727ac160cb2bf3681f943839c103c6b..8a152d0f6f41f8e9390b75f635fafe6bccbafeb6 100644 (file)
@@ -396,7 +396,7 @@ static int raw_pull_make_local_copy(RawPull *i) {
                 return log_error_errno(r, "Failed to make writable copy of image: %m");
 
         (void) copy_times(i->raw_job->disk_fd, dfd, COPY_CRTIME);
-        (void) copy_xattr(i->raw_job->disk_fd, dfd, 0);
+        (void) copy_xattr(i->raw_job->disk_fd, NULL, dfd, NULL, 0);
 
         dfd = safe_close(dfd);
 
index 8f18ecd0d2fd79cfbed4a260a278772a94624938..d6b6593bea607d9e4738d352033c8cd36f06955b 100644 (file)
@@ -921,7 +921,7 @@ int locale_gen_enable_locale(const char *locale) {
                 r = copy_access(fileno(fr), fileno(fw));
                 if (r < 0)
                         return r;
-                r = copy_xattr(fileno(fr), fileno(fw), COPY_ALL_XATTRS);
+                r = copy_xattr(fileno(fr), NULL, fileno(fw), NULL, COPY_ALL_XATTRS);
                 if (r < 0)
                         log_debug_errno(r, "Failed to copy all xattrs from old to new /etc/locale.gen file, ignoring: %m");
         }
index 6ba48b528ec8b10d9c6195b402ba07c0075793d5..43f25e7e59a0a59f59fdb66c9813daf4b95aeb9a 100644 (file)
@@ -3840,7 +3840,7 @@ static int do_copy_files(Partition *p, const char *root, const Set *denylist) {
                         if (r < 0)
                                 return log_error_errno(r, "Failed to copy '%s' to '%s%s': %m", *source, strempty(arg_root), *target);
 
-                        (void) copy_xattr(sfd, tfd, COPY_ALL_XATTRS);
+                        (void) copy_xattr(sfd, NULL, tfd, NULL, COPY_ALL_XATTRS);
                         (void) copy_access(sfd, tfd);
                         (void) copy_times(sfd, tfd, 0);
                 }
index 4eb4f9f765ca9c8450bf8fe636d0cd6a2b1831cc..3e624d8844f28aaf659c7e839ce894079d7bf4fd 100644 (file)
@@ -754,7 +754,7 @@ static int fd_copy_regular(
                 r = -errno;
 
         (void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
-        (void) copy_xattr(fdf, fdt, copy_flags);
+        (void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags);
 
         if (copy_flags & COPY_FSYNC) {
                 if (fsync(fdt) < 0) {
@@ -1058,7 +1058,7 @@ static int fd_copy_directory(
                 if (fchmod(fdt, st->st_mode & 07777) < 0)
                         r = -errno;
 
-                (void) copy_xattr(dirfd(d), fdt, copy_flags);
+                (void) copy_xattr(dirfd(d), NULL, fdt, NULL, copy_flags);
                 (void) futimens(fdt, (struct timespec[]) { st->st_atim, st->st_mtim });
         }
 
@@ -1313,7 +1313,7 @@ int copy_file_fd_full(
          * mode/ownership of that device node...) */
         if (S_ISREG(st.st_mode)) {
                 (void) copy_times(fdf, fdt, copy_flags);
-                (void) copy_xattr(fdf, fdt, copy_flags);
+                (void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags);
         }
 
         if (copy_flags & COPY_FSYNC_FULL) {
@@ -1385,7 +1385,7 @@ int copy_file_full(
                 goto fail;
 
         (void) copy_times(fdf, fdt, copy_flags);
-        (void) copy_xattr(fdf, fdt, copy_flags);
+        (void) copy_xattr(fdf, NULL, fdt, NULL, copy_flags);
 
         if (chattr_mask != 0)
                 (void) chattr_fd(fdt, chattr_flags, chattr_mask & ~CHATTR_EARLY_FL, NULL);
@@ -1570,11 +1570,11 @@ int copy_rights_with_fallback(int fdf, int fdt, const char *patht) {
         return fchmod_and_chown_with_fallback(fdt, patht, st.st_mode & 07777, st.st_uid, st.st_gid);
 }
 
-int copy_xattr(int fdf, int fdt, CopyFlags copy_flags) {
+int copy_xattr(int df, const char *from, int dt, const char *to, CopyFlags copy_flags) {
         _cleanup_free_ char *names = NULL;
         int ret = 0, r;
 
-        r = flistxattr_malloc(fdf, &names);
+        r = listxattr_at_malloc(df, from, 0, &names);
         if (r < 0)
                 return r;
 
@@ -1584,13 +1584,13 @@ int copy_xattr(int fdf, int fdt, CopyFlags copy_flags) {
                 if (!FLAGS_SET(copy_flags, COPY_ALL_XATTRS) && !startswith(p, "user."))
                         continue;
 
-                r = fgetxattr_malloc(fdf, p, &value);
+                r = getxattr_at_malloc(df, from, p, 0, &value);
                 if (r == -ENODATA)
                         continue; /* gone by now */
                 if (r < 0)
                         return r;
 
-                if (fsetxattr(fdt, p, value, r, 0) < 0)
+                if (xsetxattr(dt, to, p, value, r, 0) < 0)
                         ret = -errno;
         }
 
index 1eb6d1ce0532e041cc66f617d5d6468f82e180f2..22151ff83b07a012085ab7be2854412b676cd907 100644 (file)
@@ -77,4 +77,4 @@ int copy_rights_with_fallback(int fdf, int fdt, const char *patht);
 static inline int copy_rights(int fdf, int fdt) {
         return copy_rights_with_fallback(fdf, fdt, NULL); /* no fallback */
 }
-int copy_xattr(int fdf, int fdt, CopyFlags copy_flags);
+int copy_xattr(int df, const char *from, int dt, const char *to, CopyFlags copy_flags);