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