}
}
*p = '/';
-@@ -172,15 +183,18 @@ static int robust_move(char *src, char *
+@@ -172,15 +183,18 @@ static int robust_move(const char *src,
* We will move the file to be deleted into a parallel directory tree. */
- static int keep_backup(char *fname)
+ static int keep_backup(const char *fname)
{
- STRUCT_STAT st;
+ statx sx;
if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
return 1; /* the file could have disappeared */
-@@ -188,6 +202,13 @@ static int keep_backup(char *fname)
+@@ -188,6 +202,13 @@ static int keep_backup(const char *fname
if (!(buf = get_backup_name(fname)))
return 0;
/* Check to see if this is a device file, or link */
if ((am_root && preserve_devices && IS_DEVICE(file->mode))
|| (preserve_specials && IS_SPECIAL(file->mode))) {
-@@ -256,7 +277,7 @@ static int keep_backup(char *fname)
+@@ -256,7 +277,7 @@ static int keep_backup(const char *fname
if (robust_move(fname, buf) != 0) {
rsyserr(FERROR, errno, "keep_backup failed: %s -> \"%s\"",
full_fname(fname), buf);
#ifdef SUPPORT_LINKS
links = "";
#endif
-@@ -227,17 +233,16 @@ static void print_rsync_version(enum log
- RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
- rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
- rprintf(f, "<http://rsync.samba.org/>\n");
-- rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, "
-- "%shard links, %ssymlinks, batchfiles,\n",
-- (int) (sizeof (OFF_T) * 8),
-- got_socketpair, hardlinks, links);
-+ rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, %shard links, %ssymlinks,\n",
-+ (int) (sizeof (OFF_T) * 8), got_socketpair, hardlinks, links);
-+
-+ rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs,\n",
-+ have_inplace, ipv6, acls);
+@@ -233,8 +239,8 @@ static void print_rsync_version(enum log
+ (int)(sizeof (int64) * 8));
+ rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
+ got_socketpair, hardlinks, links, ipv6, have_inplace);
+- rprintf(f, " %sappend\n",
+- have_inplace);
++ rprintf(f, " %sappend, %sACLs\n",
++ have_inplace, acls);
- /* Note that this field may not have type ino_t. It depends
- * on the complicated interaction between largefile feature
- * macros. */
-- rprintf(f, " %sinplace, %sIPv6, "
-- "%d-bit system inums, %d-bit internal inums\n",
-- have_inplace, ipv6,
-+ rprintf(f, " %d-bit system inums, %d-bit internal inums\n",
- (int) (sizeof dumstat->st_ino * 8),
- (int) (sizeof (int64) * 8));
#ifdef MAINTAINER_MODE
-@@ -284,7 +289,7 @@ void usage(enum logcode F)
+ rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
+@@ -280,7 +286,7 @@ void usage(enum logcode F)
rprintf(F," -q, --quiet suppress non-error messages\n");
rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
rprintf(F," -r, --recursive recurse into directories\n");
rprintf(F," -R, --relative use relative path names\n");
-@@ -306,6 +311,9 @@ void usage(enum logcode F)
+@@ -302,6 +308,9 @@ void usage(enum logcode F)
rprintf(F," -p, --perms preserve permissions\n");
rprintf(F," -E, --executability preserve the file's executability\n");
rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
rprintf(F," -o, --owner preserve owner (super-user only)\n");
rprintf(F," -g, --group preserve group\n");
rprintf(F," --devices preserve device files (super-user only)\n");
-@@ -426,6 +434,9 @@ static struct poptOption long_options[]
+@@ -422,6 +431,9 @@ static struct poptOption long_options[]
{"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
{"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
{"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
{"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
{"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
{"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
-@@ -1091,6 +1102,24 @@ int parse_arguments(int *argc, const cha
+@@ -1087,6 +1099,24 @@ int parse_arguments(int *argc, const cha
usage(FINFO);
exit_cleanup(0);
default:
/* A large opt value means that set_refuse_options()
* turned this option off. */
-@@ -1533,6 +1562,10 @@ void server_options(char **args,int *arg
+@@ -1529,6 +1559,10 @@ void server_options(char **args,int *arg
if (preserve_hard_links)
argstr[x++] = 'H';
for (i = 0; i < flist->count; i++)
--- old/util.c
+++ new/util.c
-@@ -1468,3 +1468,31 @@ int bitbag_next_bit(struct bitbag *bb, i
+@@ -1467,3 +1467,31 @@ int bitbag_next_bit(struct bitbag *bb, i
return -1;
}
+static int deleting;
+
/* make a complete pathname for backup file */
- char *get_backup_name(char *fname)
+ char *get_backup_name(const char *fname)
{
-@@ -51,11 +58,28 @@ char *get_backup_name(char *fname)
+@@ -51,11 +58,28 @@ char *get_backup_name(const char *fname)
return NULL;
}
-+static char *get_delete_name(char *fname)
++static char *get_delete_name(const char *fname)
+{
+ if (backup_dir_dels) {
+ if (stringjoin(backup_dir_dels_buf + backup_dir_dels_len, backup_dir_dels_remainder,
+}
+
/* simple backup creates a backup with a suffix in the same directory */
- static int make_simple_backup(char *fname)
+ static int make_simple_backup(const char *fname)
{
int rename_errno;
-- char *fnamebak = get_backup_name(fname);
-+ char *fnamebak = deleting ? get_delete_name(fname)
-+ : get_backup_name(fname);
+- const char *fnamebak = get_backup_name(fname);
++ const char *fnamebak = deleting ? get_delete_name(fname)
++ : get_backup_name(fname);
if (!fnamebak)
return 0;
char *end = rel + strlen(rel);
char *p = end;
-@@ -185,7 +210,8 @@ static int keep_backup(char *fname)
+@@ -185,7 +210,8 @@ static int keep_backup(const char *fname
if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
return 1; /* the file could have disappeared */
return 0;
/* Check to see if this is a device file, or link */
-@@ -280,3 +306,13 @@ int make_backup(char *fname)
+@@ -280,3 +306,13 @@ int make_backup(const char *fname)
return keep_backup(fname);
return make_simple_backup(fname);
}
char *sockopts = NULL;
int rsync_port = 0;
int compare_dest = 0;
-@@ -292,6 +298,8 @@ void usage(enum logcode F)
+@@ -288,6 +294,8 @@ void usage(enum logcode F)
rprintf(F," -b, --backup make backups (see --suffix & --backup-dir)\n");
rprintf(F," --backup-dir=DIR make backups into hierarchy based in DIR\n");
rprintf(F," --suffix=SUFFIX set backup suffix (default %s w/o --backup-dir)\n",BACKUP_SUFFIX);
rprintf(F," -u, --update skip files that are newer on the receiver\n");
rprintf(F," --inplace update destination files in-place (SEE MAN PAGE)\n");
rprintf(F," --append append data onto shorter files\n");
-@@ -520,7 +528,9 @@ static struct poptOption long_options[]
+@@ -516,7 +524,9 @@ static struct poptOption long_options[]
{"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
{"backup", 'b', POPT_ARG_NONE, &make_backups, 0, 0, 0 },
{"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
{"list-only", 0, POPT_ARG_VAL, &list_only, 2, 0, 0 },
{"read-batch", 0, POPT_ARG_STRING, &batch_name, OPT_READ_BATCH, 0, 0 },
{"write-batch", 0, POPT_ARG_STRING, &batch_name, OPT_WRITE_BATCH, 0, 0 },
-@@ -1234,6 +1244,8 @@ int parse_arguments(int *argc, const cha
+@@ -1230,6 +1240,8 @@ int parse_arguments(int *argc, const cha
tmpdir = sanitize_path(NULL, tmpdir, NULL, 0, NULL);
if (backup_dir)
backup_dir = sanitize_path(NULL, backup_dir, NULL, 0, NULL);
}
if (server_filter_list.head && !am_sender) {
struct filter_list_struct *elp = &server_filter_list;
-@@ -1251,6 +1263,14 @@ int parse_arguments(int *argc, const cha
+@@ -1247,6 +1259,14 @@ int parse_arguments(int *argc, const cha
if (check_filter(elp, backup_dir, 1) < 0)
goto options_rejected;
}
}
if (!backup_suffix)
-@@ -1262,6 +1282,16 @@ int parse_arguments(int *argc, const cha
+@@ -1258,6 +1278,16 @@ int parse_arguments(int *argc, const cha
backup_suffix);
return 0;
}
if (backup_dir) {
backup_dir_len = strlcpy(backup_dir_buf, backup_dir, sizeof backup_dir_buf);
backup_dir_remainder = sizeof backup_dir_buf - backup_dir_len;
-@@ -1285,6 +1315,31 @@ int parse_arguments(int *argc, const cha
+@@ -1281,6 +1311,31 @@ int parse_arguments(int *argc, const cha
"P *%s", backup_suffix);
parse_rule(&filter_list, backup_dir_buf, 0, 0);
}
if (make_backups && !backup_dir)
omit_dir_times = 1;
-@@ -1649,6 +1704,10 @@ void server_options(char **args,int *arg
+@@ -1645,6 +1700,10 @@ void server_options(char **args,int *arg
args[ac++] = "--backup-dir";
args[ac++] = backup_dir;
}
/* Only send --suffix if it specifies a non-default value. */
if (strcmp(backup_suffix, backup_dir ? "" : BACKUP_SUFFIX) != 0) {
-@@ -1657,7 +1716,13 @@ void server_options(char **args,int *arg
+@@ -1653,7 +1712,13 @@ void server_options(char **args,int *arg
goto oom;
args[ac++] = arg;
}
extern int preserve_hard_links;
extern int preserve_devices;
extern int preserve_specials;
-+extern int preserve_flags;
++extern int preserve_fileflags;
extern int preserve_uid;
extern int preserve_gid;
extern int relative_paths;
if ((preserve_devices && IS_DEVICE(mode))
|| (preserve_specials && IS_SPECIAL(mode))) {
if (protocol_version < 28) {
-@@ -418,6 +428,10 @@ static void send_file_entry(struct file_
+@@ -417,6 +427,10 @@ static void send_file_entry(struct file_
write_int(f, modtime);
if (!(flags & XMIT_SAME_MODE))
write_int(f, to_wire_mode(mode));
+#ifdef SUPPORT_FLAGS
-+ if (preserve_flags && !(flags & XMIT_SAME_FLAGS))
++ if (preserve_fileflags && !(flags & XMIT_SAME_FLAGS))
+ write_int(f, (int)fileflags);
+#endif
if (preserve_uid && !(flags & XMIT_SAME_UID)) {
if (!numeric_ids)
add_uid(uid);
-@@ -485,6 +499,9 @@ static struct file_struct *receive_file_
+@@ -484,6 +498,9 @@ static struct file_struct *receive_file_
{
static time_t modtime;
static mode_t mode;
static int64 dev;
static dev_t rdev;
static uint32 rdev_major;
-@@ -558,9 +575,12 @@ static struct file_struct *receive_file_
+@@ -557,9 +574,12 @@ static struct file_struct *receive_file_
modtime = (time_t)read_int(f);
if (!(flags & XMIT_SAME_MODE))
mode = from_wire_mode(read_int(f));
if (chmod_modes && !S_ISLNK(mode))
mode = tweak_mode(mode, chmod_modes);
+#ifdef SUPPORT_FLAGS
-+ if (preserve_flags && !(flags & XMIT_SAME_FLAGS))
++ if (preserve_fileflags && !(flags & XMIT_SAME_FLAGS))
+ fileflags = (uint32)read_int(f);
+#endif
if (preserve_uid && !(flags & XMIT_SAME_UID))
uid = (uid_t)read_int(f);
-@@ -611,6 +631,9 @@ static struct file_struct *receive_file_
+@@ -610,6 +630,9 @@ static struct file_struct *receive_file_
file->modtime = modtime;
file->length = file_length;
file->mode = mode;
file->uid = uid;
file->gid = gid;
-@@ -871,6 +894,9 @@ struct file_struct *make_file(char *fnam
+@@ -870,6 +893,9 @@ struct file_struct *make_file(const char
file->modtime = st.st_mtime;
file->length = st.st_size;
file->mode = st.st_mode;
int preserve_links = 0;
int preserve_hard_links = 0;
int preserve_perms = 0;
-+int preserve_flags = 0;
++int preserve_fileflags = 0;
int preserve_executability = 0;
int preserve_devices = 0;
int preserve_specials = 0;
char const *hardlinks = "no ";
char const *links = "no ";
char const *ipv6 = "no ";
-+ char const *flags = "no ";
++ char const *fileflags = "no ";
STRUCT_STAT *dumstat;
#ifdef HAVE_SOCKETPAIR
#endif
+#ifdef SUPPORT_FLAGS
-+ flags = "";
++ fileflags = "";
+#endif
+
rprintf(f, "%s version %s protocol version %d\n",
RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
-@@ -235,9 +241,9 @@ static void print_rsync_version(enum log
- /* Note that this field may not have type ino_t. It depends
- * on the complicated interaction between largefile feature
- * macros. */
-- rprintf(f, " %sinplace, %sIPv6, "
-+ rprintf(f, " %sinplace, %sIPv6, %sfile flags, "
- "%d-bit system inums, %d-bit internal inums\n",
-- have_inplace, ipv6,
-+ have_inplace, ipv6, flags,
- (int) (sizeof dumstat->st_ino * 8),
- (int) (sizeof (int64) * 8));
+@@ -233,8 +239,8 @@ static void print_rsync_version(enum log
+ (int)(sizeof (int64) * 8));
+ rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
+ got_socketpair, hardlinks, links, ipv6, have_inplace);
+- rprintf(f, " %sappend\n",
+- have_inplace);
++ rprintf(f, " %sappend, %sfile-flags\n",
++ have_inplace, fileflags);
+
#ifdef MAINTAINER_MODE
-@@ -304,6 +310,7 @@ void usage(enum logcode F)
+ rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
+@@ -300,6 +306,7 @@ void usage(enum logcode F)
rprintf(F," -K, --keep-dirlinks treat symlinked dir on receiver as dir\n");
rprintf(F," -H, --hard-links preserve hard links\n");
rprintf(F," -p, --perms preserve permissions\n");
-+ rprintf(F," --flags preserve file flags\n");
++ rprintf(F," --fileflags preserve file-flags\n");
rprintf(F," -E, --executability preserve the file's executability\n");
rprintf(F," --chmod=CHMOD affect file and/or directory permissions\n");
rprintf(F," -o, --owner preserve owner (super-user only)\n");
-@@ -425,6 +432,8 @@ static struct poptOption long_options[]
+@@ -421,6 +428,8 @@ static struct poptOption long_options[]
{"perms", 'p', POPT_ARG_VAL, &preserve_perms, 1, 0, 0 },
{"no-perms", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
{"no-p", 0, POPT_ARG_VAL, &preserve_perms, 0, 0, 0 },
-+ {"flags", 0, POPT_ARG_VAL, &preserve_flags, 1, 0, 0 },
-+ {"no-flags", 0, POPT_ARG_VAL, &preserve_flags, 0, 0, 0 },
++ {"fileflags", 0, POPT_ARG_VAL, &preserve_fileflags, 1, 0, 0 },
++ {"no-fileflags", 0, POPT_ARG_VAL, &preserve_fileflags, 0, 0, 0 },
{"executability", 'E', POPT_ARG_NONE, &preserve_executability, 0, 0, 0 },
{"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
{"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
-@@ -1130,6 +1139,15 @@ int parse_arguments(int *argc, const cha
+@@ -1126,6 +1135,15 @@ int parse_arguments(int *argc, const cha
}
#endif
+#ifndef SUPPORT_FLAGS
-+ if (preserve_flags) {
++ if (preserve_fileflags) {
+ snprintf(err_buf, sizeof err_buf,
+ "file flags are not supported on this %s\n",
+ am_server ? "server" : "client");
if (write_batch && read_batch) {
snprintf(err_buf, sizeof err_buf,
"--write-batch and --read-batch can not be used together\n");
-@@ -1584,6 +1602,9 @@ void server_options(char **args,int *arg
+@@ -1580,6 +1598,9 @@ void server_options(char **args,int *arg
if (xfer_dirs && !recurse && delete_mode && am_sender)
args[ac++] = "--no-r";
-+ if (preserve_flags)
++ if (preserve_fileflags)
+ args[ac++] = "--flags";
+
if (do_compression && def_compress_level != Z_DEFAULT_COMPRESSION) {
extern int verbose;
extern int dry_run;
extern int preserve_perms;
-+extern int preserve_flags;
++extern int preserve_fileflags;
extern int preserve_executability;
extern int preserve_times;
extern int omit_dir_times;
+/* Remove immutable flags from an object, so it can be altered/removed. */
+void make_mutable(char *fname, mode_t mode, uint32 fileflags)
+{
-+ if (!preserve_flags && S_ISLNK(mode))
++ if (!preserve_fileflags && S_ISLNK(mode))
+ return;
+
+ if (fileflags & NOCHANGE_FLAGS)
+/* Undo a prior make_mutable() call. */
+void undo_make_mutable(char *fname, mode_t mode, uint32 fileflags)
+{
-+ if (!preserve_flags && S_ISLNK(mode))
++ if (!preserve_fileflags && S_ISLNK(mode))
+ return;
+
+ if (fileflags & NOCHANGE_FLAGS)
#endif
+#ifdef SUPPORT_FLAGS
-+ if (preserve_flags && !S_ISLNK(st->st_mode)
++ if (preserve_fileflags && !S_ISLNK(st->st_mode)
+ && st->st_flags != file->fileflags) {
+ if (!set_fileflags(fname, file->fileflags))
+ return 0;
+ return client_run(fd, fd, -1, argc, argv);
}
- int start_inband_exchange(char *user, char *path, int f_in, int f_out,
-@@ -168,6 +181,33 @@ int start_inband_exchange(char *user, ch
+ int start_inband_exchange(const char *user, char *path, int f_in, int f_out,
+@@ -168,6 +181,33 @@ int start_inband_exchange(const char *us
if (verbose > 1)
print_child_argv(sargs);
p = strchr(path,'/');
if (p) *p = 0;
io_printf(f_out, "%s\n", path);
-@@ -196,6 +236,10 @@ int start_inband_exchange(char *user, ch
+@@ -196,6 +236,10 @@ int start_inband_exchange(const char *us
* server to terminate the listing of modules.
* We don't want to go on and transfer
* anything; just exit. */
exit(0);
}
-@@ -203,6 +247,10 @@ int start_inband_exchange(char *user, ch
+@@ -203,6 +247,10 @@ int start_inband_exchange(const char *us
rprintf(FERROR, "%s\n", line);
/* This is always fatal; the server will now
* close the socket. */
rprintf(f, "%s version %s protocol version %d\n",
RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
-@@ -235,9 +248,9 @@ static void print_rsync_version(enum log
- /* Note that this field may not have type ino_t. It depends
- * on the complicated interaction between largefile feature
- * macros. */
-- rprintf(f, " %sinplace, %sIPv6, "
-+ rprintf(f, " %sinplace, %sIPv6, %sSSL, "
- "%d-bit system inums, %d-bit internal inums\n",
-- have_inplace, ipv6,
-+ have_inplace, ipv6, ssl,
- (int) (sizeof dumstat->st_ino * 8),
- (int) (sizeof (int64) * 8));
+@@ -233,8 +246,8 @@ static void print_rsync_version(enum log
+ (int)(sizeof (int64) * 8));
+ rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
+ got_socketpair, hardlinks, links, ipv6, have_inplace);
+- rprintf(f, " %sappend\n",
+- have_inplace);
++ rprintf(f, " %sappend, %sSSL\n",
++ have_inplace, ssl);
+
#ifdef MAINTAINER_MODE
-@@ -385,6 +398,13 @@ void usage(enum logcode F)
+ rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
+@@ -382,6 +395,13 @@ void usage(enum logcode F)
rprintf(F," -4, --ipv4 prefer IPv4\n");
rprintf(F," -6, --ipv6 prefer IPv6\n");
#endif
rprintf(F," --version print version number\n");
rprintf(F,"(-h) --help show this help (-h works with no other options)\n");
-@@ -398,7 +418,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OP
+@@ -395,7 +415,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OP
OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
OPT_SERVER, OPT_REFUSED_BASE = 9000};
static struct poptOption long_options[] = {
-@@ -545,6 +565,13 @@ static struct poptOption long_options[]
+@@ -543,6 +563,13 @@ static struct poptOption long_options[]
{"checksum-seed", 0, POPT_ARG_INT, &checksum_seed, 0, 0, 0 },
{"server", 0, POPT_ARG_NONE, 0, OPT_SERVER, 0, 0 },
{"sender", 0, POPT_ARG_NONE, 0, OPT_SENDER, 0, 0 },
/* All the following options switch us into daemon-mode option-parsing. */
{"config", 0, POPT_ARG_STRING, 0, OPT_DAEMON, 0, 0 },
{"daemon", 0, POPT_ARG_NONE, 0, OPT_DAEMON, 0, 0 },
-@@ -572,6 +599,13 @@ static void daemon_usage(enum logcode F)
+@@ -570,6 +597,13 @@ static void daemon_usage(enum logcode F)
rprintf(F," -4, --ipv4 prefer IPv4\n");
rprintf(F," -6, --ipv6 prefer IPv6\n");
#endif
rprintf(F," --help show this help screen\n");
rprintf(F,"\n");
-@@ -598,6 +632,13 @@ static struct poptOption long_daemon_opt
+@@ -596,6 +630,13 @@ static struct poptOption long_daemon_opt
{"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
{"server", 0, POPT_ARG_NONE, &am_server, 0, 0, 0 },
{"temp-dir", 'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
{"verbose", 'v', POPT_ARG_NONE, 0, 'v', 0, 0 },
{"no-verbose", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
{"no-v", 0, POPT_ARG_VAL, &verbose, 0, 0, 0 },
-@@ -855,6 +896,12 @@ int parse_arguments(int *argc, const cha
+@@ -853,6 +894,12 @@ int parse_arguments(int *argc, const cha
verbose++;
break;
default:
rprintf(FERROR,
"rsync: %s: %s (in daemon mode)\n",
-@@ -878,6 +925,17 @@ int parse_arguments(int *argc, const cha
+@@ -876,6 +923,17 @@ int parse_arguments(int *argc, const cha
exit_cleanup(RERR_SYNTAX);
}
*argv = poptGetArgs(pc);
*argc = count_args(*argv);
am_starting_up = 0;
-@@ -1089,6 +1147,12 @@ int parse_arguments(int *argc, const cha
+@@ -1087,6 +1145,12 @@ int parse_arguments(int *argc, const cha
usage(FINFO);
exit_cleanup(0);
default:
/* A large opt value means that set_refuse_options()
* turned this option off. */
-@@ -1365,6 +1429,17 @@ int parse_arguments(int *argc, const cha
+@@ -1359,6 +1423,17 @@ int parse_arguments(int *argc, const cha
if (delay_updates && !partial_dir)
partial_dir = tmp_partialdir;
if (inplace) {
#ifdef HAVE_FTRUNCATE
if (partial_dir) {
-@@ -1782,10 +1857,27 @@ char *check_for_hostspec(char *s, char *
+@@ -1783,10 +1858,27 @@ char *check_for_hostspec(char *s, char *
char *p;
int not_host;
int hostlen;
#define BACKUP_SUFFIX "~"
-@@ -419,6 +420,11 @@ enum msgcode {
+@@ -420,6 +421,11 @@ enum msgcode {
# define SIZEOF_INT64 SIZEOF_OFF_T
#endif
--- /dev/null
+This patch adds the --preallocate option that asks rsync to preallocate the
+copied files. This slows down the copy, but should reduce fragmentation on
+systems that need that.
+
+To use this patch, run these commands for a successful build:
+
+ patch -p1 <patches/preallocate.diff
+ ./prepare-source
+ ./configure
+ make
+
+
+TODO: update docs
+
+--- old/configure.in
++++ new/configure.in
+@@ -550,7 +550,7 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strd
+ strlcat strlcpy strtol mallinfo getgroups setgroups geteuid getegid \
+ setlocale setmode open64 lseek64 mkstemp64 mtrace va_copy __va_copy \
+ strerror putenv iconv_open locale_charset nl_langinfo \
+- sigaction sigprocmask)
++ sigaction sigprocmask posix_fallocate)
+
+ AC_CHECK_FUNCS(getpgrp tcgetpgrp)
+ if test $ac_cv_func_getpgrp = yes; then
+--- old/options.c
++++ new/options.c
+@@ -69,6 +69,7 @@ int remove_source_files = 0;
+ int one_file_system = 0;
+ int protocol_version = PROTOCOL_VERSION;
+ int sparse_files = 0;
++int preallocate_files = 0;
+ int do_compression = 0;
+ int def_compress_level = Z_DEFAULT_COMPRESSION;
+ int am_root = 0;
+@@ -201,6 +202,7 @@ static void print_rsync_version(enum log
+ char const *hardlinks = "no ";
+ char const *links = "no ";
+ char const *ipv6 = "no ";
++ char const *preallocation = "no ";
+ STRUCT_STAT *dumstat;
+
+ #ifdef HAVE_SOCKETPAIR
+@@ -223,6 +225,10 @@ static void print_rsync_version(enum log
+ ipv6 = "";
+ #endif
+
++#ifdef SUPPORT_PREALLOCATION
++ preallocation = "";
++#endif
++
+ rprintf(f, "%s version %s protocol version %d\n",
+ RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
+ rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
+@@ -233,8 +239,8 @@ static void print_rsync_version(enum log
+ (int)(sizeof (int64) * 8));
+ rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
+ got_socketpair, hardlinks, links, ipv6, have_inplace);
+- rprintf(f, " %sappend\n",
+- have_inplace);
++ rprintf(f, " %sappend, %spreallocation\n",
++ have_inplace, preallocation);
+
+ #ifdef MAINTAINER_MODE
+ rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
+@@ -311,6 +317,9 @@ void usage(enum logcode F)
+ rprintf(F," -O, --omit-dir-times omit directories when preserving times\n");
+ rprintf(F," --super receiver attempts super-user activities\n");
+ rprintf(F," -S, --sparse handle sparse files efficiently\n");
++#ifdef SUPPORT_PREALLOCATION
++ rprintf(F," --preallocate posix_fallocate dest files before writing them\n");
++#endif
+ rprintf(F," -n, --dry-run show what would have been transferred\n");
+ rprintf(F," -W, --whole-file copy files whole (without rsync algorithm)\n");
+ rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n");
+@@ -468,6 +477,7 @@ static struct poptOption long_options[]
+ {"max-size", 0, POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },
+ {"min-size", 0, POPT_ARG_STRING, &min_size_arg, OPT_MIN_SIZE, 0, 0 },
+ {"sparse", 'S', POPT_ARG_NONE, &sparse_files, 0, 0, 0 },
++ {"preallocate", 0, POPT_ARG_NONE, &preallocate_files, 0, 0, 0},
+ {"inplace", 0, POPT_ARG_NONE, &inplace, 0, 0, 0 },
+ {"append", 0, POPT_ARG_VAL, &append_mode, 1, 0, 0 },
+ {"del", 0, POPT_ARG_NONE, &delete_during, 0, 0, 0 },
+@@ -1126,6 +1136,15 @@ int parse_arguments(int *argc, const cha
+ }
+ #endif
+
++#ifndef SUPPORT_PREALLOCATION
++ if (preallocate_files && !am_sender) {
++ snprintf(err_buf, sizeof err_buf,
++ "preallocation is not supported on this %s\n",
++ am_server ? "server" : "client");
++ return 0;
++ }
++#endif
++
+ if (write_batch && read_batch) {
+ snprintf(err_buf, sizeof err_buf,
+ "--write-batch and --read-batch can not be used together\n");
+@@ -1764,6 +1783,9 @@ void server_options(char **args,int *arg
+ else if (remove_source_files)
+ args[ac++] = "--remove-sent-files";
+
++ if (preallocate_files && am_sender)
++ args[ac++] = "--preallocate";
++
+ *argc = ac;
+ return;
+
+--- old/receiver.c
++++ new/receiver.c
+@@ -43,6 +43,7 @@ extern int cleanup_got_literal;
+ extern int remove_source_files;
+ extern int append_mode;
+ extern int sparse_files;
++extern int preallocate_files;
+ extern int keep_partial;
+ extern int checksum_seed;
+ extern int inplace;
+@@ -137,6 +138,19 @@ static int receive_data(int f_in, char *
+ int32 i;
+ char *map = NULL;
+
++#ifdef SUPPORT_PREALLOCATION
++ int preallocated_len = 0;
++
++ if (preallocate_files && fd != -1 && total_size > 0) {
++ /* Preallocate enough space for file's eventual length if
++ * possible; seems to reduce fragmentation on Windows. */
++ if (posix_fallocate(fd, 0, total_size) == 0)
++ preallocated_len = total_size;
++ else
++ rsyserr(FINFO, errno, "preallocate %s", full_fname(fname));
++ }
++#endif
++
+ read_sum_head(f_in, &sum);
+
+ if (fd_r >= 0 && size_r > 0) {
+@@ -244,8 +258,18 @@ static int receive_data(int f_in, char *
+ goto report_write_error;
+
+ #ifdef HAVE_FTRUNCATE
+- if (inplace && fd != -1)
+- ftruncate(fd, offset);
++ /* inplace: New data could be shorter than old data.
++ * preallocate_files: total_size could have been an overestimate.
++ * Cut off any extra preallocated zeros from dest file. */
++ if ((inplace
++#ifdef SUPPORT_PREALLOCATION
++ || preallocated_len > offset
++#endif
++ ) && fd != -1)
++ if (ftruncate(fd, offset) < 0)
++ /* If we fail to truncate, the dest file may be wrong, so we
++ * must trigger the "partial transfer" error. */
++ rsyserr(FERROR, errno, "ftruncate %s", full_fname(fname));
+ #endif
+
+ if (do_progress)
+--- old/rsync.h
++++ new/rsync.h
+@@ -493,6 +493,10 @@ struct idev {
+ #define IN_LOOPBACKNET 127
+ #endif
+
++#if defined HAVE_FTRUNCATE && defined HAVE_POSIX_FALLOCATE
++#define SUPPORT_PREALLOCATION 1
++#endif
++
+ #define GID_NONE ((gid_t)-1)
+
+ #define HL_CHECK_MASTER 0
+--- old/t_stub.c
++++ new/t_stub.c
+@@ -23,6 +23,7 @@
+ #include "rsync.h"
+
+ int modify_window = 0;
++int preallocate_files = 0;
+ int module_id = -1;
+ int relative_paths = 0;
+ int human_readable = 0;
+--- old/util.c
++++ new/util.c
+@@ -25,6 +25,7 @@
+
+ extern int verbose;
+ extern int dry_run;
++extern int preallocate_files;
+ extern int module_id;
+ extern int modify_window;
+ extern int relative_paths;
+@@ -270,6 +271,10 @@ int copy_file(const char *source, const
+ int ofd;
+ char buf[1024 * 8];
+ int len; /* Number of bytes read into `buf'. */
++#ifdef SUPPORT_PREALLOCATION
++ int preallocated_len = 0;
++ int offset = 0;
++#endif
+
+ ifd = do_open(source, O_RDONLY, 0);
+ if (ifd == -1) {
+@@ -289,7 +294,27 @@ int copy_file(const char *source, const
+ return -1;
+ }
+
++#ifdef SUPPORT_PREALLOCATION
++ if (preallocate_files) {
++ /* Preallocate enough space for file's eventual length if
++ * possible; seems to reduce fragmentation on Windows. */
++ STRUCT_STAT srcst;
++ if (do_fstat(ifd, &srcst) == 0) {
++ if (srcst.st_size > 0) {
++ if (posix_fallocate(ofd, 0, srcst.st_size) == 0)
++ preallocated_len = srcst.st_size;
++ else
++ rsyserr(FINFO, errno, "posix_fallocate %s", full_fname(dest));
++ }
++ } else
++ rsyserr(FINFO, errno, "fstat %s", full_fname(source));
++ }
++#endif
++
+ while ((len = safe_read(ifd, buf, sizeof buf)) > 0) {
++#ifdef SUPPORT_PREALLOCATION
++ offset += len;
++#endif
+ if (full_write(ofd, buf, len) < 0) {
+ rsyserr(FERROR, errno, "write %s", full_fname(dest));
+ close(ifd);
+@@ -310,6 +335,16 @@ int copy_file(const char *source, const
+ full_fname(source));
+ }
+
++#ifdef SUPPORT_PREALLOCATION
++ /* Source file might have shrunk since we fstatted it.
++ * Cut off any extra preallocated zeros from dest file. */
++ if (preallocated_len > offset)
++ if (ftruncate(ofd, offset) < 0)
++ /* If we fail to truncate, the dest file may be wrong, so we
++ * must trigger the "partial transfer" error. */
++ rsyserr(FERROR, errno, "ftruncate %s", full_fname(dest));
++#endif
++
+ if (close(ofd) < 0) {
+ rsyserr(FERROR, errno, "close failed on %s",
+ full_fname(dest));
int fd;
--- old/configure.in
+++ new/configure.in
-@@ -592,6 +592,29 @@ if test $rsync_cv_can_hardlink_special =
+@@ -614,6 +614,29 @@ if test $rsync_cv_can_hardlink_special =
AC_DEFINE(CAN_HARDLINK_SPECIAL, 1, [Define to 1 if link() can hard-link special files.])
fi
FN_LOCAL_STRING(lp_comment, comment)
--- old/main.c
+++ new/main.c
-@@ -1058,6 +1058,18 @@ static int start_client(int argc, char *
+@@ -1059,6 +1059,18 @@ static int start_client(int argc, char *
if (!read_batch) { /* for read_batch, NO source is specified */
shell_path = check_for_hostspec(argv[0], &shell_machine, &rsync_port);
rprintf(f, "%s version %s protocol version %d\n",
RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION);
rprintf(f, "Copyright (C) 1996-2006 by Andrew Tridgell, Wayne Davison, and others.\n");
-@@ -235,9 +240,9 @@ static void print_rsync_version(enum log
- /* Note that this field may not have type ino_t. It depends
- * on the complicated interaction between largefile feature
- * macros. */
-- rprintf(f, " %sinplace, %sIPv6, "
-+ rprintf(f, " %sinplace, %sIPv6, %sSLP, "
- "%d-bit system inums, %d-bit internal inums\n",
-- have_inplace, ipv6,
-+ have_inplace, ipv6, slp,
- (int) (sizeof dumstat->st_ino * 8),
- (int) (sizeof (int64) * 8));
+@@ -233,8 +238,8 @@ static void print_rsync_version(enum log
+ (int)(sizeof (int64) * 8));
+ rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
+ got_socketpair, hardlinks, links, ipv6, have_inplace);
+- rprintf(f, " %sappend\n",
+- have_inplace);
++ rprintf(f, " %sappend, %sSLP\n",
++ have_inplace, slp);
+
#ifdef MAINTAINER_MODE
+ rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
--- old/rsync.h
+++ new/rsync.h
-@@ -157,6 +157,9 @@
+@@ -158,6 +158,9 @@
#define SIGNIFICANT_ITEM_FLAGS (~(\
ITEM_BASIS_TYPE_FOLLOWS | ITEM_XNAME_FOLLOWS | ITEM_LOCAL_CHANGE))
set_file_attrs(fullpath, file, NULL, 0);
free(file);
}
-@@ -195,6 +205,9 @@ static int keep_backup(char *fname)
+@@ -195,6 +205,9 @@ static int keep_backup(const char *fname
#ifdef SUPPORT_ACLS
sx.acc_acl = sx.def_acl = NULL;
#endif
if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
return 1; /* the file could have disappeared */
-@@ -208,6 +221,12 @@ static int keep_backup(char *fname)
+@@ -208,6 +221,12 @@ static int keep_backup(const char *fname
cache_acl(file, &sx);
}
#endif
if ((am_root && preserve_devices && IS_DEVICE(file->mode))
--- old/configure.in
+++ new/configure.in
-@@ -856,6 +856,40 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
+@@ -878,6 +878,40 @@ samba_cv_HAVE_ACL_GET_PERM_NP=yes,samba_
AC_MSG_RESULT(no)
)
extern int preserve_links;
extern int preserve_hard_links;
extern int preserve_devices;
-@@ -498,7 +499,7 @@ static struct file_struct *receive_file_
+@@ -499,7 +500,7 @@ static struct file_struct *receive_file_
char thisname[MAXPATHLEN];
unsigned int l1 = 0, l2 = 0;
int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
int xtra_len;
#endif
OFF_T file_length;
-@@ -610,10 +611,16 @@ static struct file_struct *receive_file_
+@@ -611,10 +612,16 @@ static struct file_struct *receive_file_
xtra_len = (S_ISDIR(mode) ? 2 : 1) * 4;
else
xtra_len = 0;
+ xtra_len
#endif
+ linkname_len + sum_len;
-@@ -622,7 +629,7 @@ static struct file_struct *receive_file_
+@@ -623,7 +630,7 @@ static struct file_struct *receive_file_
file = (struct file_struct *)bp;
memset(bp, 0, file_struct_len);
bp += file_struct_len;
bp += xtra_len;
#endif
-@@ -723,6 +730,10 @@ static struct file_struct *receive_file_
+@@ -724,6 +731,10 @@ static struct file_struct *receive_file_
if (preserve_acls)
receive_acl(file, f);
#endif
return file;
}
-@@ -974,7 +985,7 @@ static struct file_struct *send_file_nam
+@@ -982,7 +993,7 @@ static struct file_struct *send_file_nam
unsigned short flags)
{
struct file_struct *file;
statx sx;
#endif
-@@ -994,6 +1005,13 @@ static struct file_struct *send_file_nam
+@@ -1002,6 +1013,13 @@ static struct file_struct *send_file_nam
return NULL;
}
#endif
maybe_emit_filelist_progress(flist->count + flist_count_offset);
-@@ -1006,11 +1024,19 @@ static struct file_struct *send_file_nam
+@@ -1014,11 +1032,19 @@ static struct file_struct *send_file_nam
if (preserve_acls && f >= 0)
send_acl(&sx, f);
#endif
#ifdef SUPPORT_LINKS
links = "";
#endif
-@@ -236,8 +240,8 @@ static void print_rsync_version(enum log
- rprintf(f, "Capabilities: %d-bit files, %ssocketpairs, %shard links, %ssymlinks,\n",
- (int) (sizeof (OFF_T) * 8), got_socketpair, hardlinks, links);
+@@ -239,8 +243,8 @@ static void print_rsync_version(enum log
+ (int)(sizeof (int64) * 8));
+ rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n",
+ got_socketpair, hardlinks, links, ipv6, have_inplace);
+- rprintf(f, " %sappend, %sACLs\n",
+- have_inplace, acls);
++ rprintf(f, " %sappend, %sACLs, %sxattrs\n",
++ have_inplace, acls, xattrs);
-- rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs,\n",
-- have_inplace, ipv6, acls);
-+ rprintf(f, " batchfiles, %sinplace, %sIPv6, %sACLs, %sxattrs,\n",
-+ have_inplace, ipv6, acls, xattrs);
-
- /* Note that this field may not have type ino_t. It depends
- * on the complicated interaction between largefile feature
-@@ -289,7 +293,7 @@ void usage(enum logcode F)
+ #ifdef MAINTAINER_MODE
+ rprintf(f, "Panic Action: \"%s\"\n", get_panic_action());
+@@ -286,7 +290,7 @@ void usage(enum logcode F)
rprintf(F," -q, --quiet suppress non-error messages\n");
rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
rprintf(F," -r, --recursive recurse into directories\n");
rprintf(F," -R, --relative use relative path names\n");
-@@ -314,6 +318,9 @@ void usage(enum logcode F)
+@@ -311,6 +315,9 @@ void usage(enum logcode F)
#ifdef SUPPORT_ACLS
rprintf(F," -A, --acls preserve ACLs (implies --perms)\n");
#endif
rprintf(F," -o, --owner preserve owner (super-user only)\n");
rprintf(F," -g, --group preserve group\n");
rprintf(F," --devices preserve device files (super-user only)\n");
-@@ -436,6 +443,9 @@ static struct poptOption long_options[]
+@@ -434,6 +441,9 @@ static struct poptOption long_options[]
{"acls", 'A', POPT_ARG_NONE, 0, 'A', 0, 0 },
{"no-acls", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
{"no-A", 0, POPT_ARG_VAL, &preserve_acls, 0, 0, 0 },
{"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
{"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
{"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
-@@ -1117,6 +1127,17 @@ int parse_arguments(int *argc, const cha
+@@ -1116,6 +1126,17 @@ int parse_arguments(int *argc, const cha
return 0;
#endif
#define GID_NONE ((gid_t)-1)
#define HL_CHECK_MASTER 0
-@@ -692,6 +696,9 @@ typedef struct {
+@@ -699,6 +703,9 @@ typedef struct {
struct rsync_acl *acc_acl; /* access ACL */
struct rsync_acl *def_acl; /* default ACL */
#endif
-o, --owner preserve owner (super-user only)
-g, --group preserve group
--devices preserve device files (super-user only)
-@@ -818,6 +819,11 @@ version makes it incompatible with sendi
+@@ -819,6 +820,11 @@ version makes it incompatible with sendi
rsync unless you double the bf(--acls) option (e.g. bf(-AA)). This
doubling is not needed when pulling files from an older rsync.