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