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