1 This patch handles the creation time on OS X by putting it into an
2 extended attribute. This is a modified version of a patch that was
3 provided by Wesley W. Terpstra.
5 To use this patch, run these commands for a successful build:
7 patch -p1 <patches/osx-create-time.diff
8 ./configure (optional if already run)
11 --- old/lib/sysxattrs.c
12 +++ new/lib/sysxattrs.c
13 @@ -52,29 +52,118 @@ ssize_t sys_llistxattr(const char *path,
17 +#include <sys/attr.h>
19 +#define CRTIME_XATTR "com.apple.crtime96"
20 +#define IS_CRTIME(name) (*(name) == *CRTIME_XATTR && strcmp(name, CRTIME_XATTR) == 0)
21 +#define CRTIME_XATTR_LEN (8+4)
23 +struct CreationTime {
24 + unsigned long length;
25 + struct timespec crtime;
28 +static struct timespec *getCreationTime(const char *path)
30 + static struct CreationTime attrBuf;
31 + struct attrlist attrList;
33 + memset(&attrList, 0, sizeof attrList);
34 + attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
35 + attrList.commonattr = ATTR_CMN_CRTIME;
36 + if (getattrlist(path, &attrList, &attrBuf, sizeof attrBuf, FSOPT_NOFOLLOW) < 0)
38 + return &attrBuf.crtime;
41 +static ssize_t get_crtime_xattr(const char *path, char *buf, size_t size)
43 + struct timespec *crtime_p;
46 + return CRTIME_XATTR_LEN;
47 + if (size < CRTIME_XATTR_LEN)
48 + return -1; /* Doesn't happen with rsync code... */
50 + if ((crtime_p = getCreationTime(path)) == NULL)
53 + SIVAL(buf, 0, crtime_p->tv_sec);
54 +#if SIZEOF_TIME_T > 4
55 + SIVAL(buf, 4, crtime_p->tv_sec >> 32);
59 + SIVAL(buf, 8, crtime_p->tv_nsec);
61 + return CRTIME_XATTR_LEN;
64 +static int set_crtime_xattr(const char *path, const char *buf, size_t size)
66 + struct attrlist attrList;
67 + struct timespec crtime;
69 + if (size != CRTIME_XATTR_LEN)
72 + crtime.tv_sec = IVAL(buf, 0);
73 +#if SIZEOF_TIME_T > 4
74 + crtime.tv_sec += (time_t)IVAL(buf, 4) << 32;
76 + crtime.tv_nsec = IVAL(buf, 8);
78 + memset(&attrList, 0, sizeof attrList);
79 + attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
80 + attrList.commonattr = ATTR_CMN_CRTIME;
81 + return setattrlist(path, &attrList, &crtime, sizeof crtime, FSOPT_NOFOLLOW);
84 ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
86 + if (IS_CRTIME(name))
87 + return get_crtime_xattr(path, value, size);
88 return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
91 ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
93 + /* XXX Figure out how to get creation time from an open filedes? */
94 return fgetxattr(filedes, name, value, size, 0, 0);
97 int sys_lsetxattr(const char *path, const char *name, const void *value, size_t size)
99 + if (IS_CRTIME(name))
100 + return set_crtime_xattr(path, value, size);
101 return setxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
104 int sys_lremovexattr(const char *path, const char *name)
106 + /* Every file on hfs+ has this; you can't remove it... */
107 + if (IS_CRTIME(name))
109 return removexattr(path, name, XATTR_NOFOLLOW);
112 ssize_t sys_llistxattr(const char *path, char *list, size_t size)
114 - return listxattr(path, list, size, XATTR_NOFOLLOW);
115 + ssize_t ret = listxattr(path, list, size, XATTR_NOFOLLOW);
118 + if (getCreationTime(path) != NULL) {
119 + ret += sizeof CRTIME_XATTR;
121 + if ((size_t)ret > size) {
125 + memcpy(list + ret - sizeof CRTIME_XATTR,
126 + CRTIME_XATTR, sizeof CRTIME_XATTR);
132 #elif HAVE_FREEBSD_XATTRS