emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Btrfs clone support in copy operations


From: Kieran Colford
Subject: Btrfs clone support in copy operations
Date: Tue, 05 Jul 2016 15:06:42 -0400

I've put together a patch for supporting the btrfs clone operation for
copying

diff --git a/src/fileio.c b/src/fileio.c
index b1f9d3c..d7c1e6e 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -21,6 +21,7 @@ along with GNU Emacs.  If not, see 
<http://www.gnu.org/licenses/>.  */
 #include <limits.h>
 #include <fcntl.h>
 #include "sysstdio.h"
+#include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -1988,6 +1989,16 @@ permissions.  */)
        oldsize = out_st.st_size;
     }
 
+  /* Perform the O(1) btrfs clone operation, if possible. */
+#ifdef __linux__
+# undef BTRFS_IOCTL_MAGIC
+# define BTRFS_IOCTL_MAGIC 0x94
+# undef BTRFS_IOC_CLONE
+# define BTRFS_IOC_CLONE _IOW (BTRFS_IOCTL_MAGIC, 9, int)
+  if (ioctl (ofd, BTRFS_IOC_CLONE, ifd) == 0)
+    goto done_copy;
+#endif
+
   immediate_quit = 1;
   QUIT;
   while (true)
@@ -2011,6 +2022,8 @@ permissions.  */)
 
   immediate_quit = 0;
 
+ done_copy:
+
 #ifndef MSDOS
   /* Preserve the original file permissions, and if requested, also its
      owner and group.  */

-- 
Kieran Colford <address@hidden>

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]