just a stub for now
[rsync/rsync.git] / rsync.h
CommitLineData
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"
7b8356d0 22
c627d613
AT
23#define RSYNC_NAME "rsync"
24#define BACKUP_SUFFIX "~"
25
1b01b295
AT
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
3333ffbd 31#define FLAG_DELETE (1<<0)
4fe159a8 32#define SAME_MODE (1<<1)
dc5ddbcc 33#define SAME_RDEV (1<<2)
4fe159a8
AT
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
c627d613 41/* update this if you make incompatible changes */
6ba9279f 42#define PROTOCOL_VERSION 17
3ec4dd97 43#define MIN_PROTOCOL_VERSION 11
6ba9279f 44#define MAX_PROTOCOL_VERSION 30
c627d613 45
9486289c
AT
46#define RSYNC_PORT 873
47
d867229b 48#define SPARSE_WRITE_SIZE (1024)
dc5ddbcc 49#define WRITE_SIZE (32*1024)
34ccb63e 50#define CHUNK_SIZE (32*1024)
d9bea2dd 51#define MAX_MAP_SIZE (4*1024*1024)
c627d613 52
58d433ab
AT
53#define BLOCKING_TIMEOUT 10
54
9486289c
AT
55#define FERROR 1
56#define FINFO 2
7bec6a5c 57
c627d613
AT
58#include "config.h"
59
24d95c03
AT
60#if HAVE_REMSH
61#define RSYNC_RSH "remsh"
62#else
63#define RSYNC_RSH "rsh"
64#endif
65
c627d613
AT
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
d7b305fd
AT
76#ifdef HAVE_STDLIB_H
77#include <stdlib.h>
78#endif
79
fdd71e17
AT
80#ifdef HAVE_SYS_SOCKET_H
81#include <sys/socket.h>
82#endif
83
d7b305fd
AT
84#ifdef HAVE_STRING_H
85#include <string.h>
c627d613
AT
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
94481d91
AT
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
c627d613
AT
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
7bec6a5c 137#ifdef HAVE_MMAP
c627d613 138#include <sys/mman.h>
7bec6a5c
AT
139#endif
140
c627d613
AT
141#ifdef HAVE_UTIME_H
142#include <utime.h>
143#endif
144
8bf73749
AT
145#ifdef HAVE_SYS_SELECT_H
146#include <sys/select.h>
147#endif
148
773f2bd4
AT
149#ifdef HAVE_SYS_MODE_H
150/* apparently AIX needs this for S_ISLNK */
05a6556d 151#ifndef S_ISLNK
773f2bd4
AT
152#include <sys/mode.h>
153#endif
05a6556d 154#endif
773f2bd4 155
c627d613
AT
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
f6c34742
AT
168/* these are needed for the uid/gid mapping code */
169#include <pwd.h>
170#include <grp.h>
171
9486289c
AT
172#include <stdarg.h>
173
cbbe4892
AT
174#ifndef S_IFLNK
175#define S_IFLNK 0120000
176#endif
c627d613
AT
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
debb4505
AT
186#if HAVE_UNSIGNED_CHAR
187#define schar signed char
188#else
189#define schar char
190#endif
191
c627d613
AT
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
bcacc18b
AT
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)
3bee6733
AT
217#define int64 long
218#elif (SIZEOF_INT == 8)
219#define int64 int
220#elif HAVE_LONGLONG
71c46176
AT
221#define int64 long long
222#else
223#define int64 off_t
3bee6733 224#define NO_INT64
71c46176 225#endif
c627d613
AT
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 */
ebb0a6f6 236#define MD4_SUM_LENGTH 16
c627d613
AT
237#define SUM_LENGTH 16
238
239#ifndef MAXPATHLEN
240#define MAXPATHLEN 1024
241#endif
242
243struct file_struct {
3333ffbd 244 unsigned flags;
3ec4dd97 245 time_t modtime;
bcacc18b 246 OFF_T length;
3ec4dd97
AT
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;
2d0bb8eb 257 char *sum;
c627d613
AT
258};
259
260struct file_list {
261 int count;
262 int malloced;
3ec4dd97 263 struct file_struct **files;
c627d613
AT
264};
265
266struct sum_buf {
bcacc18b 267 OFF_T offset; /* offset in file of this chunk */
c627d613
AT
268 int len; /* length of chunk of file */
269 int i; /* index of this chunk */
270 uint32 sum1; /* simple checksum */
ebb0a6f6 271 char sum2[SUM_LENGTH]; /* checksum */
c627d613
AT
272};
273
274struct sum_struct {
bcacc18b 275 OFF_T flength; /* total file length */
c627d613
AT
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
c6e7fcb4 282struct map_struct {
0b910560
AT
283 char *map,*p;
284 int fd,p_size,p_len;
bcacc18b 285 OFF_T size, p_offset;
c6e7fcb4 286};
c627d613 287
3b3a2fbc
AT
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 */
71c46176 291static inline int flist_up(struct file_list *flist, int i)
3b3a2fbc 292{
3ec4dd97 293 while (!flist->files[i]->basename) i++;
3b3a2fbc
AT
294 return i;
295}
296
d6e6ecbd
AT
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
3b3a2fbc 311
c627d613
AT
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
c627d613
AT
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
cbbe4892 339#define SUPPORT_LINKS HAVE_READLINK
dc5ddbcc 340#define SUPPORT_HARD_LINKS HAVE_LINK
c627d613 341
8bf73749
AT
342#ifndef HAVE_LCHOWN
343#define lchown chown
344#endif
345
ac1eb754 346#define SIGNAL_CAST (RETSIGTYPE (*)())
720b47f2
AT
347
348#ifndef EWOULDBLOCK
349#define EWOULDBLOCK EAGAIN
350#endif
182dca5c 351
7b8356d0
AT
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
1e9f155a
AT
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
a0b65b18
AT
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
1e9f155a
AT
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
a0b65b18
AT
400
401#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) || S_ISFIFO(mode))
7bec6a5c 402