Make a special version number 2.3.0-beta for a short period because
[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
d41c7d02
DD
20#define False 0
21#define True 1
22
c627d613
AT
23#define BLOCK_SIZE 700
24#define RSYNC_RSH_ENV "RSYNC_RSH"
7b8356d0 25
c627d613 26#define RSYNC_NAME "rsync"
f0fca04e 27#define RSYNCD_CONF "/etc/rsyncd.conf"
f0fca04e 28
5e71c444 29#define DEFAULT_LOCK_FILE "/var/run/rsyncd.lock"
f7632fc6
AT
30#define URL_PREFIX "rsync://"
31
c627d613
AT
32#define BACKUP_SUFFIX "~"
33
1b01b295
AT
34/* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is
35 imcompatible with older versions :-( */
36#define CHAR_OFFSET 0
37
38
3333ffbd 39#define FLAG_DELETE (1<<0)
4fe159a8 40#define SAME_MODE (1<<1)
dc5ddbcc 41#define SAME_RDEV (1<<2)
4fe159a8
AT
42#define SAME_UID (1<<3)
43#define SAME_GID (1<<4)
44#define SAME_DIR (1<<5)
45#define SAME_NAME SAME_DIR
46#define LONG_NAME (1<<6)
47#define SAME_TIME (1<<7)
48
c627d613 49/* update this if you make incompatible changes */
7b1ce0d7 50#define PROTOCOL_VERSION 19
3ec4dd97 51#define MIN_PROTOCOL_VERSION 11
6ba9279f 52#define MAX_PROTOCOL_VERSION 30
c627d613 53
9486289c
AT
54#define RSYNC_PORT 873
55
d867229b 56#define SPARSE_WRITE_SIZE (1024)
dc5ddbcc 57#define WRITE_SIZE (32*1024)
34ccb63e 58#define CHUNK_SIZE (32*1024)
4440b8aa 59#define MAX_MAP_SIZE (256*1024)
e3fe383a 60#define IO_BUFFER_SIZE (4092)
5dd7e031 61#define MAX_READ_BUFFER (1024*1024)
c627d613 62
874895d5 63#define MAX_ARGS 1000
f0fca04e 64
8d9dc9f9 65#define MPLEX_BASE 7
9486289c
AT
66#define FERROR 1
67#define FINFO 2
11a5a3c7 68#define FLOG 3
7bec6a5c 69
65417579
AT
70#include "errcode.h"
71
c627d613
AT
72#include "config.h"
73
24d95c03
AT
74#if HAVE_REMSH
75#define RSYNC_RSH "remsh"
76#else
77#define RSYNC_RSH "rsh"
78#endif
79
c627d613 80#include <sys/types.h>
6ed67e6d
AT
81
82#ifdef HAVE_GETOPT_LONG
83#include <getopt.h>
84#else
85#include "lib/getopt.h"
86#endif
87
c627d613
AT
88#ifdef HAVE_UNISTD_H
89#include <unistd.h>
90#endif
91#include <stdio.h>
3591c066 92#include <stddef.h>
c627d613
AT
93
94#ifdef HAVE_SYS_PARAM_H
95#include <sys/param.h>
96#endif
97
d7b305fd
AT
98#ifdef HAVE_STDLIB_H
99#include <stdlib.h>
100#endif
101
fdd71e17
AT
102#ifdef HAVE_SYS_SOCKET_H
103#include <sys/socket.h>
104#endif
105
d7b305fd
AT
106#ifdef HAVE_STRING_H
107#include <string.h>
c627d613
AT
108#endif
109
c627d613
AT
110#ifdef HAVE_MALLOC_H
111#include <malloc.h>
112#endif
113
114#ifdef TIME_WITH_SYS_TIME
115#include <sys/time.h>
116#include <time.h>
117#else
118#ifdef HAVE_SYS_TIME_H
119#include <sys/time.h>
120#else
121#include <time.h>
122#endif
123#endif
124
125#ifdef HAVE_FCNTL_H
126#include <fcntl.h>
127#else
128#ifdef HAVE_SYS_FCNTL_H
129#include <sys/fcntl.h>
130#endif
131#endif
132
133#include <sys/stat.h>
134
94481d91
AT
135#ifdef HAVE_SYS_IOCTL_H
136#include <sys/ioctl.h>
137#endif
138
139#ifdef HAVE_SYS_FILIO_H
140#include <sys/filio.h>
141#endif
142
c627d613
AT
143#include <signal.h>
144#ifdef HAVE_SYS_WAIT_H
145#include <sys/wait.h>
146#endif
147#ifdef HAVE_CTYPE_H
148#include <ctype.h>
149#endif
150#ifdef HAVE_GRP_H
151#include <grp.h>
152#endif
153#include <errno.h>
154
c627d613
AT
155#ifdef HAVE_UTIME_H
156#include <utime.h>
157#endif
158
8bf73749
AT
159#ifdef HAVE_SYS_SELECT_H
160#include <sys/select.h>
161#endif
162
773f2bd4
AT
163#ifdef HAVE_SYS_MODE_H
164/* apparently AIX needs this for S_ISLNK */
05a6556d 165#ifndef S_ISLNK
773f2bd4
AT
166#include <sys/mode.h>
167#endif
05a6556d 168#endif
773f2bd4 169
c627d613
AT
170#ifdef HAVE_FNMATCH
171#include <fnmatch.h>
172#else
173#include "lib/fnmatch.h"
174#endif
175
932be9aa 176#ifdef HAVE_GLOB_H
874895d5
AT
177#include <glob.h>
178#endif
179
f6c34742
AT
180/* these are needed for the uid/gid mapping code */
181#include <pwd.h>
182#include <grp.h>
183
9486289c 184#include <stdarg.h>
f0fca04e
AT
185#include <netinet/in.h>
186#include <arpa/inet.h>
187#include <netdb.h>
ff8b29b8 188#include <syslog.h>
6c8f5373 189#include <sys/file.h>
9486289c 190
e8f5b936
AT
191#if HAVE_DIRENT_H
192# include <dirent.h>
193#else
194# define dirent direct
195# if HAVE_SYS_NDIR_H
196# include <sys/ndir.h>
197# endif
198# if HAVE_SYS_DIR_H
199# include <sys/dir.h>
200# endif
201# if HAVE_NDIR_H
202# include <ndir.h>
203# endif
204#endif
205
206#ifdef HAVE_COMPAT_H
207#include <compat.h>
208#endif
209
210
f0fca04e
AT
211#define BOOL int
212
c627d613
AT
213#ifndef uchar
214#define uchar unsigned char
215#endif
216
debb4505
AT
217#if HAVE_UNSIGNED_CHAR
218#define schar signed char
219#else
220#define schar char
221#endif
222
c627d613
AT
223#ifndef int32
224#if (SIZEOF_INT == 4)
225#define int32 int
226#elif (SIZEOF_LONG == 4)
227#define int32 long
228#elif (SIZEOF_SHORT == 4)
229#define int32 short
8de330a3
AT
230#else
231/* I hope this works */
232#define int32 int
f3737e06 233#define LARGE_INT32
c627d613
AT
234#endif
235#endif
236
237#ifndef uint32
238#define uint32 unsigned int32
239#endif
240
bcacc18b
AT
241#if HAVE_OFF64_T
242#define OFF_T off64_t
243#define STRUCT_STAT struct stat64
244#else
245#define OFF_T off_t
246#define STRUCT_STAT struct stat
247#endif
248
249#if HAVE_OFF64_T
250#define int64 off64_t
251#elif (SIZEOF_LONG == 8)
3bee6733
AT
252#define int64 long
253#elif (SIZEOF_INT == 8)
254#define int64 int
255#elif HAVE_LONGLONG
71c46176
AT
256#define int64 long long
257#else
258#define int64 off_t
3bee6733 259#define NO_INT64
71c46176 260#endif
c627d613 261
c29ee43d
AT
262#if HAVE_SHORT_INO_T
263#define INO_T uint32
264#else
265#define INO_T ino_t
266#endif
267
c627d613
AT
268#ifndef MIN
269#define MIN(a,b) ((a)<(b)?(a):(b))
270#endif
271
272#ifndef MAX
273#define MAX(a,b) ((a)>(b)?(a):(b))
274#endif
275
d41c7d02
DD
276#ifndef MAXHOSTNAMELEN
277#define MAXHOSTNAMELEN 256
278#endif
279
c627d613 280/* the length of the md4 checksum */
ebb0a6f6 281#define MD4_SUM_LENGTH 16
c627d613
AT
282#define SUM_LENGTH 16
283
284#ifndef MAXPATHLEN
285#define MAXPATHLEN 1024
286#endif
287
0473e2a1
AT
288#ifndef INADDR_NONE
289#define INADDR_NONE 0xffffffff
290#endif
291
c627d613 292struct file_struct {
3333ffbd 293 unsigned flags;
3ec4dd97 294 time_t modtime;
bcacc18b 295 OFF_T length;
3ec4dd97 296 mode_t mode;
c29ee43d 297 INO_T inode;
3ec4dd97
AT
298 dev_t dev;
299 dev_t rdev;
300 uid_t uid;
301 gid_t gid;
302 char *basename;
303 char *dirname;
304 char *basedir;
305 char *link;
2d0bb8eb 306 char *sum;
c627d613
AT
307};
308
4440b8aa 309
c627d613 310struct file_list {
a800434a
AT
311 int count;
312 int malloced;
313 struct file_struct **files;
c627d613
AT
314};
315
316struct sum_buf {
c29ee43d
AT
317 OFF_T offset; /* offset in file of this chunk */
318 int len; /* length of chunk of file */
319 int i; /* index of this chunk */
320 uint32 sum1; /* simple checksum */
321 char sum2[SUM_LENGTH]; /* checksum */
c627d613
AT
322};
323
324struct sum_struct {
bcacc18b 325 OFF_T flength; /* total file length */
c627d613
AT
326 int count; /* how many chunks */
327 int remainder; /* flength % block_length */
328 int n; /* block_length */
329 struct sum_buf *sums; /* points to info for each chunk */
330};
331
c6e7fcb4 332struct map_struct {
4440b8aa 333 char *p;
0b910560 334 int fd,p_size,p_len;
4440b8aa 335 OFF_T file_size, p_offset, p_fd_offset;
c6e7fcb4 336};
c627d613 337
2b6b4d53
AT
338struct exclude_struct {
339 char *orig;
340 char *pattern;
341 int regular_exp;
a8b9d4ed 342 int fnmatch_flags;
2b6b4d53
AT
343 int include;
344 int directory;
345 int local;
346};
347
a800434a
AT
348struct stats {
349 int64 total_size;
350 int64 total_transferred_size;
351 int64 total_written;
352 int64 total_read;
353 int64 literal_data;
354 int64 matched_data;
355 int flist_size;
356 int num_files;
357 int num_transferred_files;
358};
359
2b6b4d53 360
3b3a2fbc
AT
361/* we need this function because of the silly way in which duplicate
362 entries are handled in the file lists - we can't change this
363 without breaking existing versions */
71c46176 364static inline int flist_up(struct file_list *flist, int i)
3b3a2fbc 365{
3ec4dd97 366 while (!flist->files[i]->basename) i++;
3b3a2fbc
AT
367 return i;
368}
369
c627d613
AT
370#include "byteorder.h"
371#include "version.h"
372#include "proto.h"
8de330a3 373#include "lib/mdfour.h"
c627d613
AT
374
375#if !HAVE_STRERROR
376extern char *sys_errlist[];
377#define strerror(i) sys_errlist[i]
378#endif
379
380#ifndef HAVE_STRCHR
381# define strchr index
382# define strrchr rindex
383#endif
384
c627d613
AT
385#ifndef HAVE_ERRNO_DECL
386extern int errno;
387#endif
388
cbbe4892 389#define SUPPORT_LINKS HAVE_READLINK
dc5ddbcc 390#define SUPPORT_HARD_LINKS HAVE_LINK
c627d613 391
8bf73749
AT
392#ifndef HAVE_LCHOWN
393#define lchown chown
394#endif
395
ac1eb754 396#define SIGNAL_CAST (RETSIGTYPE (*)())
720b47f2
AT
397
398#ifndef EWOULDBLOCK
399#define EWOULDBLOCK EAGAIN
400#endif
182dca5c 401
7b8356d0
AT
402#ifndef STDIN_FILENO
403#define STDIN_FILENO 0
404#endif
405
406#ifndef STDOUT_FILENO
407#define STDOUT_FILENO 1
408#endif
409
410#ifndef STDERR_FILENO
411#define STDERR_FILENO 2
412#endif
413
414#ifndef S_IWUSR
415#define S_IWUSR 0200
416#endif
417
b280a1f4
AT
418#ifndef _S_IFMT
419#define _S_IFMT 0170000
420#endif
421
422#ifndef _S_IFLNK
423#define _S_IFLNK 0120000
424#endif
425
426#ifndef S_ISLNK
427#define S_ISLNK(mode) (((mode) & (_S_IFMT)) == (_S_IFLNK))
428#endif
429
1e9f155a
AT
430#ifndef S_ISBLK
431#define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
432#endif
433
434#ifndef S_ISCHR
435#define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
436#endif
437
a0b65b18
AT
438#ifndef S_ISSOCK
439#ifdef _S_IFSOCK
440#define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
441#else
442#define S_ISSOCK(mode) (0)
443#endif
444#endif
445
446#ifndef S_ISFIFO
447#ifdef _S_IFIFO
448#define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
449#else
450#define S_ISFIFO(mode) (0)
451#endif
452#endif
453
1e9f155a
AT
454#ifndef S_ISDIR
455#define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
456#endif
457
458#ifndef S_ISREG
459#define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
460#endif
461
a0b65b18
AT
462
463#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) || S_ISFIFO(mode))
7bec6a5c 464
972a3619
DD
465#ifndef ACCESSPERMS
466#define ACCESSPERMS 0777
467#endif
5afd8aed
DD
468/* Initial mask on permissions given to temporary files. Mask off setuid
469 bits and group access because of potential race-condition security
470 holes, and mask other access because mode 707 is bizarre */
972a3619 471#define INITACCESSPERMS 0700
e08bfe12
AT
472
473/* handler for null strings in printf format */
474#define NS(s) ((s)?(s):"<NULL>")
475
476/* use magic gcc attributes to catch format errors */
477 void rprintf(int , const char *, ...)
478#ifdef __GNUC__
479 __attribute__ ((format (printf, 2, 3)))
480#endif
481;
7b3d4257
AT
482
483#ifdef REPLACE_INET_NTOA
484#define inet_ntoa rep_inet_ntoa
485#endif
5a788ade
AT
486
487
488#ifndef HAVE_STRLCPY
489size_t strlcpy(char *d, const char *s, size_t bufsize);
490#endif
491
492#ifndef HAVE_STRLCAT
493size_t strlcat(char *d, const char *s, size_t bufsize);
494#endif
495
a9766ef1 496#define exit_cleanup(code) _exit_cleanup(code, __FILE__, __LINE__)