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