diff --git a/src/common/mfu_flist_copy.c b/src/common/mfu_flist_copy.c index 0775116f..e3af0a2b 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,50 @@ static int mfu_copy_xattrs( mfu_free(&list); list_bufsize = 0; + /* open the src */ + int src_fd = open(src_path, O_RDONLY); + if (src_fd < 0) { + MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno)); + rc = -1; + goto xattr_fin; + } + /* open the dest */ + int dest_fd = open(dest_path, O_RDONLY); + if (dest_fd < 0) { + MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); + rc = -1; + goto xattr_close_src; + } + struct fsxattr src_attr; + /* get src's xattr */ + rc = ioctl(src_fd, FS_IOC_FSGETXATTR, &src_attr); + if (rc != 0) { + MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSGETXATTR) failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno)); + goto xattr_close_dest; + } + struct fsxattr dest_attr; + /* get dest's xattr */ + rc = ioctl(dest_fd, FS_IOC_FSGETXATTR, &dest_attr); + if (rc != 0) { + MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSGETXATTR) failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); + goto xattr_close_dest; + } + dest_attr.fsx_projid = src_attr.fsx_projid; + dest_attr.fsx_xflags = (dest_attr.fsx_xflags & ~FS_XFLAG_PROJINHERIT) | + (src_attr.fsx_xflags & FS_XFLAG_PROJINHERIT); + /* set dest's xattr */ + rc = ioctl(dest_fd, FS_IOC_FSSETXATTR, &dest_attr); + if (rc != 0) { + MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSSETXATTR) failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); + } +xattr_close_dest: + /* close dest */ + close(dest_fd); +xattr_close_src: + /* close src */ + close(src_fd); +xattr_fin: + #endif /* DCOPY_USE_XATTR */ return rc;