X-Git-Url: https://mattmccutchen.net/rsync/rsync-patches.git/blobdiff_plain/f9df736a3e22f15307f9e304eb9069b06e94208f..0ef5abcbbb95298fa9faf1d3eb275a9e76e1d951:/preallocate.diff diff --git a/preallocate.diff b/preallocate.diff index 97c0b96..e9cd77c 100644 --- a/preallocate.diff +++ b/preallocate.diff @@ -20,7 +20,7 @@ diff --git a/compat.c b/compat.c extern int append_mode; extern int fuzzy_basis; extern int read_batch; -@@ -184,6 +185,15 @@ void setup_protocol(int f_out,int f_in) +@@ -187,6 +188,15 @@ void setup_protocol(int f_out,int f_in) if (read_batch) check_batch_flags(); @@ -39,7 +39,7 @@ diff --git a/compat.c b/compat.c diff --git a/configure.in b/configure.in --- a/configure.in +++ b/configure.in -@@ -552,13 +552,40 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strdup chown chmod lchmod mknod mkfifo \ +@@ -554,13 +554,40 @@ AC_CHECK_FUNCS(waitpid wait4 getcwd strdup chown chmod lchmod mknod mkfifo \ 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 getxattr \ @@ -84,7 +84,7 @@ diff --git a/configure.in b/configure.in diff --git a/options.c b/options.c --- a/options.c +++ b/options.c -@@ -72,6 +72,7 @@ int remove_source_files = 0; +@@ -73,6 +73,7 @@ int remove_source_files = 0; int one_file_system = 0; int protocol_version = PROTOCOL_VERSION; int sparse_files = 0; @@ -92,7 +92,7 @@ diff --git a/options.c b/options.c int do_compression = 0; int def_compress_level = Z_DEFAULT_COMPRESSION; int am_root = 0; /* 0 = normal, 1 = root, 2 = --super, -1 = --fake-super */ -@@ -224,6 +225,7 @@ static void print_rsync_version(enum logcode f) +@@ -225,6 +226,7 @@ static void print_rsync_version(enum logcode f) char const *links = "no "; char const *iconv = "no "; char const *ipv6 = "no "; @@ -100,7 +100,7 @@ diff --git a/options.c b/options.c STRUCT_STAT *dumstat; #if SUBPROTOCOL_VERSION != 0 -@@ -256,6 +258,9 @@ static void print_rsync_version(enum logcode f) +@@ -258,6 +260,9 @@ static void print_rsync_version(enum logcode f) #if defined HAVE_LUTIMES && defined HAVE_UTIMES symtimes = ""; #endif @@ -110,7 +110,7 @@ diff --git a/options.c b/options.c rprintf(f, "%s version %s protocol version %d%s\n", RSYNC_NAME, RSYNC_VERSION, PROTOCOL_VERSION, subprotocol); -@@ -269,8 +274,8 @@ static void print_rsync_version(enum logcode f) +@@ -271,8 +276,8 @@ static void print_rsync_version(enum logcode f) (int)(sizeof (int64) * 8)); rprintf(f, " %ssocketpairs, %shardlinks, %ssymlinks, %sIPv6, batchfiles, %sinplace,\n", got_socketpair, hardlinks, links, ipv6, have_inplace); @@ -121,7 +121,7 @@ diff --git a/options.c b/options.c #ifdef MAINTAINER_MODE rprintf(f, "Panic Action: \"%s\"\n", get_panic_action()); -@@ -357,6 +362,9 @@ void usage(enum logcode F) +@@ -359,6 +364,9 @@ void usage(enum logcode F) rprintf(F," --fake-super store/recover privileged attrs using xattrs\n"); #endif rprintf(F," -S, --sparse handle sparse files efficiently\n"); @@ -131,24 +131,24 @@ diff --git a/options.c b/options.c rprintf(F," -n, --dry-run perform a trial run with no changes made\n"); rprintf(F," -W, --whole-file copy files whole (without delta-xfer algorithm)\n"); rprintf(F," -x, --one-file-system don't cross filesystem boundaries\n"); -@@ -537,6 +545,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 }, +@@ -543,6 +551,7 @@ static struct poptOption long_options[] = { + {"sparse", 'S', POPT_ARG_VAL, &sparse_files, 1, 0, 0 }, + {"no-sparse", 0, POPT_ARG_VAL, &sparse_files, 0, 0, 0 }, + {"no-S", 0, POPT_ARG_VAL, &sparse_files, 0, 0, 0 }, + {"preallocate", 0, POPT_ARG_NONE, &preallocate_files, 0, 0, 0}, - {"inplace", 0, POPT_ARG_NONE, &inplace, 0, 0, 0 }, + {"inplace", 0, POPT_ARG_VAL, &inplace, 1, 0, 0 }, + {"no-inplace", 0, POPT_ARG_VAL, &inplace, 0, 0, 0 }, {"append", 0, POPT_ARG_NONE, 0, OPT_APPEND, 0, 0 }, - {"append-verify", 0, POPT_ARG_VAL, &append_mode, 2, 0, 0 }, -@@ -2022,6 +2031,9 @@ void server_options(char **args, int *argc_p) +@@ -2063,6 +2072,9 @@ void server_options(char **args, int *argc_p) else if (remove_source_files) args[ac++] = "--remove-sent-files"; + if (preallocate_files && am_sender) + args[ac++] = "--preallocate"; + - *argc_p = ac; - return; - + if (ac > MAX_SERVER_ARGS) { /* Not possible... */ + rprintf(FERROR, "argc overflow in server_options().\n"); + exit_cleanup(RERR_MALLOC); diff --git a/receiver.c b/receiver.c --- a/receiver.c +++ b/receiver.c @@ -160,7 +160,7 @@ diff --git a/receiver.c b/receiver.c extern int keep_partial; extern int checksum_seed; extern int inplace; -@@ -174,6 +175,18 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r, +@@ -175,6 +176,18 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r, char *data; int32 i; char *map = NULL; @@ -179,31 +179,27 @@ diff --git a/receiver.c b/receiver.c read_sum_head(f_in, &sum); -@@ -284,8 +297,18 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r, +@@ -285,7 +298,15 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r, goto report_write_error; #ifdef HAVE_FTRUNCATE -- if (inplace && fd != -1) -- ftruncate(fd, offset); +- if (inplace && fd != -1 + /* 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 ++ if (fd != -1 +#ifdef SUPPORT_PREALLOCATION -+ || preallocated_len > offset ++ && (inplace || preallocated_len > offset) ++#else ++ && inplace +#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_XFER, errno, "ftruncate %s", full_fname(fname)); - #endif - - if (do_progress) + && ftruncate(fd, offset) < 0) { + rsyserr(FERROR_XFER, errno, "ftruncate failed on %s", + full_fname(fname)); diff --git a/rsync.h b/rsync.h --- a/rsync.h +++ b/rsync.h -@@ -602,6 +602,13 @@ struct ht_int64_node { +@@ -614,6 +614,13 @@ struct ht_int64_node { #define ACLS_NEED_MASK 1 #endif @@ -220,7 +216,7 @@ diff --git a/rsync.h b/rsync.h diff --git a/rsync.yo b/rsync.yo --- a/rsync.yo +++ b/rsync.yo -@@ -352,6 +352,7 @@ to the detailed description below for a complete description. verb( +@@ -356,6 +356,7 @@ to the detailed description below for a complete description. verb( --super receiver attempts super-user activities --fake-super store/recover privileged attrs using xattrs -S, --sparse handle sparse files efficiently @@ -228,7 +224,7 @@ diff --git a/rsync.yo b/rsync.yo -n, --dry-run perform a trial run with no changes made -W, --whole-file copy files whole (w/o delta-xfer algorithm) -x, --one-file-system don't cross filesystem boundaries -@@ -1036,6 +1037,18 @@ NOTE: Don't use this option when the destination is a Solaris "tmpfs" +@@ -1053,6 +1054,18 @@ NOTE: Don't use this option when the destination is a Solaris "tmpfs" filesystem. It doesn't seem to handle seeks over null regions correctly and ends up corrupting the files. @@ -261,8 +257,8 @@ diff --git a/syscall.c b/syscall.c extern int dry_run; extern int am_root; extern int read_only; -@@ -291,3 +295,21 @@ char *d_name(struct dirent *di) - return di->d_name; +@@ -282,3 +286,21 @@ OFF_T do_lseek(int fd, OFF_T offset, int whence) + return lseek(fd, offset, whence); #endif } + @@ -305,7 +301,7 @@ diff --git a/util.c b/util.c extern int module_id; extern int modify_window; extern int relative_paths; -@@ -273,6 +274,10 @@ int copy_file(const char *source, const char *dest, int ofd, +@@ -276,6 +277,10 @@ int copy_file(const char *source, const char *dest, int ofd, int ifd; char buf[1024 * 8]; int len; /* Number of bytes read into `buf'. */ @@ -315,8 +311,8 @@ diff --git a/util.c b/util.c +#endif if ((ifd = do_open(source, O_RDONLY, 0)) < 0) { - rsyserr(FERROR_XFER, errno, "open %s", full_fname(source)); -@@ -294,7 +299,27 @@ int copy_file(const char *source, const char *dest, int ofd, + int save_errno = errno; +@@ -309,7 +314,27 @@ int copy_file(const char *source, const char *dest, int ofd, } } @@ -342,9 +338,9 @@ diff --git a/util.c b/util.c + offset += len; +#endif if (full_write(ofd, buf, len) < 0) { + int save_errno = errno; rsyserr(FERROR_XFER, errno, "write %s", full_fname(dest)); - close(ifd); -@@ -315,6 +340,16 @@ int copy_file(const char *source, const char *dest, int ofd, +@@ -334,6 +359,16 @@ int copy_file(const char *source, const char *dest, int ofd, full_fname(source)); } @@ -359,5 +355,5 @@ diff --git a/util.c b/util.c +#endif + if (close(ofd) < 0) { + int save_errno = errno; rsyserr(FERROR_XFER, errno, "close failed on %s", - full_fname(dest));