added --size-only option. Useful when starting to use rsync after a
[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;
342 int include;
343 int directory;
344 int local;
345};
346
a800434a
AT
347struct stats {
348 int64 total_size;
349 int64 total_transferred_size;
350 int64 total_written;
351 int64 total_read;
352 int64 literal_data;
353 int64 matched_data;
354 int flist_size;
355 int num_files;
356 int num_transferred_files;
357};
358
2b6b4d53 359
3b3a2fbc
AT
360/* we need this function because of the silly way in which duplicate
361 entries are handled in the file lists - we can't change this
362 without breaking existing versions */
71c46176 363static inline int flist_up(struct file_list *flist, int i)
3b3a2fbc 364{
3ec4dd97 365 while (!flist->files[i]->basename) i++;
3b3a2fbc
AT
366 return i;
367}
368
c627d613
AT
369#include "byteorder.h"
370#include "version.h"
371#include "proto.h"
8de330a3 372#include "lib/mdfour.h"
c627d613
AT
373
374#if !HAVE_STRERROR
375extern char *sys_errlist[];
376#define strerror(i) sys_errlist[i]
377#endif
378
379#ifndef HAVE_STRCHR
380# define strchr index
381# define strrchr rindex
382#endif
383
c627d613
AT
384#ifndef HAVE_ERRNO_DECL
385extern int errno;
386#endif
387
cbbe4892 388#define SUPPORT_LINKS HAVE_READLINK
dc5ddbcc 389#define SUPPORT_HARD_LINKS HAVE_LINK
c627d613 390
8bf73749
AT
391#ifndef HAVE_LCHOWN
392#define lchown chown
393#endif
394
ac1eb754 395#define SIGNAL_CAST (RETSIGTYPE (*)())
720b47f2
AT
396
397#ifndef EWOULDBLOCK
398#define EWOULDBLOCK EAGAIN
399#endif
182dca5c 400
7b8356d0
AT
401#ifndef STDIN_FILENO
402#define STDIN_FILENO 0
403#endif
404
405#ifndef STDOUT_FILENO
406#define STDOUT_FILENO 1
407#endif
408
409#ifndef STDERR_FILENO
410#define STDERR_FILENO 2
411#endif
412
413#ifndef S_IWUSR
414#define S_IWUSR 0200
415#endif
416
b280a1f4
AT
417#ifndef _S_IFMT
418#define _S_IFMT 0170000
419#endif
420
421#ifndef _S_IFLNK
422#define _S_IFLNK 0120000
423#endif
424
425#ifndef S_ISLNK
426#define S_ISLNK(mode) (((mode) & (_S_IFMT)) == (_S_IFLNK))
427#endif
428
1e9f155a
AT
429#ifndef S_ISBLK
430#define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
431#endif
432
433#ifndef S_ISCHR
434#define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
435#endif
436
a0b65b18
AT
437#ifndef S_ISSOCK
438#ifdef _S_IFSOCK
439#define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
440#else
441#define S_ISSOCK(mode) (0)
442#endif
443#endif
444
445#ifndef S_ISFIFO
446#ifdef _S_IFIFO
447#define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
448#else
449#define S_ISFIFO(mode) (0)
450#endif
451#endif
452
1e9f155a
AT
453#ifndef S_ISDIR
454#define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
455#endif
456
457#ifndef S_ISREG
458#define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
459#endif
460
a0b65b18
AT
461
462#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) || S_ISFIFO(mode))
7bec6a5c 463
22b19332
AT
464#ifndef ACCESSPERMS
465#define ACCESSPERMS 0777
466#endif
e08bfe12
AT
467
468/* handler for null strings in printf format */
469#define NS(s) ((s)?(s):"<NULL>")
470
471/* use magic gcc attributes to catch format errors */
472 void rprintf(int , const char *, ...)
473#ifdef __GNUC__
474 __attribute__ ((format (printf, 2, 3)))
475#endif
476;
7b3d4257
AT
477
478#ifdef REPLACE_INET_NTOA
479#define inet_ntoa rep_inet_ntoa
480#endif
5a788ade
AT
481
482
483#ifndef HAVE_STRLCPY
484size_t strlcpy(char *d, const char *s, size_t bufsize);
485#endif
486
487#ifndef HAVE_STRLCAT
488size_t strlcat(char *d, const char *s, size_t bufsize);
489#endif
490
a9766ef1 491#define exit_cleanup(code) _exit_cleanup(code, __FILE__, __LINE__)