]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libreplace: add rep_copy_reflink()
authorRalph Boehme <slow@samba.org>
Sun, 24 Mar 2024 16:02:21 +0000 (17:02 +0100)
committerRalph Boehme <slow@samba.org>
Tue, 20 Aug 2024 05:41:32 +0000 (05:41 +0000)
FICLONERANGE was introduced in kernel version 4.5, so I guess we can just assume
it is present if HAVE_LINUX_IOCTL is defined.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
lib/replace/replace.c
lib/replace/replace.h

index 68829f2a3c9701914357c6ea4f7bde268b3d5c01..0b4e06d8bd53741089f99b646f4be1a7196dc36a 100644 (file)
@@ -1083,6 +1083,34 @@ ssize_t rep_copy_file_range(int fd_in,
 }
 #endif /* HAVE_COPY_FILE_RANGE */
 
+#ifdef HAVE_LINUX_IOCTL
+# include <linux/fs.h>
+# include <sys/ioctl.h>
+#endif
+
+ssize_t rep_copy_reflink(int src_fd,
+                        off_t src_off,
+                        int dst_fd,
+                        off_t dst_off,
+                        off_t to_copy)
+{
+#ifdef HAVE_LINUX_IOCTL
+       struct file_clone_range cr;
+
+       cr = (struct file_clone_range) {
+               .src_fd = src_fd,
+               .src_offset = (uint64_t)src_off,
+               .dest_offset = (uint64_t)dst_off,
+               .src_length = (uint64_t)to_copy,
+       };
+
+       return ioctl(dst_fd, FICLONERANGE, &cr);
+#else
+       errno = ENOSYS;
+       return -1;
+#endif
+}
+
 #ifndef HAVE_OPENAT2
 
 /* fallback known wellknown __NR_openat2 values */
index 537e61e1e4888ed0b0327509ecda6d8b677944aa..586f4e0a5751f7eade6555a02310610cf0ee5a8a 100644 (file)
@@ -1014,6 +1014,15 @@ ssize_t rep_copy_file_range(int fd_in,
                            unsigned int flags);
 #endif /* HAVE_COPY_FILE_RANGE */
 
+
+#define copy_reflink rep_copy_reflink
+
+ssize_t rep_copy_reflink(int src_fd,
+                        off_t src_off,
+                        int dst_fd,
+                        off_t dst_off,
+                        off_t to_copy);
+
 #ifndef FALL_THROUGH
 # ifdef HAVE_FALLTHROUGH_ATTRIBUTE
 #  define FALL_THROUGH __attribute__ ((fallthrough))