Mention option in the man-page.
[rsync/rsync-patches.git] / copy-devices.diff
CommitLineData
998e0bab
WD
1This patch adds the --copy-devices option, which will try to copy
2the data inside a device instead of duplicating the device node.
3
4To use this patch, run these commands for a successful build:
5
6 patch -p1 <patches/copy-devices.diff
7 ./prepare-source
8 ./configure (optional if already run)
9 make
10
11--- old/generator.c
12+++ new/generator.c
13@@ -39,6 +39,7 @@ extern int preserve_acls;
14 extern int preserve_xattrs;
15 extern int preserve_links;
16 extern int preserve_devices;
17+extern int copy_devices;
18 extern int preserve_specials;
19 extern int preserve_hard_links;
20 extern int preserve_perms;
790ba11a 21@@ -1480,7 +1481,7 @@ static void recv_generator(char *fname,
998e0bab
WD
22 goto cleanup;
23 }
24
25- if (!S_ISREG(file->mode)) {
26+ if (!(S_ISREG(file->mode) || (copy_devices && IS_DEVICE(file->mode)))) {
27 if (solo_file)
28 fname = f_name(file, NULL);
29 rprintf(FINFO, "skipping non-regular file \"%s\"\n", fname);
30--- old/options.c
31+++ new/options.c
32@@ -45,6 +45,7 @@ int append_mode = 0;
33 int keep_dirlinks = 0;
34 int copy_dirlinks = 0;
35 int copy_links = 0;
36+int copy_devices = 0;
37 int preserve_links = 0;
38 int preserve_hard_links = 0;
39 int preserve_acls = 0;
790ba11a 40@@ -341,6 +342,7 @@ void usage(enum logcode F)
998e0bab
WD
41 rprintf(F," -o, --owner preserve owner (super-user only)\n");
42 rprintf(F," -g, --group preserve group\n");
43 rprintf(F," --devices preserve device files (super-user only)\n");
44+ rprintf(F," --copy-devices copy device contents as regular file\n");
45 rprintf(F," --specials preserve special files\n");
46 rprintf(F," -D same as --devices --specials\n");
47 rprintf(F," -t, --times preserve modification times\n");
790ba11a 48@@ -496,6 +498,7 @@ static struct poptOption long_options[]
998e0bab
WD
49 {"no-D", 0, POPT_ARG_NONE, 0, OPT_NO_D, 0, 0 },
50 {"devices", 0, POPT_ARG_VAL, &preserve_devices, 1, 0, 0 },
51 {"no-devices", 0, POPT_ARG_VAL, &preserve_devices, 0, 0, 0 },
52+ {"copy-devices", 0, POPT_ARG_NONE, &copy_devices, 0, 0, 0 },
53 {"specials", 0, POPT_ARG_VAL, &preserve_specials, 1, 0, 0 },
54 {"no-specials", 0, POPT_ARG_VAL, &preserve_specials, 0, 0, 0 },
55 {"links", 'l', POPT_ARG_VAL, &preserve_links, 1, 0, 0 },
790ba11a 56@@ -1978,6 +1981,9 @@ void server_options(char **args, int *ar
998e0bab
WD
57 else if (remove_source_files)
58 args[ac++] = "--remove-sent-files";
59
60+ if (copy_devices)
61+ args[ac++] = "--copy-devices";
62+
790ba11a 63 *argc_p = ac;
998e0bab
WD
64 return;
65
66--- old/rsync.c
67+++ new/rsync.c
a54a2c4d
WD
68@@ -33,6 +33,7 @@ extern int preserve_xattrs;
69 extern int preserve_perms;
998e0bab
WD
70 extern int preserve_executability;
71 extern int preserve_times;
998e0bab
WD
72+extern int copy_devices;
73 extern int am_root;
74 extern int am_server;
75 extern int am_sender;
a54a2c4d 76@@ -219,7 +220,8 @@ int read_ndx_and_attrs(int f_in, int *if
998e0bab
WD
77
78 if (iflags & ITEM_TRANSFER) {
79 int i = ndx - cur_flist->ndx_start;
80- if (i < 0 || !S_ISREG(cur_flist->files[i]->mode)) {
81+ struct file_struct *file = cur_flist->files[i];
82+ if (i < 0 || !(S_ISREG(file->mode) || (copy_devices && IS_DEVICE(file->mode)))) {
83 rprintf(FERROR,
84 "received request to transfer non-regular file: %d [%s]\n",
85 ndx, who_am_i());
86--- old/sender.c
87+++ new/sender.c
88@@ -314,6 +314,20 @@ void send_files(int f_in, int f_out)
89 exit_cleanup(RERR_PROTOCOL);
90 }
91
92+ /* On Matt's computer, st_size is falsely 0 for most devices.
93+ * If this happens, try harder to determine the actual device size. */
94+ if (IS_DEVICE(st.st_mode) && st.st_size == 0) {
95+ OFF_T off = lseek(fd, 0, SEEK_END);
96+ if (off == (OFF_T) -1)
97+ rsyserr(FERROR, errno, "failed to seek to end of %s to determine size", fname);
98+ else {
99+ st.st_size = off;
100+ off = lseek(fd, 0, SEEK_SET);
101+ if (off != 0)
102+ rsyserr(FERROR, errno, "failed to seek back to beginning of %s to read it", fname);
103+ }
104+ }
105+
106 if (st.st_size) {
107 int32 read_size = MAX(s->blength * 3, MAX_MAP_SIZE);
108 mbuf = map_file(fd, st.st_size, read_size, s->blength);