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 @@ -1573,6 +1573,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 @@ -1744,6 +1745,14 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
49 sx.st.st_size = F_LENGTH(fuzzy_file);
50 +#ifdef SUPPORT_HFS_COMPRESSION
51 + if (sx.st.st_flags & UF_COMPRESSED) {
52 + if (preserve_hfs_compression)
55 + sx.st.st_flags &= ~UF_COMPRESSED;
59 fnamecmp = fnamecmpbuf;
61 @@ -1911,6 +1920,18 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
65 +#ifdef SUPPORT_HFS_COMPRESSION
66 + if (F_FFLAGS(file) & UF_COMPRESSED) {
67 + /* At this point the attrs have already been copied, we don't need to transfer a data fork
68 + * If my filesystem doesn't support HFS compression, the existing file's content
69 + * will not be automatically truncated, so we'll do that manually here */
70 + if (preserve_hfs_compression && sx.st.st_size > 0) {
71 + if (ftruncate(fd, 0) == 0)
77 if (statret != 0 || whole_file)
78 write_sum_head(f_out, NULL);
79 else if (sx.st.st_size <= 0) {
80 diff --git a/lib/sysxattrs.c b/lib/sysxattrs.c
85 #include "sysxattrs.h"
87 +extern int preserve_hfs_compression;
89 +#ifdef HAVE_OSX_XATTRS
90 +#ifndef XATTR_SHOWCOMPRESSION
91 +#define XATTR_SHOWCOMPRESSION 0x0020
93 +#define GETXATTR_FETCH_LIMIT (64*1024*1024)
95 +int xattr_options = XATTR_NOFOLLOW;
100 #if defined HAVE_LINUX_XATTRS
101 @@ -55,7 +66,27 @@ ssize_t sys_llistxattr(const char *path, char *list, size_t size)
103 ssize_t sys_lgetxattr(const char *path, const char *name, void *value, size_t size)
105 - return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
108 + if (preserve_hfs_compression)
109 + xattr_options |= XATTR_SHOWCOMPRESSION;
111 + len = getxattr(path, name, value, size, 0, xattr_options);
113 + /* If we're retrieving data, handle resource forks > 64MB specially */
114 + if (value != NULL && strcmp(name, XATTR_RESOURCEFORK_NAME) == 0 && len == GETXATTR_FETCH_LIMIT) {
115 + /* getxattr will only return 64MB of data at a time, need to call again with a new offset */
116 + u_int32_t offset = GETXATTR_FETCH_LIMIT;
117 + ssize_t data_retrieved = len;
118 + while (data_retrieved < (ssize_t)size) {
119 + len = getxattr(path, name, value + offset, size - data_retrieved, offset, xattr_options);
120 + data_retrieved += len;
121 + offset += (u_int32_t)len;
123 + len = data_retrieved;
129 ssize_t sys_fgetxattr(int filedes, const char *name, void *value, size_t size)
130 @@ -70,12 +101,16 @@ int sys_lsetxattr(const char *path, const char *name, const void *value, size_t
132 int sys_lremovexattr(const char *path, const char *name)
134 - return removexattr(path, name, XATTR_NOFOLLOW);
135 + if (preserve_hfs_compression)
136 + xattr_options |= XATTR_SHOWCOMPRESSION;
137 + return removexattr(path, name, xattr_options);
140 ssize_t sys_llistxattr(const char *path, char *list, size_t size)
142 - return listxattr(path, list, size, XATTR_NOFOLLOW);
143 + if (preserve_hfs_compression)
144 + xattr_options |= XATTR_SHOWCOMPRESSION;
145 + return listxattr(path, list, size, xattr_options);
148 #elif HAVE_FREEBSD_XATTRS
149 diff --git a/main.c b/main.c
153 #ifdef SUPPORT_FORCE_CHANGE
154 #include <sys/sysctl.h>
156 +#ifdef SUPPORT_HFS_COMPRESSION
157 +#include <sys/attr.h> /* For getattrlist() */
158 +#include <sys/mount.h> /* For statfs() */
162 extern int list_only;
163 @@ -53,7 +57,9 @@ extern int copy_dirlinks;
164 extern int copy_unsafe_links;
165 extern int keep_dirlinks;
166 extern int preserve_hard_links;
167 +extern int preserve_hfs_compression;
168 extern int protocol_version;
169 +extern int force_change;
170 extern int file_total;
172 extern int xfer_dirs;
173 @@ -106,6 +112,7 @@ int daemon_over_rsh = 0;
174 mode_t orig_umask = 0;
175 int batch_gen_fd = -1;
176 int sender_keeps_checksum = 0;
177 +int fs_supports_hfs_compression = 0;
179 /* There's probably never more than at most 2 outstanding child processes,
180 * but set it higher, just in case. */
181 @@ -558,6 +565,43 @@ static pid_t do_cmd(char *cmd, char *machine, char *user, char **remote_argv, in
182 return 0; /* not reached */
185 +#ifdef SUPPORT_HFS_COMPRESSION
186 +static void hfs_receiver_check(void)
189 + struct attrlist attrs;
192 + vol_capabilities_set_t caps;
195 + if (preserve_hfs_compression != 1)
196 + return; /* Nothing to check if --hfs-compression option isn't enabled. */
198 + if (statfs(".", &fsb) < 0) {
199 + rsyserr(FERROR, errno, "statfs %s failed", curr_dir);
200 + exit_cleanup(RERR_FILESELECT);
203 + bzero(&attrs, sizeof attrs);
204 + attrs.bitmapcount = ATTR_BIT_MAP_COUNT;
205 + attrs.volattr = ATTR_VOL_CAPABILITIES;
207 + bzero(&attrData, sizeof attrData);
208 + attrData.len = sizeof attrData;
210 + if (getattrlist(fsb.f_mntonname, &attrs, &attrData, sizeof attrData, 0) < 0) {
211 + rsyserr(FERROR, errno, "getattrlist %s failed", curr_dir);
212 + exit_cleanup(RERR_FILESELECT);
215 + if (!(attrData.caps[VOL_CAPABILITIES_FORMAT] & VOL_CAP_FMT_DECMPFS_COMPRESSION)) {
216 + rprintf(FERROR, "The destination filesystem does not support HFS+ compression.\n");
217 + exit_cleanup(RERR_UNSUPPORTED);
222 /* The receiving side operates in one of two modes:
224 * 1. it receives any number of files into a destination directory,
225 @@ -616,6 +660,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
226 exit_cleanup(RERR_FILESELECT);
228 filesystem_dev = st.st_dev; /* ensures --force works right w/-x */
229 +#ifdef SUPPORT_HFS_COMPRESSION
230 + hfs_receiver_check();
234 if (file_total > 1) {
235 @@ -676,7 +723,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
236 full_fname(dest_path));
237 exit_cleanup(RERR_FILESELECT);
240 +#ifdef SUPPORT_HFS_COMPRESSION
241 + hfs_receiver_check();
246 @@ -696,6 +745,9 @@ static char *get_local_name(struct file_list *flist, char *dest_path)
247 full_fname(dest_path));
248 exit_cleanup(RERR_FILESELECT);
250 +#ifdef SUPPORT_HFS_COMPRESSION
251 + hfs_receiver_check();
256 diff --git a/options.c b/options.c
259 @@ -52,6 +52,7 @@ int preserve_links = 0;
260 int preserve_hard_links = 0;
261 int preserve_acls = 0;
262 int preserve_xattrs = 0;
263 +int preserve_hfs_compression = 0;
264 int preserve_perms = 0;
265 int preserve_fileflags = 0;
266 int preserve_executability = 0;
267 @@ -711,6 +712,10 @@ void usage(enum logcode F)
268 #ifdef SUPPORT_XATTRS
269 rprintf(F," -X, --xattrs preserve extended attributes\n");
271 +#ifdef SUPPORT_HFS_COMPRESSION
272 + rprintf(F," --hfs-compression preserve HFS compression if supported\n");
273 + rprintf(F," --protect-decmpfs preserve HFS compression as xattrs\n");
275 rprintf(F," -o, --owner preserve owner (super-user only)\n");
276 rprintf(F," -g, --group preserve group\n");
277 rprintf(F," --devices preserve device files (super-user only)\n");
278 @@ -972,6 +977,12 @@ static struct poptOption long_options[] = {
279 {"force-uchange", 0, POPT_ARG_VAL, &force_change, USR_IMMUTABLE, 0, 0 },
280 {"force-schange", 0, POPT_ARG_VAL, &force_change, SYS_IMMUTABLE, 0, 0 },
282 +#ifdef SUPPORT_HFS_COMPRESSION
283 + {"hfs-compression", 0, POPT_ARG_VAL, &preserve_hfs_compression, 1, 0, 0 },
284 + {"no-hfs-compression",0, POPT_ARG_VAL, &preserve_hfs_compression, 0, 0, 0 },
285 + {"protect-decmpfs", 0, POPT_ARG_VAL, &preserve_hfs_compression, 2, 0, 0 },
286 + {"no-protect-decmpfs",0, POPT_ARG_VAL, &preserve_hfs_compression, 0, 0, 0 },
288 {"ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 1, 0, 0 },
289 {"no-ignore-errors", 0, POPT_ARG_VAL, &ignore_errors, 0, 0, 0 },
290 {"max-delete", 0, POPT_ARG_INT, &max_delete, 0, 0, 0 },
291 @@ -1954,6 +1965,15 @@ int parse_arguments(int *argc_p, const char ***argv_p)
295 +#ifdef SUPPORT_HFS_COMPRESSION
296 + if (preserve_hfs_compression) {
297 + if (!preserve_xattrs)
298 + preserve_xattrs = 1;
299 + if (!preserve_fileflags)
300 + preserve_fileflags = 1;
304 if (block_size > MAX_BLOCK_SIZE) {
305 snprintf(err_buf, sizeof err_buf,
306 "--block-size=%lu is too large (max: %u)\n", block_size, MAX_BLOCK_SIZE);
307 @@ -2549,6 +2569,11 @@ void server_options(char **args, int *argc_p)
308 if (preserve_fileflags)
309 args[ac++] = "--fileflags";
311 +#ifdef SUPPORT_HFS_COMPRESSION
312 + if (preserve_hfs_compression)
313 + args[ac++] = preserve_hfs_compression == 1 ? "--hfs-compression" : "--protect-decmpfs";
316 if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
317 if (asprintf(&arg, "--compress-level=%d", def_compress_level) < 0)
319 diff --git a/rsync.c b/rsync.c
322 @@ -526,8 +526,14 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
323 #ifdef SUPPORT_XATTRS
325 set_stat_xattr(fname, file, new_mode);
326 - if (preserve_xattrs && fnamecmp)
327 + if (preserve_xattrs && fnamecmp) {
328 + uint32 tmpflags = sxp->st.st_flags;
329 + sxp->st.st_flags = F_FFLAGS(file); /* set_xattr() needs to check UF_COMPRESSED */
330 set_xattr(fname, file, fnamecmp, sxp);
331 + sxp->st.st_flags = tmpflags;
332 + if (S_ISDIR(sxp->st.st_mode))
333 + link_stat(fname, &sx2.st, 0);
338 @@ -538,6 +544,9 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
339 if (sxp->st.st_ino == 2 && S_ISDIR(sxp->st.st_mode))
340 flags |= ATTRS_SKIP_CRTIME;
341 if (!(flags & ATTRS_SKIP_MTIME)
342 +#ifdef SUPPORT_HFS_COMPRESSION
343 + && !(sxp->st.st_flags & UF_COMPRESSED) /* setting this alters mtime, so defer to after set_fileflags */
345 && cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
346 int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), sxp->st.st_mode, ST_FLAGS(sxp->st));
348 @@ -643,6 +652,16 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
349 && !set_fileflags(fname, fileflags))
352 +#ifdef SUPPORT_HFS_COMPRESSION
353 + int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), new_mode, fileflags);
355 + rsyserr(FERROR_XFER, errno, "failed to set times on %s",
356 + full_fname(fname));
360 + file->flags |= FLAG_TIME_FAILED;
365 diff --git a/rsync.h b/rsync.h
368 @@ -548,6 +548,17 @@ typedef unsigned int size_t;
369 #define ST_FLAGS(st) NO_FFLAGS
372 +#ifndef UF_COMPRESSED
373 +#define UF_COMPRESSED 0x00000020
375 +#ifndef VOL_CAP_FMT_DECMPFS_COMPRESSION
376 +#define VOL_CAP_FMT_DECMPFS_COMPRESSION 0x00010000
379 +#if defined SUPPORT_XATTRS && defined SUPPORT_FILEFLAGS
380 +#define SUPPORT_HFS_COMPRESSION 1
383 /* Find a variable that is either exactly 32-bits or longer.
384 * If some code depends on 32-bit truncation, it will need to
385 * take special action in a "#if SIZEOF_INT32 > 4" section. */
386 diff --git a/rsync.yo b/rsync.yo
389 @@ -364,6 +364,8 @@ to the detailed description below for a complete description. verb(
390 --chmod=CHMOD affect file and/or directory permissions
391 -A, --acls preserve ACLs (implies -p)
392 -X, --xattrs preserve extended attributes
393 + --hfs-compression preserve HFS compression if supported
394 + --protect-decmpfs preserve HFS compression as xattrs
395 -o, --owner preserve owner (super-user only)
396 -g, --group preserve group
397 --devices preserve device files (super-user only)
398 @@ -1124,6 +1126,42 @@ flags on files and directories that are being updated or deleted on the
399 receiving side. It does not try to affect user flags. This option overrides
400 bf(--force-change) and bf(--force-uchange).
402 +dit(bf(--hfs-compression)) This option causes rsync to preserve HFS+
403 +compression if the destination filesystem supports it. If the destination
404 +does not support it, rsync will exit with an error.
406 +Filesystem compression was introduced to HFS+ in Mac OS 10.6. A file that is
407 +compressed has no data in its data fork. Rather, the compressed data is stored
408 +in an extended attribute named com.apple.decmpfs and a file flag is set to
409 +indicate that the file is compressed (UF_COMPRESSED). HFS+ decompresses this
410 +data "on-the-fly" and presents it to the operating system as a normal file.
411 +Normal attempts to copy compressed files (e.g. in the Finder, via cp, ditto,
412 +etc.) will copy the file's decompressed contents, remove the UF_COMPRESSED file
413 +flag, and discard the com.apple.decmpfs extended attribute. This option will
414 +preserve the data in the com.apple.decmpfs extended attribute and ignore the
415 +synthesized data in the file contents.
417 +This option implies both bf(--fileflags) and (--xattrs).
419 +dit(bf(--protect-decmpfs)) The com.apple.decmpfs extended attribute is hidden
420 +by default from list/get xattr calls, therefore normal attempts to copy
421 +compressed files will functionally decompress those files. While this is
422 +desirable behavior when copying files to filesystems that do not support HFS+
423 +compression, it has serious performance and capacity impacts when backing up
424 +or restoring the Mac OS X filesystem.
426 +This option will transfer the com.apple.decmpfs extended attribute regardless
427 +of support on the destination. If a source file is compressed and an existing
428 +file on the destination is not compressed, the data fork of the destination
429 +file will be truncated and the com.apple.decmpfs xattr will be transferred
430 +instead. Note that compressed files will not be readable to the operating
431 +system of the destination if that operating system does not support HFS+
432 +compression. Once restored (with or without this option) to an operating system
433 +that supports HFS+ compression, however, these files will be accessible as
436 +This option implies bf(--fileflags) and bf(--xattrs).
438 dit(bf(--chmod)) This option tells rsync to apply one or more
439 comma-separated "chmod" modes to the permission of the files in the
440 transfer. The resulting value is treated as though it were the permissions
441 diff --git a/t_stub.c b/t_stub.c
444 @@ -32,6 +32,7 @@ int force_change = 0;
445 int preserve_acls = 0;
446 int preserve_times = 0;
447 int preserve_xattrs = 0;
448 +int preserve_hfs_compression = 0;
451 filter_rule_list daemon_filter_list;
452 diff --git a/xattrs.c b/xattrs.c
455 @@ -33,6 +33,7 @@ extern int am_generator;
456 extern int read_only;
457 extern int list_only;
458 extern int preserve_xattrs;
459 +extern int preserve_hfs_compression;
460 extern int preserve_links;
461 extern int preserve_devices;
462 extern int preserve_specials;
463 @@ -41,6 +42,10 @@ extern int checksum_seed;
464 #define RSYNC_XAL_INITIAL 5
465 #define RSYNC_XAL_LIST_INITIAL 100
467 +#define GXD_NO_MISSING_ERROR (1<<0)
468 +#define GXD_OMIT_COMPRESSED (1<<1)
469 +#define GXD_FILE_IS_COMPRESSED (1<<2)
471 #define MAX_FULL_DATUM 32
473 #define HAS_PREFIX(str, prfx) (*(str) == *(prfx) \
474 @@ -73,6 +78,17 @@ extern int checksum_seed;
475 #define XDEF_ACL_SUFFIX "dacl"
476 #define XDEF_ACL_ATTR RSYNC_PREFIX "%" XDEF_ACL_SUFFIX
478 +#define APPLE_PREFIX "com.apple."
479 +#define APLPRE_LEN ((int)sizeof APPLE_PREFIX - 1)
480 +#define DECMPFS_SUFFIX "decmpfs"
481 +#define RESOURCEFORK_SUFFIX "ResourceFork"
483 +#define UNREAD_DATA ((char *)1)
485 +#if MAX_DIGEST_LEN < SIZEOF_TIME_T
486 +#error MAX_DIGEST_LEN is too small to hold an mtime
491 size_t datum_len, name_len;
492 @@ -167,8 +183,7 @@ static ssize_t get_xattr_names(const char *fname)
493 /* On entry, the *len_ptr parameter contains the size of the extra space we
494 * should allocate when we create a buffer for the data. On exit, it contains
495 * the length of the datum. */
496 -static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr,
497 - int no_missing_error)
498 +static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr, int flags)
500 size_t datum_len = sys_lgetxattr(fname, name, NULL, 0);
501 size_t extra_len = *len_ptr;
502 @@ -177,7 +192,7 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
503 *len_ptr = datum_len;
505 if (datum_len == (size_t)-1) {
506 - if (errno == ENOTSUP || no_missing_error)
507 + if (errno == ENOTSUP || flags & GXD_NO_MISSING_ERROR)
509 rsyserr(FERROR_XFER, errno,
510 "get_xattr_data: lgetxattr(\"%s\",\"%s\",0) failed",
511 @@ -185,6 +200,15 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
515 + if (flags & GXD_OMIT_COMPRESSED && datum_len > MAX_FULL_DATUM
516 + && HAS_PREFIX(name, APPLE_PREFIX)
517 + && (strcmp(name+APLPRE_LEN, DECMPFS_SUFFIX) == 0
518 + || (flags & GXD_FILE_IS_COMPRESSED && strcmp(name+APLPRE_LEN, RESOURCEFORK_SUFFIX) == 0))) {
519 + /* If we are omitting compress-file-related data, we don't want to
520 + * actually read this data. */
521 + return UNREAD_DATA;
524 if (!datum_len && !extra_len)
525 extra_len = 1; /* request non-zero amount of memory */
526 if (datum_len + extra_len < datum_len)
527 @@ -213,7 +237,29 @@ static char *get_xattr_data(const char *fname, const char *name, size_t *len_ptr
531 -static int rsync_xal_get(const char *fname, item_list *xalp)
532 +static void checksum_xattr_data(char *sum, const char *datum, size_t datum_len, stat_x *sxp)
534 + if (datum == UNREAD_DATA) {
535 + /* For abbreviated compressed data, we store the file's mtime as the checksum. */
536 + SIVAL(sum, 0, sxp->st.st_mtime);
537 +#if SIZEOF_TIME_T > 4
538 + SIVAL(sum, 4, sxp->st.st_mtime >> 32);
539 +#if MAX_DIGEST_LEN > 8
540 + memset(sum + 8, 0, MAX_DIGEST_LEN - 8);
543 +#if MAX_DIGEST_LEN > 4
544 + memset(sum + 4, 0, MAX_DIGEST_LEN - 4);
548 + sum_init(checksum_seed);
549 + sum_update(datum, datum_len);
554 +static int rsync_xal_get(const char *fname, stat_x *sxp)
556 ssize_t list_len, name_len;
557 size_t datum_len, name_offset;
558 @@ -222,7 +268,8 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
559 int user_only = am_sender ? 0 : !am_root;
564 + item_list *xalp = sxp->xattr;
566 /* This puts the name list into the "namebuf" buffer. */
567 if ((list_len = get_xattr_names(fname)) < 0)
568 @@ -252,20 +299,22 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
571 datum_len = name_len; /* Pass extra size to get_xattr_data() */
572 - if (!(ptr = get_xattr_data(fname, name, &datum_len, 0)))
573 + flags = GXD_OMIT_COMPRESSED;
574 + if (preserve_hfs_compression && sxp->st.st_flags & UF_COMPRESSED)
575 + flags |= GXD_FILE_IS_COMPRESSED;
576 + if (!(ptr = get_xattr_data(fname, name, &datum_len, flags)))
579 if (datum_len > MAX_FULL_DATUM) {
580 /* For large datums, we store a flag and a checksum. */
582 name_offset = 1 + MAX_DIGEST_LEN;
583 - sum_init(checksum_seed);
584 - sum_update(ptr, datum_len);
587 if (!(ptr = new_array(char, name_offset + name_len)))
588 out_of_memory("rsync_xal_get");
589 *ptr = XSTATE_ABBREV;
591 + checksum_xattr_data(ptr+1, datum, datum_len, sxp);
592 + if (datum != UNREAD_DATA)
595 name_offset = datum_len;
597 @@ -310,7 +359,7 @@ int get_xattr(const char *fname, stat_x *sxp)
601 - if (rsync_xal_get(fname, sxp->xattr) < 0) {
602 + if (rsync_xal_get(fname, sxp) < 0) {
606 @@ -345,6 +394,8 @@ int copy_xattrs(const char *source, const char *dest)
608 if (!(ptr = get_xattr_data(source, name, &datum_len, 0)))
610 + if (ptr == UNREAD_DATA)
611 + continue; /* XXX Is this right? */
612 if (sys_lsetxattr(dest, name, ptr, datum_len) < 0) {
613 int save_errno = errno ? errno : EINVAL;
614 rsyserr(FERROR_XFER, errno,
615 @@ -361,6 +412,10 @@ int copy_xattrs(const char *source, const char *dest)
617 static int find_matching_xattr(item_list *xalp)
619 +#ifdef HAVE_OSX_XATTRS
621 + return -1; /* find_matching_xattr is a waste of cycles for MOSX clients */
624 item_list *lst = rsync_xal_l.items;
626 @@ -394,6 +449,7 @@ static int find_matching_xattr(item_list *xalp)
633 /* Store *xalp on the end of rsync_xal_l */
634 @@ -573,11 +629,13 @@ void send_xattr_request(const char *fname, struct file_struct *file, int f_out)
636 /* Re-read the long datum. */
637 if (!(ptr = get_xattr_data(fname, rxa->name, &len, 0))) {
638 - rprintf(FERROR_XFER, "failed to re-read xattr %s for %s\n", rxa->name, fname);
639 + if (errno != ENOTSUP && errno != ENOATTR)
640 + rprintf(FERROR_XFER, "failed to re-read xattr %s for %s\n", rxa->name, fname);
641 write_varint(f_out, 0);
645 + assert(ptr != UNREAD_DATA);
646 write_varint(f_out, len); /* length might have changed! */
647 write_buf(f_out, ptr, len);
649 @@ -793,7 +851,7 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
650 int user_only = am_root <= 0;
654 + int flags, ret = 0;
656 /* This puts the current name list into the "namebuf" buffer. */
657 if ((list_len = get_xattr_names(fname)) < 0)
658 @@ -805,7 +863,10 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
659 if (XATTR_ABBREV(rxas[i])) {
660 /* See if the fnamecmp version is identical. */
661 len = name_len = rxas[i].name_len;
662 - if ((ptr = get_xattr_data(fnamecmp, name, &len, 1)) == NULL) {
663 + flags = GXD_OMIT_COMPRESSED | GXD_NO_MISSING_ERROR;
664 + if (preserve_hfs_compression && sxp->st.st_flags & UF_COMPRESSED)
665 + flags |= GXD_FILE_IS_COMPRESSED;
666 + if ((ptr = get_xattr_data(fnamecmp, name, &len, flags)) == NULL) {
670 @@ -814,14 +875,14 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
674 + if (ptr == UNREAD_DATA)
675 + continue; /* XXX Is this right? */
676 if (len != rxas[i].datum_len) {
681 - sum_init(checksum_seed);
682 - sum_update(ptr, len);
684 + checksum_xattr_data(sum, ptr, len, sxp);
685 if (memcmp(sum, rxas[i].datum + 1, MAX_DIGEST_LEN) != 0) {
688 @@ -890,6 +951,10 @@ static int rsync_xal_set(const char *fname, item_list *xalp,
692 +#ifdef HAVE_OSX_XATTRS
693 + rsync_xal_free(xalp); /* Free this because we aren't using find_matching_xattr(). */
699 @@ -936,7 +1001,7 @@ char *get_xattr_acl(const char *fname, int is_access_acl, size_t *len_p)
701 const char *name = is_access_acl ? XACC_ACL_ATTR : XDEF_ACL_ATTR;
702 *len_p = 0; /* no extra data alloc needed from get_xattr_data() */
703 - return get_xattr_data(fname, name, len_p, 1);
704 + return get_xattr_data(fname, name, len_p, GXD_NO_MISSING_ERROR);
707 int set_xattr_acl(const char *fname, int is_access_acl, const char *buf, size_t buf_len)
708 @@ -1079,11 +1144,33 @@ int set_stat_xattr(const char *fname, struct file_struct *file, mode_t new_mode)
712 +#ifdef SUPPORT_HFS_COMPRESSION
713 +static inline void hfs_compress_tweaks(STRUCT_STAT *fst)
715 + if (fst->st_flags & UF_COMPRESSED) {
716 + if (preserve_hfs_compression) {
717 + /* We're sending the compression xattr, not the decompressed data fork.
718 + * Setting rsync's idea of the file size to 0 effectively prevents the
719 + * transfer of the data fork. */
722 + /* If the sender's filesystem supports compression, then we'll be able
723 + * to send the decompressed data fork and the decmpfs xattr will be
724 + * hidden (not sent). As such, we need to strip the compression flag. */
725 + fst->st_flags &= ~UF_COMPRESSED;
731 int x_stat(const char *fname, STRUCT_STAT *fst, STRUCT_STAT *xst)
733 int ret = do_stat(fname, fst);
734 if ((ret < 0 || get_stat_xattr(fname, -1, fst, xst) < 0) && xst)
736 +#ifdef SUPPORT_HFS_COMPRESSION
737 + hfs_compress_tweaks(fst);
742 @@ -1092,6 +1179,9 @@ int x_lstat(const char *fname, STRUCT_STAT *fst, STRUCT_STAT *xst)
743 int ret = do_lstat(fname, fst);
744 if ((ret < 0 || get_stat_xattr(fname, -1, fst, xst) < 0) && xst)
746 +#ifdef SUPPORT_HFS_COMPRESSION
747 + hfs_compress_tweaks(fst);
752 @@ -1100,6 +1190,9 @@ int x_fstat(int fd, STRUCT_STAT *fst, STRUCT_STAT *xst)
753 int ret = do_fstat(fd, fst);
754 if ((ret < 0 || get_stat_xattr(NULL, fd, fst, xst) < 0) && xst)
756 +#ifdef SUPPORT_HFS_COMPRESSION
757 + hfs_compress_tweaks(fst);