Commit | Line | Data |
---|---|---|
c627d613 AT |
1 | /* |
2 | Copyright (C) Andrew Tridgell 1996 | |
3 | Copyright (C) Paul Mackerras 1996 | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
16 | along with this program; if not, write to the Free Software | |
17 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | */ | |
19 | ||
20 | #define BLOCK_SIZE 700 | |
21 | #define RSYNC_RSH_ENV "RSYNC_RSH" | |
22 | #define RSYNC_RSH "rsh" | |
23 | #define RSYNC_NAME "rsync" | |
24 | #define BACKUP_SUFFIX "~" | |
25 | ||
1b01b295 AT |
26 | /* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is |
27 | imcompatible with older versions :-( */ | |
28 | #define CHAR_OFFSET 0 | |
29 | ||
30 | ||
4fe159a8 AT |
31 | #define FILE_VALID 1 |
32 | #define SAME_MODE (1<<1) | |
dc5ddbcc | 33 | #define SAME_RDEV (1<<2) |
4fe159a8 AT |
34 | #define SAME_UID (1<<3) |
35 | #define SAME_GID (1<<4) | |
36 | #define SAME_DIR (1<<5) | |
37 | #define SAME_NAME SAME_DIR | |
38 | #define LONG_NAME (1<<6) | |
39 | #define SAME_TIME (1<<7) | |
40 | ||
c627d613 | 41 | /* update this if you make incompatible changes */ |
9e31c482 | 42 | #define PROTOCOL_VERSION 14 |
182dca5c | 43 | #define MIN_PROTOCOL_VERSION 10 |
7bec6a5c | 44 | #define MAX_PROTOCOL_VERSION 20 |
c627d613 | 45 | |
dc5ddbcc AT |
46 | #define SPARSE_WRITE_SIZE (4*1024) |
47 | #define WRITE_SIZE (32*1024) | |
34ccb63e | 48 | #define CHUNK_SIZE (32*1024) |
d9bea2dd | 49 | #define MAX_MAP_SIZE (4*1024*1024) |
c627d613 | 50 | |
58d433ab AT |
51 | #define BLOCKING_TIMEOUT 10 |
52 | ||
dc5ddbcc AT |
53 | #define FERROR stderr |
54 | #define FINFO (am_server?stderr:stdout) | |
7bec6a5c | 55 | |
c627d613 AT |
56 | #include "config.h" |
57 | ||
58 | #include <sys/types.h> | |
59 | #ifdef HAVE_UNISTD_H | |
60 | #include <unistd.h> | |
61 | #endif | |
62 | #include <stdio.h> | |
63 | ||
64 | #ifdef HAVE_SYS_PARAM_H | |
65 | #include <sys/param.h> | |
66 | #endif | |
67 | ||
d7b305fd AT |
68 | #ifdef HAVE_STDLIB_H |
69 | #include <stdlib.h> | |
70 | #endif | |
71 | ||
72 | #ifdef HAVE_STRING_H | |
73 | #include <string.h> | |
c627d613 AT |
74 | #endif |
75 | ||
76 | #ifdef HAVE_COMPAT_H | |
77 | #include <compat.h> | |
78 | #endif | |
79 | ||
80 | #ifdef HAVE_MALLOC_H | |
81 | #include <malloc.h> | |
82 | #endif | |
83 | ||
84 | #ifdef TIME_WITH_SYS_TIME | |
85 | #include <sys/time.h> | |
86 | #include <time.h> | |
87 | #else | |
88 | #ifdef HAVE_SYS_TIME_H | |
89 | #include <sys/time.h> | |
90 | #else | |
91 | #include <time.h> | |
92 | #endif | |
93 | #endif | |
94 | ||
95 | #ifdef HAVE_FCNTL_H | |
96 | #include <fcntl.h> | |
97 | #else | |
98 | #ifdef HAVE_SYS_FCNTL_H | |
99 | #include <sys/fcntl.h> | |
100 | #endif | |
101 | #endif | |
102 | ||
103 | #include <sys/stat.h> | |
104 | ||
94481d91 AT |
105 | #ifdef HAVE_SYS_IOCTL_H |
106 | #include <sys/ioctl.h> | |
107 | #endif | |
108 | ||
109 | #ifdef HAVE_SYS_FILIO_H | |
110 | #include <sys/filio.h> | |
111 | #endif | |
112 | ||
c627d613 AT |
113 | #include <signal.h> |
114 | #ifdef HAVE_SYS_WAIT_H | |
115 | #include <sys/wait.h> | |
116 | #endif | |
117 | #ifdef HAVE_CTYPE_H | |
118 | #include <ctype.h> | |
119 | #endif | |
120 | #ifdef HAVE_GRP_H | |
121 | #include <grp.h> | |
122 | #endif | |
123 | #include <errno.h> | |
124 | ||
7bec6a5c | 125 | #ifdef HAVE_MMAP |
c627d613 | 126 | #include <sys/mman.h> |
7bec6a5c AT |
127 | #endif |
128 | ||
c627d613 AT |
129 | #ifdef HAVE_UTIME_H |
130 | #include <utime.h> | |
131 | #endif | |
132 | ||
133 | #ifdef HAVE_FNMATCH | |
134 | #include <fnmatch.h> | |
135 | #else | |
136 | #include "lib/fnmatch.h" | |
137 | #endif | |
138 | ||
139 | #ifdef HAVE_GETOPT_LONG | |
140 | #include <getopt.h> | |
141 | #else | |
142 | #include "lib/getopt.h" | |
143 | #endif | |
144 | ||
145 | ||
146 | #ifndef S_ISLNK | |
147 | #define S_ISLNK(mode) (((mode) & S_IFLNK) == S_IFLNK) | |
148 | #endif | |
149 | ||
150 | #ifndef uchar | |
151 | #define uchar unsigned char | |
152 | #endif | |
153 | ||
154 | #ifndef int32 | |
155 | #if (SIZEOF_INT == 4) | |
156 | #define int32 int | |
157 | #elif (SIZEOF_LONG == 4) | |
158 | #define int32 long | |
159 | #elif (SIZEOF_SHORT == 4) | |
160 | #define int32 short | |
161 | #endif | |
162 | #endif | |
163 | ||
164 | #ifndef uint32 | |
165 | #define uint32 unsigned int32 | |
166 | #endif | |
167 | ||
168 | ||
169 | #ifndef MIN | |
170 | #define MIN(a,b) ((a)<(b)?(a):(b)) | |
171 | #endif | |
172 | ||
173 | #ifndef MAX | |
174 | #define MAX(a,b) ((a)>(b)?(a):(b)) | |
175 | #endif | |
176 | ||
177 | /* the length of the md4 checksum */ | |
ebb0a6f6 | 178 | #define MD4_SUM_LENGTH 16 |
c627d613 AT |
179 | #define SUM_LENGTH 16 |
180 | ||
181 | #ifndef MAXPATHLEN | |
182 | #define MAXPATHLEN 1024 | |
183 | #endif | |
184 | ||
185 | struct file_struct { | |
186 | time_t modtime; | |
187 | off_t length; | |
188 | mode_t mode; | |
dc5ddbcc | 189 | ino_t inode; |
c627d613 | 190 | dev_t dev; |
dc5ddbcc | 191 | dev_t rdev; |
c627d613 AT |
192 | uid_t uid; |
193 | gid_t gid; | |
194 | char *name; | |
195 | char *dir; | |
196 | char *link; | |
ebb0a6f6 | 197 | char sum[MD4_SUM_LENGTH]; |
c627d613 AT |
198 | }; |
199 | ||
200 | struct file_list { | |
201 | int count; | |
202 | int malloced; | |
203 | struct file_struct *files; | |
204 | }; | |
205 | ||
206 | struct sum_buf { | |
207 | off_t offset; /* offset in file of this chunk */ | |
208 | int len; /* length of chunk of file */ | |
209 | int i; /* index of this chunk */ | |
210 | uint32 sum1; /* simple checksum */ | |
ebb0a6f6 | 211 | char sum2[SUM_LENGTH]; /* checksum */ |
c627d613 AT |
212 | }; |
213 | ||
214 | struct sum_struct { | |
215 | off_t flength; /* total file length */ | |
216 | int count; /* how many chunks */ | |
217 | int remainder; /* flength % block_length */ | |
218 | int n; /* block_length */ | |
219 | struct sum_buf *sums; /* points to info for each chunk */ | |
220 | }; | |
221 | ||
c6e7fcb4 AT |
222 | struct map_struct { |
223 | char *map,*p; | |
224 | int fd,size,p_size,p_offset,p_len; | |
225 | }; | |
c627d613 AT |
226 | |
227 | #include "byteorder.h" | |
228 | #include "version.h" | |
229 | #include "proto.h" | |
230 | #include "md4.h" | |
231 | ||
232 | #if !HAVE_STRERROR | |
233 | extern char *sys_errlist[]; | |
234 | #define strerror(i) sys_errlist[i] | |
235 | #endif | |
236 | ||
237 | #ifndef HAVE_STRCHR | |
238 | # define strchr index | |
239 | # define strrchr rindex | |
240 | #endif | |
241 | ||
242 | #if HAVE_DIRENT_H | |
243 | # include <dirent.h> | |
244 | #else | |
245 | # define dirent direct | |
246 | # if HAVE_SYS_NDIR_H | |
247 | # include <sys/ndir.h> | |
248 | # endif | |
249 | # if HAVE_SYS_DIR_H | |
250 | # include <sys/dir.h> | |
251 | # endif | |
252 | # if HAVE_NDIR_H | |
253 | # include <ndir.h> | |
254 | # endif | |
255 | #endif | |
256 | ||
257 | #ifndef HAVE_ERRNO_DECL | |
258 | extern int errno; | |
259 | #endif | |
260 | ||
261 | #ifndef HAVE_BCOPY | |
262 | #define bcopy(src,dest,n) memcpy(dest,src,n) | |
263 | #endif | |
264 | ||
265 | #ifndef HAVE_BZERO | |
266 | #define bzero(buf,n) memset(buf,0,n) | |
267 | #endif | |
268 | ||
269 | #define SUPPORT_LINKS (HAVE_READLINK && defined(S_ISLNK)) | |
dc5ddbcc | 270 | #define SUPPORT_HARD_LINKS HAVE_LINK |
c627d613 | 271 | |
7bec6a5c AT |
272 | #ifndef S_ISLNK |
273 | #define S_ISLNK(x) 0 | |
274 | #endif | |
275 | ||
c627d613 AT |
276 | #if !SUPPORT_LINKS |
277 | #define lstat stat | |
278 | #endif | |
ac1eb754 AT |
279 | |
280 | #define SIGNAL_CAST (RETSIGTYPE (*)()) | |
720b47f2 AT |
281 | |
282 | #ifndef EWOULDBLOCK | |
283 | #define EWOULDBLOCK EAGAIN | |
284 | #endif | |
182dca5c AT |
285 | |
286 | #define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode)) | |
7bec6a5c | 287 |