just a stub for now
[rsync/rsync.git] / rsync.h
... / ...
CommitLineData
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#define RSYNC_NAME "rsync"
24#define BACKUP_SUFFIX "~"
25
26/* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is
27 imcompatible with older versions :-( */
28#define CHAR_OFFSET 0
29
30
31#define FLAG_DELETE (1<<0)
32#define SAME_MODE (1<<1)
33#define SAME_RDEV (1<<2)
34#define SAME_UID (1<<3)
35#define SAME_GID (1<<4)
36#define SAME_DIR (1<<5)
37#define SAME_NAME SAME_DIR
38#define LONG_NAME (1<<6)
39#define SAME_TIME (1<<7)
40
41/* update this if you make incompatible changes */
42#define PROTOCOL_VERSION 17
43#define MIN_PROTOCOL_VERSION 11
44#define MAX_PROTOCOL_VERSION 30
45
46#define RSYNC_PORT 873
47
48#define SPARSE_WRITE_SIZE (1024)
49#define WRITE_SIZE (32*1024)
50#define CHUNK_SIZE (32*1024)
51#define MAX_MAP_SIZE (4*1024*1024)
52
53#define BLOCKING_TIMEOUT 10
54
55#define FERROR 1
56#define FINFO 2
57
58#include "config.h"
59
60#if HAVE_REMSH
61#define RSYNC_RSH "remsh"
62#else
63#define RSYNC_RSH "rsh"
64#endif
65
66#include <sys/types.h>
67#ifdef HAVE_UNISTD_H
68#include <unistd.h>
69#endif
70#include <stdio.h>
71
72#ifdef HAVE_SYS_PARAM_H
73#include <sys/param.h>
74#endif
75
76#ifdef HAVE_STDLIB_H
77#include <stdlib.h>
78#endif
79
80#ifdef HAVE_SYS_SOCKET_H
81#include <sys/socket.h>
82#endif
83
84#ifdef HAVE_STRING_H
85#include <string.h>
86#endif
87
88#ifdef HAVE_COMPAT_H
89#include <compat.h>
90#endif
91
92#ifdef HAVE_MALLOC_H
93#include <malloc.h>
94#endif
95
96#ifdef TIME_WITH_SYS_TIME
97#include <sys/time.h>
98#include <time.h>
99#else
100#ifdef HAVE_SYS_TIME_H
101#include <sys/time.h>
102#else
103#include <time.h>
104#endif
105#endif
106
107#ifdef HAVE_FCNTL_H
108#include <fcntl.h>
109#else
110#ifdef HAVE_SYS_FCNTL_H
111#include <sys/fcntl.h>
112#endif
113#endif
114
115#include <sys/stat.h>
116
117#ifdef HAVE_SYS_IOCTL_H
118#include <sys/ioctl.h>
119#endif
120
121#ifdef HAVE_SYS_FILIO_H
122#include <sys/filio.h>
123#endif
124
125#include <signal.h>
126#ifdef HAVE_SYS_WAIT_H
127#include <sys/wait.h>
128#endif
129#ifdef HAVE_CTYPE_H
130#include <ctype.h>
131#endif
132#ifdef HAVE_GRP_H
133#include <grp.h>
134#endif
135#include <errno.h>
136
137#ifdef HAVE_MMAP
138#include <sys/mman.h>
139#endif
140
141#ifdef HAVE_UTIME_H
142#include <utime.h>
143#endif
144
145#ifdef HAVE_SYS_SELECT_H
146#include <sys/select.h>
147#endif
148
149#ifdef HAVE_SYS_MODE_H
150/* apparently AIX needs this for S_ISLNK */
151#ifndef S_ISLNK
152#include <sys/mode.h>
153#endif
154#endif
155
156#ifdef HAVE_FNMATCH
157#include <fnmatch.h>
158#else
159#include "lib/fnmatch.h"
160#endif
161
162#ifdef HAVE_GETOPT_LONG
163#include <getopt.h>
164#else
165#include "lib/getopt.h"
166#endif
167
168/* these are needed for the uid/gid mapping code */
169#include <pwd.h>
170#include <grp.h>
171
172#include <stdarg.h>
173
174#ifndef S_IFLNK
175#define S_IFLNK 0120000
176#endif
177
178#ifndef S_ISLNK
179#define S_ISLNK(mode) (((mode) & S_IFLNK) == S_IFLNK)
180#endif
181
182#ifndef uchar
183#define uchar unsigned char
184#endif
185
186#if HAVE_UNSIGNED_CHAR
187#define schar signed char
188#else
189#define schar char
190#endif
191
192#ifndef int32
193#if (SIZEOF_INT == 4)
194#define int32 int
195#elif (SIZEOF_LONG == 4)
196#define int32 long
197#elif (SIZEOF_SHORT == 4)
198#define int32 short
199#endif
200#endif
201
202#ifndef uint32
203#define uint32 unsigned int32
204#endif
205
206#if HAVE_OFF64_T
207#define OFF_T off64_t
208#define STRUCT_STAT struct stat64
209#else
210#define OFF_T off_t
211#define STRUCT_STAT struct stat
212#endif
213
214#if HAVE_OFF64_T
215#define int64 off64_t
216#elif (SIZEOF_LONG == 8)
217#define int64 long
218#elif (SIZEOF_INT == 8)
219#define int64 int
220#elif HAVE_LONGLONG
221#define int64 long long
222#else
223#define int64 off_t
224#define NO_INT64
225#endif
226
227#ifndef MIN
228#define MIN(a,b) ((a)<(b)?(a):(b))
229#endif
230
231#ifndef MAX
232#define MAX(a,b) ((a)>(b)?(a):(b))
233#endif
234
235/* the length of the md4 checksum */
236#define MD4_SUM_LENGTH 16
237#define SUM_LENGTH 16
238
239#ifndef MAXPATHLEN
240#define MAXPATHLEN 1024
241#endif
242
243struct file_struct {
244 unsigned flags;
245 time_t modtime;
246 OFF_T length;
247 mode_t mode;
248 ino_t inode;
249 dev_t dev;
250 dev_t rdev;
251 uid_t uid;
252 gid_t gid;
253 char *basename;
254 char *dirname;
255 char *basedir;
256 char *link;
257 char *sum;
258};
259
260struct file_list {
261 int count;
262 int malloced;
263 struct file_struct **files;
264};
265
266struct sum_buf {
267 OFF_T offset; /* offset in file of this chunk */
268 int len; /* length of chunk of file */
269 int i; /* index of this chunk */
270 uint32 sum1; /* simple checksum */
271 char sum2[SUM_LENGTH]; /* checksum */
272};
273
274struct sum_struct {
275 OFF_T flength; /* total file length */
276 int count; /* how many chunks */
277 int remainder; /* flength % block_length */
278 int n; /* block_length */
279 struct sum_buf *sums; /* points to info for each chunk */
280};
281
282struct map_struct {
283 char *map,*p;
284 int fd,p_size,p_len;
285 OFF_T size, p_offset;
286};
287
288/* we need this function because of the silly way in which duplicate
289 entries are handled in the file lists - we can't change this
290 without breaking existing versions */
291static inline int flist_up(struct file_list *flist, int i)
292{
293 while (!flist->files[i]->basename) i++;
294 return i;
295}
296
297#if HAVE_DIRENT_H
298# include <dirent.h>
299#else
300# define dirent direct
301# if HAVE_SYS_NDIR_H
302# include <sys/ndir.h>
303# endif
304# if HAVE_SYS_DIR_H
305# include <sys/dir.h>
306# endif
307# if HAVE_NDIR_H
308# include <ndir.h>
309# endif
310#endif
311
312#include "byteorder.h"
313#include "version.h"
314#include "proto.h"
315#include "md4.h"
316
317#if !HAVE_STRERROR
318extern char *sys_errlist[];
319#define strerror(i) sys_errlist[i]
320#endif
321
322#ifndef HAVE_STRCHR
323# define strchr index
324# define strrchr rindex
325#endif
326
327#ifndef HAVE_ERRNO_DECL
328extern int errno;
329#endif
330
331#ifndef HAVE_BCOPY
332#define bcopy(src,dest,n) memcpy(dest,src,n)
333#endif
334
335#ifndef HAVE_BZERO
336#define bzero(buf,n) memset(buf,0,n)
337#endif
338
339#define SUPPORT_LINKS HAVE_READLINK
340#define SUPPORT_HARD_LINKS HAVE_LINK
341
342#ifndef HAVE_LCHOWN
343#define lchown chown
344#endif
345
346#define SIGNAL_CAST (RETSIGTYPE (*)())
347
348#ifndef EWOULDBLOCK
349#define EWOULDBLOCK EAGAIN
350#endif
351
352#ifndef STDIN_FILENO
353#define STDIN_FILENO 0
354#endif
355
356#ifndef STDOUT_FILENO
357#define STDOUT_FILENO 1
358#endif
359
360#ifndef STDERR_FILENO
361#define STDERR_FILENO 2
362#endif
363
364#ifndef S_IWUSR
365#define S_IWUSR 0200
366#endif
367
368#ifndef S_ISBLK
369#define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
370#endif
371
372#ifndef S_ISCHR
373#define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
374#endif
375
376#ifndef S_ISSOCK
377#ifdef _S_IFSOCK
378#define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
379#else
380#define S_ISSOCK(mode) (0)
381#endif
382#endif
383
384#ifndef S_ISFIFO
385#ifdef _S_IFIFO
386#define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
387#else
388#define S_ISFIFO(mode) (0)
389#endif
390#endif
391
392#ifndef S_ISDIR
393#define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
394#endif
395
396#ifndef S_ISREG
397#define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
398#endif
399
400
401#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) || S_ISFIFO(mode))
402