diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-13 20:30:02 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-07-13 20:30:02 +0200 |
commit | 79fb6ac7a5acc4178b66314c573aeada1d387ed9 (patch) | |
tree | 421fd899e9dfcc5533b3107af6eba3de0f153044 /libbb | |
parent | 253f555f01fa380083a7436a569397a4e7f997b0 (diff) | |
download | busybox-w32-79fb6ac7a5acc4178b66314c573aeada1d387ed9.tar.gz busybox-w32-79fb6ac7a5acc4178b66314c573aeada1d387ed9.tar.bz2 busybox-w32-79fb6ac7a5acc4178b66314c573aeada1d387ed9.zip |
cp: optional --reflink support
function old new delta
cp_main 428 512 +84
copy_file 1676 1742 +66
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/copy_file.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 1b8befd65..98bd4fe72 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -340,8 +340,27 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags) | |||
340 | } | 340 | } |
341 | } | 341 | } |
342 | #endif | 342 | #endif |
343 | #if ENABLE_FEATURE_CP_REFLINK | ||
344 | # undef BTRFS_IOCTL_MAGIC | ||
345 | # define BTRFS_IOCTL_MAGIC 0x94 | ||
346 | # undef BTRFS_IOC_CLONE | ||
347 | # define BTRFS_IOC_CLONE _IOW (BTRFS_IOCTL_MAGIC, 9, int) | ||
348 | if (flags & FILEUTILS_REFLINK) { | ||
349 | retval = ioctl(dst_fd, BTRFS_IOC_CLONE, src_fd); | ||
350 | if (retval == 0) | ||
351 | goto do_close; | ||
352 | /* reflink did not work */ | ||
353 | if (flags & FILEUTILS_REFLINK_ALWAYS) { | ||
354 | bb_perror_msg("failed to clone '%s' from '%s'", dest, source); | ||
355 | goto do_close; | ||
356 | } | ||
357 | /* fall through to standard copy */ | ||
358 | retval = 0; | ||
359 | } | ||
360 | #endif | ||
343 | if (bb_copyfd_eof(src_fd, dst_fd) == -1) | 361 | if (bb_copyfd_eof(src_fd, dst_fd) == -1) |
344 | retval = -1; | 362 | retval = -1; |
363 | IF_FEATURE_CP_REFLINK(do_close:) | ||
345 | /* Careful with writing... */ | 364 | /* Careful with writing... */ |
346 | if (close(dst_fd) < 0) { | 365 | if (close(dst_fd) < 0) { |
347 | bb_perror_msg("error writing to '%s'", dest); | 366 | bb_perror_msg("error writing to '%s'", dest); |