From 890aa44718345e979be01a584697ea9d95e84f8d Mon Sep 17 00:00:00 2001
From: Dharanendiran <dharanendiran@timesys.com>
Date: Tue, 29 Sep 2026 18:46:44 +0530
Subject: [PATCH] Check for FICLONERANGE before using reflink

---
 lib/replace/replace.c | 2 +-
 source3/wscript       | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index dd07e6c..6950bdb 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -1255,7 +1255,7 @@ ssize_t rep_copy_reflink(int src_fd,
 			 off_t dst_off,
 			 off_t to_copy)
 {
-#ifdef HAVE_LINUX_IOCTL
+#ifdef HAVE_FICLONERANGE
 	struct file_clone_range cr;
 
 	cr = (struct file_clone_range) {
diff --git a/source3/wscript b/source3/wscript
index 342f2f0..44070fc 100644
--- a/source3/wscript
+++ b/source3/wscript
@@ -1654,6 +1654,9 @@ int main(void) {
         conf.CHECK_DECLS('FS_IOC_GETFLAGS FS_COMPR_FL', headers='linux/fs.h')):
             conf.DEFINE('HAVE_LINUX_IOCTL', '1')
 
+    if conf.CHECK_DECLS('FICLONERANGE', headers='linux/fs.h'):
+        conf.DEFINE('HAVE_FICLONERANGE', '1')
+
     conf.env['CFLAGS_CEPHFS'] = "-D_FILE_OFFSET_BITS=64"
 
     if (Options.options.with_cephfs is not False and
-- 
2.25.1

