added resend logic
[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 #define RSYNC_RSH "rsh"
23 #define RSYNC_NAME "rsync"
24 #define BACKUP_SUFFIX "~"
25
26 #define FILE_VALID 1
27 #define SAME_MODE (1<<1)
28 #define SAME_RDEV (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
36 /* update this if you make incompatible changes */
37 #define PROTOCOL_VERSION 14
38 #define MIN_PROTOCOL_VERSION 10
39 #define MAX_PROTOCOL_VERSION 20
40
41 #define SPARSE_WRITE_SIZE (4*1024)
42 #define WRITE_SIZE (32*1024)
43 #define CHUNK_SIZE (32*1024)
44 #define MAX_MAP_SIZE (4*1024*1024)
45
46 #define BLOCKING_TIMEOUT 10
47
48 #define FERROR stderr
49 #define FINFO (am_server?stderr:stdout)
50
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
63 #ifdef HAVE_STDLIB_H
64 #include <stdlib.h>
65 #endif
66
67 #ifdef HAVE_STRING_H
68 #include <string.h>
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
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
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
120 #ifdef HAVE_MMAP
121 #include <sys/mman.h>
122 #endif
123
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 */
173 #define SUM_LENGTH 16
174
175 #ifndef MAXPATHLEN
176 #define MAXPATHLEN 1024
177 #endif
178
179 struct file_struct {
180   time_t modtime;
181   off_t length;
182   mode_t mode;
183   ino_t inode;
184   dev_t dev;
185   dev_t rdev;
186   uid_t uid;
187   gid_t gid;
188   char *name;
189   char *dir;
190   char *link;
191   char sum[SUM_LENGTH];
192 };
193
194 struct file_list {
195   int count;
196   int malloced;
197   struct file_struct *files;
198 };
199
200 struct sum_buf {
201   off_t offset;                 /* offset in file of this chunk */
202   int len;                      /* length of chunk of file */
203   int i;                        /* index of this chunk */
204   uint32 sum1;                  /* simple checksum */
205   char sum2[SUM_LENGTH];        /* md4 checksum  */
206 };
207
208 struct sum_struct {
209   off_t flength;                /* total file length */
210   int count;                    /* how many chunks */
211   int remainder;                /* flength % block_length */
212   int n;                        /* block_length */
213   struct sum_buf *sums;         /* points to info for each chunk */
214 };
215
216 struct map_struct {
217   char *map,*p;
218   int fd,size,p_size,p_offset,p_len;
219 };
220
221 #include "byteorder.h"
222 #include "version.h"
223 #include "proto.h"
224 #include "md4.h"
225
226 #if !HAVE_STRERROR
227 extern char *sys_errlist[];
228 #define strerror(i) sys_errlist[i]
229 #endif
230
231 #ifndef HAVE_STRCHR
232 # define strchr                 index
233 # define strrchr                rindex
234 #endif
235
236 #if HAVE_DIRENT_H
237 # include <dirent.h>
238 #else
239 # define dirent direct
240 # if HAVE_SYS_NDIR_H
241 #  include <sys/ndir.h>
242 # endif
243 # if HAVE_SYS_DIR_H
244 #  include <sys/dir.h>
245 # endif
246 # if HAVE_NDIR_H
247 #  include <ndir.h>
248 # endif
249 #endif
250
251 #ifndef HAVE_ERRNO_DECL
252 extern int errno;
253 #endif
254
255 #ifndef HAVE_BCOPY
256 #define bcopy(src,dest,n) memcpy(dest,src,n)
257 #endif
258
259 #ifndef HAVE_BZERO
260 #define bzero(buf,n) memset(buf,0,n)
261 #endif
262
263 #define SUPPORT_LINKS (HAVE_READLINK && defined(S_ISLNK))
264 #define SUPPORT_HARD_LINKS HAVE_LINK
265
266 #ifndef S_ISLNK
267 #define S_ISLNK(x) 0
268 #endif
269
270 #if !SUPPORT_LINKS
271 #define lstat stat
272 #endif
273
274 #define SIGNAL_CAST (RETSIGTYPE (*)())
275
276 #ifndef EWOULDBLOCK
277 #define EWOULDBLOCK EAGAIN
278 #endif
279
280 #define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode))
281