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