1 This patch adds support for HFS+ compression.
3 Written by Mike Bombich. Taken from http://www.bombich.com/rsync.html
5 Modified by Wayne to fix some issues and tweak the implementation a bit.
6 This compiles on OS X and passes the testsuite, but otherwise UNTESTED!
8 To use this patch, run these commands for a successful build:
10 patch -p1 <patches/fileflags.diff
11 patch -p1 <patches/crtimes.diff
12 patch -p1 <patches/hfs-compression.diff
18 - Should rsync try to treat the compressed data as file data and use the
19 rsync algorithm on the data transfer?
21 based-on: patch/master/crtimes
22 diff --git a/flist.c b/flist.c
25 @@ -1580,6 +1580,9 @@ static struct file_struct *send_file_name(int f, struct file_list *flist,
27 if (preserve_xattrs) {
28 sx.st.st_mode = file->mode;
29 + if (preserve_fileflags)
30 + sx.st.st_flags = F_FFLAGS(file);
31 + sx.st.st_mtime = file->modtime; /* get_xattr needs mtime for decmpfs xattrs */
32 if (get_xattr(fname, &sx) < 0) {
33 io_error |= IOERR_GENERAL;
35 diff --git a/generator.c b/generator.c
38 @@ -37,6 +37,7 @@ extern int implied_dirs;
39 extern int keep_dirlinks;
40 extern int preserve_acls;
41 extern int preserve_xattrs;
42 +extern int preserve_hfs_compression;
43 extern int preserve_links;
44 extern int preserve_devices;
45 extern int preserve_specials;
46 @@ -1396,6 +1397,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
47 && make_mutable(fname, file->mode, F_FFLAGS(file), force_change))
48 need_retouch_dir_perms = 1;
52 if (!am_root && !(file->mode & S_IWUSR) && dir_tweaking) {
53 mode_t mode = file->mode | S_IWUSR;
54 @@ -1681,6 +1683,14 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
57 sx.st.st_size = F_LENGTH(fuzzy_file);
58 +#ifdef SUPPORT_HFS_COMPRESSION
59 + if (sx.st.st_flags & UF_COMPRESSED) {
60 + if (preserve_hfs_compression)
63 + sx.st.st_flags &= ~UF_COMPRESSED;
67 fnamecmp = fnamecmpbuf;
68 fnamecmp_type = FNAMECMP_FUZZY;
69 @@ -1856,6 +1866,18 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
73 +#ifdef SUPPORT_HFS_COMPRESSION
74 + if (F_FFLAGS(file) & UF_COMPRESSED) {
75 + /* At this point the attrs have already been copied, we don't need to transfer a data fork
76 + * If my filesystem doesn't support HFS compression, the existing file's content
77 + * will not be automatically truncated, so we'll do that manually here */
78 + if (preserve_hfs_compression && sx.st.st_size > 0) {
79 + if (ftruncate(fd, 0) == 0)
85 if (statret != 0 || whole_file)
86 write_sum_head(f_out, NULL);
87 else if (sx.st.st_size <= 0) {
88 diff --git a/lib/sysxattrs.c b/lib/sysxattrs.c
93 #include "sysxattrs.h"
95 +extern int preserve_hfs_compression;
97 +#ifdef HAVE_OSX_XATTRS
98 +#ifndef XATTR_SHOWCOMPRESSION
99 +#define XATTR_SHOWCOMPRESSION 0x0020
101 +#define GETXATTR_FETCH_LIMIT (64*1024*1024)
103 +int xattr_options = XATTR_NOFOLLOW;
106 #ifdef SUPPORT_XATTRS
108 #if defined HAVE_LINUX_XATTRS
109 @@ -55,7 +66,27 @@ ssize_t sys_llistxattr(const char *path, char *list, size_t size)
111 ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
113 - return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
116 + if (preserve_hfs_compression)
117 + xattr_options |= XATTR_SHOWCOMPRESSION;
119 + len = getxattr(path, name, value, size, 0, xattr_options);
121 + /* If we're retrieving data, handle resource forks > 64MB specially */
122 + if (value != NULL && strcmp(name, XATTR_RESOURCEFORK_NAME) == 0 && len == GETXATTR_FETCH_LIMIT) {
123 + /* getxattr will only return 64MB of data at a time, need to call again with a new offset */
124 + u_int32_t offset = GETXATTR_FETCH_LIMIT;
125 + ssize_t data_retrieved = len;
126 + while (data_retrieved < (ssize_t)size) {
127 + len = getxattr(path, name, value + offset, size - data_retrieved, offset, xattr_options);
128 + data_retrieved += len;
129 + offset += (u_int32_t)len;
131 + len = data_retrieved;
137 ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
138 @@ -70,12 +101,16 @@ int sys_lsetxattr(const char *path, const char *name, const void *value, size_t
140 int sys_lremovexattr(const char *path, const char *name)
142 - return removexattr(path, name, XATTR_NOFOLLOW);
143 + if (preserve_hfs_compression)
144 + xattr_options |= XATTR_SHOWCOMPRESSION;
145 + return removexattr(path, name, xattr_options);
148 ssize_t sys_llistxattr(const char *path, char *list, size_t size)
150 - return listxattr(path, list, size, XATTR_NOFOLLOW);
151 + if (preserve_hfs_compression)
152 + xattr_options |= XATTR_SHOWCOMPRESSION;
153 + return listxattr(path, list, size, xattr_options);
156 #elif HAVE_FREEBSD_XATTRS
157 diff --git a/main.c b/main.c
161 #ifdef SUPPORT_FORCE_CHANGE
162 #include <sys/sysctl.h>
164 +#ifdef SUPPORT_HFS_COMPRESSION
165 +#include <sys/attr.h> /* For getattrlist() */
166 +#include <sys/mount.h> /* For statfs() */
170 extern int list_only;
171 @@ -53,7 +57,9 @@ extern int copy_dirlinks;
172 extern int copy_unsafe_links;
173 extern int keep_dirlinks;
174 extern int preserve_hard_links;
175 +extern int preserve_hfs_compression;
176 extern int protocol_version;
177 +extern int force_change;
178 extern int file_total;
180 extern int xfer_dirs;
181 @@ -105,6 +111,7 @@ int daemon_over_rsh = 0;
182 mode_t orig_umask = 0;
183 int batch_gen_fd = -1;
184 int sender_keeps_checksum = 0;
185 +int fs_supports_hfs_compression = 0;
187 /* There's probably never more than at most 2 outstanding child processes,
188 * but set it higher, just in case. */
189 @@ -557,6 +564,43 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
190 return 0; /* not reached */
193 +#ifdef SUPPORT_HFS_COMPRESSION
194 +static void hfs_receiver_check(const char *dest_path)
197 + struct attrlist attrs;
200 + vol_capabilities_set_t caps;
203 + if (preserve_hfs_compression != 1)
204 + return; /* Nothing to check if --hfs-compression option isn't enabled. */
206 + if (statfs(dest_path, &fsb) < 0) {
207 + rsyserr(FERROR, errno, "statfs %s failed", full_fname(dest_path));
208 + exit_cleanup(RERR_FILESELECT);
211 + bzero(&attrs, sizeof attrs);
212 + attrs.bitmapcount = ATTR_BIT_MAP_COUNT;
213 + attrs.volattr = ATTR_VOL_CAPABILITIES;
215 + bzero(&attrData, sizeof attrData);
216 + attrData.len = sizeof attrData;
218 + if (getattrlist(fsb.f_mntonname, &attrs, &attrData, sizeof attrData, 0) < 0) {
219 + rsyserr(FERROR, errno, "getattrlist %s failed", full_fname(dest_path));
220 + exit_cleanup(RERR_FILESELECT);
223 + if (!(attrData.caps[VOL_CAPABILITIES_FORMAT] & VOL_CAP_FMT_DECMPFS_COMPRESSION)) {
224 + rprintf(FERROR, "The destination filesystem does not support HFS+ compression.\n");
225 + exit_cleanup(RERR_UNSUPPORTED);
230 /* The receiving side operates in one of two modes:
232 * 1. it receives any number of files into a destination directory,
233 @@ -615,6 +659,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
234 exit_cleanup(RERR_FILESELECT);
236 filesystem_dev = st.st_dev; /* ensures --force works right w/-x */
237 +#ifdef SUPPORT_HFS_COMPRESSION
238 + hfs_receiver_check(dest_path);
242 if (file_total > 1) {
243 @@ -675,7 +722,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
244 full_fname(dest_path));
245 exit_cleanup(RERR_FILESELECT);
248 +#ifdef SUPPORT_HFS_COMPRESSION
249 + hfs_receiver_check(dest_path);
254 @@ -695,6 +744,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
255 full_fname(dest_path));
256 exit_cleanup(RERR_FILESELECT);
258 +#ifdef SUPPORT_HFS_COMPRESSION
259 + hfs_receiver_check(dest_path);
264 @@ -1081,7 +1133,6 @@ int child_main(int argc, char *argv[])
269 void start_server(int f_in, int f_out, int argc, char *argv[])
271 set_nonblocking(f_in);
272 diff --git a/options.c b/options.c
275 @@ -52,6 +52,7 @@ int preserve_links = 0;
276 int preserve_hard_links = 0;
277 int preserve_acls = 0;
278 int preserve_xattrs = 0;
279 +int preserve_hfs_compression = 0;
280 int preserve_perms = 0;
281 int preserve_fileflags = 0;
282 int preserve_executability = 0;
283 @@ -703,6 +704,10 @@ void usage(enum logcode F)
284 #ifdef SUPPORT_XATTRS
285 rprintf(F," -X, --xattrs preserve extended attributes\n");
287 +#ifdef SUPPORT_HFS_COMPRESSION
288 + rprintf(F," --hfs-compression preserve HFS compression if supported\n");
289 + rprintf(F," --protect-decmpfs preserve HFS compression as xattrs\n");
291 rprintf(F," -o, --owner preserve owner (super-user only)\n");
292 rprintf(F," -g, --group preserve group\n");
293 rprintf(F," --devices preserve device files (super-user only)\n");
294 @@ -954,6 +959,12 @@ static struct poptOption long_options[] = {
295 {"force-uchange", 0, POPT_ARG_VAL, &force_change, USR_IMMUTABLE, 0, 0 },
296 {"force-schange", 0, POPT_ARG_VAL, &force_change, SYS_IMMUTABLE, 0, 0 },
298 +#ifdef SUPPORT_HFS_COMPRESSION
299 + {"hfs-compression", 0, POPT_ARG_VAL, &preserve_hfs_compression, 1, 0, 0 },
300 + {"no-hfs-compression",0, POPT_ARG_VAL, &preserve_hfs_compression, 0, 0, 0 },
301 + {"protect-decmpfs", 0, POPT_ARG_VAL, &preserve_hfs_compression, 2, 0, 0 },
302 + {"no-protect-decmpfs",0, POPT_ARG_VAL, &preserve_hfs_compression, 0, 0, 0 },
304 {"ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 1, 0, 0 },
305 {"no-ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 0, 0, 0 },
306 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
307 @@ -1902,6 +1913,15 @@ int parse_arguments(int *argc_p, const char ***argv_p)
311 +#ifdef SUPPORT_HFS_COMPRESSION
312 + if (preserve_hfs_compression) {
313 + if (!preserve_xattrs)
314 + preserve_xattrs = 1;
315 + if (!preserve_fileflags)
316 + preserve_fileflags = 1;
320 if (write_batch && read_batch) {
321 snprintf(err_buf, sizeof err_buf,
322 "--write-batch and --read-batch can not be used together\n");
323 @@ -2486,6 +2506,11 @@ void server_options(char **args, int *argc_p)
324 if (preserve_fileflags)
325 args[ac++] = "--fileflags";
327 +#ifdef SUPPORT_HFS_COMPRESSION
328 + if (preserve_hfs_compression)
329 + args[ac++] = preserve_hfs_compression == 1 ? "--hfs-compression" : "--protect-decmpfs";
332 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
333 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
335 diff --git a/rsync.c b/rsync.c
338 @@ -517,8 +517,14 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
339 #ifdef SUPPORT_XATTRS
341 set_stat_xattr(fname, file, new_mode);
342 - if (preserve_xattrs && fnamecmp)
343 + if (preserve_xattrs && fnamecmp) {
344 + uint32 tmpflags = sxp->st.st_flags;
345 + sxp->st.st_flags = F_FFLAGS(file); /* set_xattr() needs to check UF_COMPRESSED */
346 set_xattr(fname, file, fnamecmp, sxp);
347 + sxp->st.st_flags = tmpflags;
348 + if (S_ISDIR(sxp->st.st_mode))
349 + link_stat(fname, &sx2.st, 0);
354 @@ -529,6 +535,9 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
355 if (sxp->st.st_ino == 2 && S_ISDIR(sxp->st.st_mode))
356 flags |= ATTRS_SKIP_CRTIME;
357 if (!(flags & ATTRS_SKIP_MTIME)
358 +#ifdef SUPPORT_HFS_COMPRESSION
359 + && !(sxp->st.st_flags & UF_COMPRESSED) /* setting this alters mtime, so defer to after set_fileflags */
361 && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
362 int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), sxp->st.st_mode, ST_FLAGS(sxp->st));
364 @@ -634,6 +643,16 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
365 && !set_fileflags(fname, fileflags))
368 +#ifdef SUPPORT_HFS_COMPRESSION
369 + int ret = set_modtime(fname, file->modtime, new_mode, fileflags);
371 + rsyserr(FERROR_XFER, errno, "failed to set times on %s",
372 + full_fname(fname));
376 + file->flags |= FLAG_TIME_FAILED;
381 diff --git a/rsync.h b/rsync.h
384 @@ -540,6 +540,17 @@ typedef unsigned int size_t;
385 #define ST_FLAGS(st) NO_FFLAGS
388 +#ifndef UF_COMPRESSED
389 +#define UF_COMPRESSED 0x00000020
391 +#ifndef VOL_CAP_FMT_DECMPFS_COMPRESSION
392 +#define VOL_CAP_FMT_DECMPFS_COMPRESSION 0x00010000
395 +#if defined SUPPORT_XATTRS && defined SUPPORT_FILEFLAGS
396 +#define SUPPORT_HFS_COMPRESSION 1
399 /* Find a variable that is either exactly 32-bits or longer.
400 * If some code depends on 32-bit truncation, it will need to
401 * take special action in a "#if SIZEOF_INT32 > 4" section. */
402 diff --git a/rsync.yo b/rsync.yo
405 @@ -350,6 +350,8 @@ to the detailed description below for a complete description. verb(
406 --chmod=CHMOD affect file and/or directory permissions
407 -A, --acls preserve ACLs (implies -p)
408 -X, --xattrs preserve extended attributes
409 + --hfs-compression preserve HFS compression if supported
410 + --protect-decmpfs preserve HFS compression as xattrs
411 -o, --owner preserve owner (super-user only)
412 -g, --group preserve group
413 --devices preserve device files (super-user only)
414 @@ -1087,6 +1089,42 @@ flags on files and directories that are being updated or deleted on the
415 receiving side. It does not try to affect user flags. This option overrides
416 bf(--force-change) and bf(--force-schange).
418 +dit(bf(--hfs-compression)) This option causes rsync to preserve HFS+
419 +compression if the destination filesystem supports it. If the destination
420 +does not support it, rsync will exit with an error.
422 +Filesystem compression was introduced to HFS+ in Mac OS 10.6. A file that is
423 +compressed has no data in its data fork. Rather, the compressed data is stored
424 +in an extended attribute named com.apple.decmpfs and a file flag is set to
425 +indicate that the file is compressed (UF_COMPRESSED). HFS+ decompresses this
426 +data "on-the-fly" and presents it to the operating system as a normal file.
427 +Normal attempts to copy compressed files (e.g. in the Finder, via cp, ditto,
428 +etc.) will copy the file's decompressed contents, remove the UF_COMPRESSED file
429 +flag, and discard the com.apple.decmpfs extended attribute. This option will
430 +preserve the data in the com.apple.decmpfs extended attribute and ignore the
431 +synthesized data in the file contents.
433 +This option implies both bf(--fileflags) and (--xattrs).
435 +dit(bf(--protect-decmpfs)) The com.apple.decmpfs extended attribute is hidden
436 +by default from list/get xattr calls, therefore normal attempts to copy
437 +compressed files will functionally decompress those files. While this is
438 +desirable behavior when copying files to filesystems that do not support HFS+
439 +compression, it has serious performance and capacity impacts when backing up
440 +or restoring the Mac OS X filesystem.
442 +This option will transfer the com.apple.decmpfs extended attribute regardless
443 +of support on the destination. If a source file is compressed and an existing
444 +file on the destination is not compressed, the data fork of the destination
445 +file will be truncated and the com.apple.decmpfs xattr will be transferred
446 +instead. Note that compressed files will not be readable to the operating
447 +system of the destination if that operating system does not support HFS+
448 +compression. Once restored (with or without this option) to an operating system
449 +that supports HFS+ compression, however, these files will be accessible as
452 +This option implies bf(--fileflags) and bf(--xattrs).
454 dit(bf(--chmod)) This option tells rsync to apply one or more
455 comma-separated "chmod" modes to the permission of the files in the
456 transfer. The resulting value is treated as though it were the permissions
457 diff --git a/t_stub.c b/t_stub.c
460 @@ -28,6 +28,7 @@ int module_dirlen = 0;
461 int force_change = 0;
462 int preserve_times = 0;
463 int preserve_xattrs = 0;
464 +int preserve_hfs_compression = 0;
465 char number_separator = ',';
468 diff --git a/xattrs.c b/xattrs.c
471 @@ -33,6 +33,7 @@ extern int am_generator;
472 extern int read_only;
473 extern int list_only;
474 extern int preserve_xattrs;
475 +extern int preserve_hfs_compression;
476 extern int preserve_links;
477 extern int preserve_devices;
478 extern int preserve_specials;
479 @@ -41,6 +42,10 @@ extern int checksum_seed;
480 #define RSYNC_XAL_INITIAL 5
481 #define RSYNC_XAL_LIST_INITIAL 100
483 +#define GXD_NO_MISSING_ERROR (1<<0)
484 +#define GXD_OMIT_COMPRESSED (1<<1)
485 +#define GXD_FILE_IS_COMPRESSED (1<<2)
487 #define MAX_FULL_DATUM 32
489 #define HAS_PREFIX(str, prfx) (*(str) == *(prfx) \
490 @@ -73,6 +78,17 @@ extern int checksum_seed;
491 #define XDEF_ACL_SUFFIX "dacl"
492 #define XDEF_ACL_ATTR RSYNC_PREFIX "%" XDEF_ACL_SUFFIX
494 +#define APPLE_PREFIX "com.apple."
495 +#define APLPRE_LEN ((int)sizeof APPLE_PREFIX - 1)
496 +#define DECMPFS_SUFFIX "decmpfs"
497 +#define RESOURCEFORK_SUFFIX "ResourceFork"
499 +#define UNREAD_DATA ((char *)1)
501 +#if MAX_DIGEST_LEN < SIZEOF_TIME_T
502 +#error MAX_DIGEST_LEN is too small to hold an mtime
507 size_t datum_len, name_len;
508 @@ -164,8 +180,7 @@ static ssize_t get_xattr_names(const char *fname)
509 /* On entry, the *len_ptr parameter contains the size of the extra space we
510 * should allocate when we create a buffer for the data. On exit, it contains
511 * the length of the datum. */
512 -static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr,
513 - int no_missing_error)
514 +static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr, int flags)
516 size_t datum_len = sys_lgetxattr(fname, name, NULL, 0);
517 size_t extra_len = *len_ptr;
518 @@ -174,7 +189,7 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
519 *len_ptr = datum_len;
521 if (datum_len == (size_t)-1) {
522 - if (errno == ENOTSUP || no_missing_error)
523 + if (errno == ENOTSUP || flags & GXD_NO_MISSING_ERROR)
525 rsyserr(FERROR_XFER, errno,
526 "get_xattr_data: lgetxattr(\"%s\",\"%s\",0) failed",
527 @@ -182,6 +197,15 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
531 + if (flags & GXD_OMIT_COMPRESSED && datum_len > MAX_FULL_DATUM
532 + && HAS_PREFIX(name, APPLE_PREFIX)
533 + && (strcmp(name+APLPRE_LEN, DECMPFS_SUFFIX) == 0
534 + || (flags & GXD_FILE_IS_COMPRESSED && strcmp(name+APLPRE_LEN, RESOURCEFORK_SUFFIX) == 0))) {
535 + /* If we are omitting compress-file-related data, we don't want to
536 + * actually read this data. */
537 + return UNREAD_DATA;
540 if (!datum_len && !extra_len)
541 extra_len = 1; /* request non-zero amount of memory */
542 if (datum_len + extra_len < datum_len)
543 @@ -210,7 +234,29 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
547 -static int rsync_xal_get(const char *fname, item_list *xalp)
548 +static void checksum_xattr_data(char *sum, const char *datum, size_t datum_len, stat_x *sxp)
550 + if (datum == UNREAD_DATA) {
551 + /* For abbreviated compressed data, we store the file's mtime as the checksum. */
552 + SIVAL(sum, 0, sxp->st.st_mtime);
553 +#if SIZEOF_TIME_T > 4
554 + SIVAL(sum, 4, sxp->st.st_mtime >> 32);
555 +#if MAX_DIGEST_LEN > 8
556 + memset(sum + 8, 0, MAX_DIGEST_LEN - 8);
559 +#if MAX_DIGEST_LEN > 4
560 + memset(sum + 4, 0, MAX_DIGEST_LEN - 4);
564 + sum_init(checksum_seed);
565 + sum_update(datum, datum_len);
570 +static int rsync_xal_get(const char *fname, stat_x *sxp)
572 ssize_t list_len, name_len;
573 size_t datum_len, name_offset;
574 @@ -219,7 +265,8 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
575 int user_only = am_sender ? 0 : !am_root;
580 + item_list *xalp = sxp->xattr;
582 /* This puts the name list into the "namebuf" buffer. */
583 if ((list_len = get_xattr_names(fname)) < 0)
584 @@ -249,20 +296,22 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
587 datum_len = name_len; /* Pass extra size to get_xattr_data() */
588 - if (!(ptr = get_xattr_data(fname, name, &datum_len, 0)))
589 + flags = GXD_OMIT_COMPRESSED;
590 + if (preserve_hfs_compression && sxp->st.st_flags & UF_COMPRESSED)
591 + flags |= GXD_FILE_IS_COMPRESSED;
592 + if (!(ptr = get_xattr_data(fname, name, &datum_len, flags)))
595 if (datum_len > MAX_FULL_DATUM) {
596 /* For large datums, we store a flag and a checksum. */
598 name_offset = 1 + MAX_DIGEST_LEN;
599 - sum_init(checksum_seed);
600 - sum_update(ptr, datum_len);
603 if (!(ptr = new_array(char, name_offset + name_len)))
604 out_of_memory("rsync_xal_get");
605 *ptr = XSTATE_ABBREV;
607 + checksum_xattr_data(ptr+1, datum, datum_len, sxp);
608 + if (datum != UNREAD_DATA)
611 name_offset = datum_len;
613 @@ -307,7 +356,7 @@ int get_xattr(const char *fname, stat_x *sxp)
617 - if (rsync_xal_get(fname, sxp->xattr) < 0) {
618 + if (rsync_xal_get(fname, sxp) < 0) {
622 @@ -358,6 +407,10 @@ int copy_xattrs(const char *source, const char *dest)
624 static int find_matching_xattr(item_list *xalp)
626 +#ifdef HAVE_OSX_XATTRS
628 + return -1; /* find_matching_xattr is a waste of cycles for MOSX clients */
631 item_list *lst = rsync_xal_l.items;
633 @@ -391,6 +444,7 @@ static int find_matching_xattr(item_list *xalp)
640 /* Store *xalp on the end of rsync_xal_l */
641 @@ -570,7 +624,8 @@ void send_xattr_request(const char *fname, struct file_struct *file, int f_out)
643 /* Re-read the long datum. */
644 if (!(ptr = get_xattr_data(fname, rxa->name, &len, 0))) {
645 - rprintf(FERROR_XFER, "failed to re-read xattr %s for %s\n", rxa->name, fname);
646 + if (errno != ENOTSUP && errno != ENOATTR)
647 + rprintf(FERROR_XFER, "failed to re-read xattr %s for %s\n", rxa->name, fname);
648 write_varint(f_out, 0);
651 @@ -792,7 +847,7 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
652 int user_only = am_root <= 0;
656 + int flags, ret = 0;
658 /* This puts the current name list into the "namebuf" buffer. */
659 if ((list_len = get_xattr_names(fname)) < 0)
660 @@ -804,7 +859,10 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
661 if (XATTR_ABBREV(rxas[i])) {
662 /* See if the fnamecmp version is identical. */
663 len = name_len = rxas[i].name_len;
664 - if ((ptr = get_xattr_data(fnamecmp, name, &len, 1)) == NULL) {
665 + flags = GXD_OMIT_COMPRESSED | GXD_NO_MISSING_ERROR;
666 + if (preserve_hfs_compression && sxp->st.st_flags & UF_COMPRESSED)
667 + flags |= GXD_FILE_IS_COMPRESSED;
668 + if ((ptr = get_xattr_data(fnamecmp, name, &len, flags)) == NULL) {
672 @@ -818,9 +876,7 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
676 - sum_init(checksum_seed);
677 - sum_update(ptr, len);
679 + checksum_xattr_data(sum, ptr, len, sxp);
680 if (memcmp(sum, rxas[i].datum + 1, MAX_DIGEST_LEN) != 0) {
683 @@ -889,6 +945,10 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
687 +#ifdef HAVE_OSX_XATTRS
688 + rsync_xal_free(xalp); /* Free this because we aren't using find_matching_xattr(). */
694 @@ -935,7 +995,7 @@ char *get_xattr_acl(const char *fname, int is_access_acl, size_t *len_p)
696 const char *name = is_access_acl ? XACC_ACL_ATTR : XDEF_ACL_ATTR;
697 *len_p = 0; /* no extra data alloc needed from get_xattr_data() */
698 - return get_xattr_data(fname, name, len_p, 1);
699 + return get_xattr_data(fname, name, len_p, GXD_NO_MISSING_ERROR);
702 int set_xattr_acl(const char *fname, int is_access_acl, const char *buf, size_t buf_len)
703 @@ -1078,11 +1138,33 @@ int set_stat_xattr(const char *fname, struct file_struct *file, mode_t new_mode)
707 +#ifdef SUPPORT_HFS_COMPRESSION
708 +static inline void hfs_compress_tweaks(STRUCT_STAT *fst)
710 + if (fst->st_flags & UF_COMPRESSED) {
711 + if (preserve_hfs_compression) {
712 + /* We're sending the compression xattr, not the decompressed data fork.
713 + * Setting rsync's idea of the file size to 0 effectively prevents the
714 + * transfer of the data fork. */
717 + /* If the sender's filesystem supports compression, then we'll be able
718 + * to send the decompressed data fork and the decmpfs xattr will be
719 + * hidden (not sent). As such, we need to strip the compression flag. */
720 + fst->st_flags &= ~UF_COMPRESSED;
726 int x_stat(const char *fname, STRUCT_STAT *fst, STRUCT_STAT *xst)
728 int ret = do_stat(fname, fst);
729 if ((ret < 0 || get_stat_xattr(fname, -1, fst, xst) < 0) && xst)
731 +#ifdef SUPPORT_HFS_COMPRESSION
732 + hfs_compress_tweaks(fst);
737 @@ -1091,6 +1173,9 @@ int x_lstat(const char *fname, STRUCT_STAT *fst, STRUCT_STAT *xst)
738 int ret = do_lstat(fname, fst);
739 if ((ret < 0 || get_stat_xattr(fname, -1, fst, xst) < 0) && xst)
741 +#ifdef SUPPORT_HFS_COMPRESSION
742 + hfs_compress_tweaks(fst);
747 @@ -1099,6 +1184,9 @@ int x_fstat(int fd, STRUCT_STAT *fst, STRUCT_STAT *xst)
748 int ret = do_fstat(fd, fst);
749 if ((ret < 0 || get_stat_xattr(NULL, fd, fst, xst) < 0) && xst)
751 +#ifdef SUPPORT_HFS_COMPRESSION
752 + hfs_compress_tweaks(fst);