1 This patch from Sami Farin lets you specify --fsync if you want fsync()
2 to be called on every file we write.
4 To use this patch, run these commands for a successful build:
6 patch -p1 <patches/fsync.diff
7 ./configure (optional if already run)
10 based-on: 8695bcc2b140b2518254234659a03b96f04055fc
11 diff --git a/options.c b/options.c
14 @@ -69,6 +69,7 @@ int open_noatime = 0;
21 int delete_during = 0;
22 @@ -1010,6 +1011,7 @@ static struct poptOption long_options[] = {
23 {"no-timeout", 0, POPT_ARG_VAL, &io_timeout, 0, 0, 0 },
24 {"contimeout", 0, POPT_ARG_INT, &connect_timeout, 0, 0, 0 },
25 {"no-contimeout", 0, POPT_ARG_VAL, &connect_timeout, 0, 0, 0 },
26 + {"fsync", 0, POPT_ARG_NONE, &do_fsync, 0, 0, 0 },
27 {"stop-after", 0, POPT_ARG_STRING, 0, OPT_STOP_AFTER, 0, 0 },
28 {"time-limit", 0, POPT_ARG_STRING, 0, OPT_STOP_AFTER, 0, 0 }, /* earlier stop-after name */
29 {"stop-at", 0, POPT_ARG_STRING, 0, OPT_STOP_AT, 0, 0 },
30 @@ -3078,6 +3080,9 @@ void server_options(char **args, int *argc_p)
35 + args[ac++] = "--fsync";
38 /* the server only needs this option if it is not the sender,
39 * and it may be an older version that doesn't know this
40 diff --git a/receiver.c b/receiver.c
43 @@ -41,6 +41,7 @@ extern int preserve_hard_links;
44 extern int preserve_perms;
45 extern int write_devices;
46 extern int preserve_xattrs;
48 extern int basis_dir_cnt;
49 extern int make_backups;
50 extern int cleanup_got_literal;
51 @@ -394,6 +395,12 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
53 sum_len = sum_end(file_sum1);
55 + if (do_fsync && fd != -1 && fsync(fd) != 0) {
56 + rsyserr(FERROR, errno, "fsync failed on %s",
58 + exit_cleanup(RERR_FILEIO);
64 diff --git a/rsync.1.md b/rsync.1.md
67 @@ -410,6 +410,7 @@ detailed description below for a complete description.
68 --partial-dir=DIR put a partially transferred file into DIR
69 --delay-updates put all updated files into place at end
70 --prune-empty-dirs, -m prune empty directory chains from file-list
71 +--fsync fsync every written file
72 --numeric-ids don't map uid/gid values by user/group name
73 --usermap=STRING custom username mapping
74 --groupmap=STRING custom groupname mapping
75 diff --git a/t_stub.c b/t_stub.c
84 int modify_window = 0;
85 int preallocate_files = 0;
86 diff --git a/util.c b/util.c
94 extern int protect_args;
95 extern int modify_window;
96 extern int relative_paths;
97 @@ -412,6 +413,13 @@ int copy_file(const char *source, const char *dest, int ofd, mode_t mode)
98 rsyserr(FERROR_XFER, errno, "ftruncate %s", full_fname(dest));
101 + if (do_fsync && fsync(ofd) < 0) {
102 + rsyserr(FERROR, errno, "fsync failed on %s",
108 if (close(ofd) < 0) {
109 int save_errno = errno;
110 rsyserr(FERROR_XFER, errno, "close failed on %s",