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