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