|
18 | 18 | #include <time.h> /* asctime / localtime */
|
19 | 19 | #include <regex.h>
|
20 | 20 |
|
| 21 | +#if DCOPY_USE_XATTRS |
| 22 | +#include <linux/fs.h> |
| 23 | +#endif |
| 24 | + |
21 | 25 | #ifdef HAVE_LIBATTR
|
22 | 26 | #include <attr/libattr.h>
|
23 | 27 | #endif /* HAVE_LIBATTR */
|
@@ -443,6 +447,50 @@ static int mfu_copy_xattrs(
|
443 | 447 | mfu_free(&list);
|
444 | 448 | list_bufsize = 0;
|
445 | 449 |
|
| 450 | + /* open the src */ |
| 451 | + int src_fd = open(src_path, O_RDONLY); |
| 452 | + if (src_fd < 0) { |
| 453 | + MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno)); |
| 454 | + rc = -1; |
| 455 | + goto xattr_fin; |
| 456 | + } |
| 457 | + /* open the dest */ |
| 458 | + int dest_fd = open(dest_path, O_RDONLY); |
| 459 | + if (dest_fd < 0) { |
| 460 | + MFU_LOG(MFU_LOG_ERR, "open failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); |
| 461 | + rc = -1; |
| 462 | + goto xattr_close_src; |
| 463 | + } |
| 464 | + struct fsxattr src_attr; |
| 465 | + /* get src's xattr */ |
| 466 | + rc = ioctl(src_fd, FS_IOC_FSGETXATTR, &src_attr); |
| 467 | + if (rc != 0) { |
| 468 | + MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSGETXATTR) failed: `%s' errno=%d (%s)", src_path, errno, strerror(errno)); |
| 469 | + goto xattr_close_dest; |
| 470 | + } |
| 471 | + struct fsxattr dest_attr; |
| 472 | + /* get dest's xattr */ |
| 473 | + rc = ioctl(dest_fd, FS_IOC_FSGETXATTR, &dest_attr); |
| 474 | + if (rc != 0) { |
| 475 | + MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSGETXATTR) failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); |
| 476 | + goto xattr_close_dest; |
| 477 | + } |
| 478 | + dest_attr.fsx_projid = src_attr.fsx_projid; |
| 479 | + dest_attr.fsx_xflags = (dest_attr.fsx_xflags & ~FS_XFLAG_PROJINHERIT) | |
| 480 | + (src_attr.fsx_xflags & FS_XFLAG_PROJINHERIT); |
| 481 | + /* set dest's xattr */ |
| 482 | + rc = ioctl(dest_fd, FS_IOC_FSSETXATTR, &dest_attr); |
| 483 | + if (rc != 0) { |
| 484 | + MFU_LOG(MFU_LOG_ERR, "ioctl(FS_IOC_FSSETXATTR) failed: `%s' errno=%d (%s)", dest_path, errno, strerror(errno)); |
| 485 | + } |
| 486 | +xattr_close_dest: |
| 487 | + /* close dest */ |
| 488 | + close(dest_fd); |
| 489 | +xattr_close_src: |
| 490 | + /* close src */ |
| 491 | + close(src_fd); |
| 492 | +xattr_fin: |
| 493 | + |
446 | 494 | #endif /* DCOPY_USE_XATTR */
|
447 | 495 |
|
448 | 496 | return rc;
|
|
0 commit comments