From 0eca578af94d3e18be073deae22cb7658ed9780c Mon Sep 17 00:00:00 2001 From: Sohei Koyama Date: Wed, 30 Oct 2024 18:07:26 +0900 Subject: [PATCH] mfu: copy much more xattrs When copying files using dcp or dsync, extended attributes such as project id are also copied. Resolves #553. Signed-off-by: Sohei Koyama --- src/common/mfu_flist_copy.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/common/mfu_flist_copy.c b/src/common/mfu_flist_copy.c index 0775116f..f97d1467 100644 --- a/src/common/mfu_flist_copy.c +++ b/src/common/mfu_flist_copy.c @@ -18,6 +18,10 @@ #include /* asctime / localtime */ #include +#if DCOPY_USE_XATTRS +#include +#endif + #ifdef HAVE_LIBATTR #include #endif /* HAVE_LIBATTR */ @@ -443,6 +447,31 @@ static int mfu_copy_xattrs( mfu_free(&list); list_bufsize = 0; + int src_fd = open(src_path, O_RDONLY); + if (src_fd >= 0) { + int dest_fd = open(dest_path, O_RDONLY); + if (dest_fd >= 0) { + struct fsxattr attr; + rc = ioctl(src_fd, FS_IOC_FSGETXATTR, &attr); + if (rc == 0) { + rc = ioctl(dest_fd, FS_IOC_FSSETXATTR, &attr); + if (rc != 0) { + MFU_LOG(MFU_LOG_ERR, "ioctl failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); + } + } else { + MFU_LOG(MFU_LOG_ERR, "ioctl failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno)); + } + close(dest_fd); + } else { + MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); + rc = -1; + } + close(src_fd); + } else { + MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno)); + rc = -1; + } + #endif /* DCOPY_USE_XATTR */ return rc;