1Index: src/auto/config.h
2===================================================================
3--- src/auto/config.h	(revision 57762)
4+++ src/auto/config.h	(working copy)
5@@ -432,3 +432,9 @@
6 
7 /* Define if fcntl()'s F_SETFD command knows about FD_CLOEXEC */
8 #define HAVE_FD_CLOEXEC 1
9+
10+/* Define if there is a copyfile() */
11+#define HAVE_COPYFILE 1
12+
13+/* Define if there is a copyfile.h */
14+#define HAVE_COPYFILE_H 1
15Index: src/fileio.c
16===================================================================
17--- src/fileio.c	(revision 57776)
18+++ src/fileio.c	(working copy)
19@@ -29,6 +29,10 @@
20 # include <utime.h>		/* for struct utimbuf */
21 #endif
22 
23+#if defined(HAVE_COPYFILE_H)
24+#include <copyfile.h>
25+#endif
26+
27 #define BUFSIZE		8192	/* size of normal write buffer */
28 #define SMBUFSIZE	256	/* size of emergency write buffer */
29 
30@@ -3220,6 +3217,9 @@
31     int		    write_undo_file = FALSE;
32     context_sha256_T sha_ctx;
33 #endif
34+#ifdef HAVE_COPYFILE
35+    copyfile_state_t	copyfile_state = NULL;
36+#endif
37 
38     if (fname == NULL || *fname == NUL)	/* safety check */
39 	return FAIL;
40@@ -3659,6 +3666,13 @@
41     if (!newfile)
42 	acl = mch_get_acl(fname);
43 #endif
44+#ifdef HAVE_COPYFILE
45+    if (!newfile && copyfile((char*)fname, NULL, 0, COPYFILE_XATTR | COPYFILE_CHECK))
46+    {
47+	copyfile_state = copyfile_state_alloc();
48+	copyfile((char*)fname, NULL, copyfile_state, 0);
49+    }
50+#endif
51 
52     /*
53      * If 'backupskip' is not empty, don't make a backup for some files.
54@@ -4037,6 +4051,10 @@
55 #ifdef HAVE_ACL
56 			mch_set_acl(backup, acl);
57 #endif
58+#ifdef HAVE_COPYFILE
59+			if (copyfile_state)
60+			copyfile(NULL, (char*)backup, copyfile_state, COPYFILE_XATTR);
61+#endif
62 #ifdef HAVE_SELINUX
63 			mch_copy_sec(fname, backup);
64 #endif
65@@ -4717,6 +4735,10 @@
66 	/* Set the inode when creating a new file. */
67 	buf_setino(buf);
68 #endif
69+#ifdef HAVE_COPYFILE
70+    if (!backup_copy && copyfile_state)
71+	copyfile(NULL, (char*)wfname, copyfile_state, COPYFILE_XATTR);
72+#endif
73 
74     if (close(fd) != 0)
75     {
76@@ -5036,6 +5058,10 @@
77 #ifdef HAVE_ACL
78     mch_free_acl(acl);
79 #endif
80+#ifdef HAVE_COPYFILE
81+    if (copyfile_state)
82+	copyfile_state_free(copyfile_state);
83+#endif
84 
85     if (errmsg != NULL)
86     {
87