Define _LARGE_FILES to turn on LFS support on AIX (and some others?).
[rsync/rsync.git] / rsync.h
... / ...
CommitLineData
1/*
2 Copyright (C) by Andrew Tridgell 1996, 2000
3 Copyright (C) Paul Mackerras 1996
4 Copyright (C) 2001 by Martin Pool <mbp@samba.org>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#define False 0
22#define True 1
23
24#define BLOCK_SIZE 700
25#define RSYNC_RSH_ENV "RSYNC_RSH"
26
27#define RSYNC_NAME "rsync"
28#define RSYNCD_CONF "/etc/rsyncd.conf"
29
30#define DEFAULT_LOCK_FILE "/var/run/rsyncd.lock"
31#define URL_PREFIX "rsync://"
32
33#define BACKUP_SUFFIX "~"
34
35/* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is
36 incompatible with older versions :-( */
37#define CHAR_OFFSET 0
38
39
40#define FLAG_DELETE (1<<0)
41#define SAME_MODE (1<<1)
42#define SAME_RDEV (1<<2)
43#define SAME_UID (1<<3)
44#define SAME_GID (1<<4)
45#define SAME_DIR (1<<5)
46#define SAME_NAME SAME_DIR
47#define LONG_NAME (1<<6)
48#define SAME_TIME (1<<7)
49
50/* update this if you make incompatible changes */
51#define PROTOCOL_VERSION 24
52#define MIN_PROTOCOL_VERSION 15
53#define MAX_PROTOCOL_VERSION 30
54
55#define RSYNC_PORT 873
56
57#define SPARSE_WRITE_SIZE (1024)
58#define WRITE_SIZE (32*1024)
59#define CHUNK_SIZE (32*1024)
60#define MAX_MAP_SIZE (256*1024)
61#define IO_BUFFER_SIZE (4092)
62
63#define MAX_ARGS 1000
64
65#define MPLEX_BASE 7
66
67/* Log values. I *think* what these mean is: FLOG goes to the server
68 * logfile; FERROR and FINFO try to end up on the client, with
69 * different levels of filtering. */
70enum logcode {FNONE=0, FERROR=1, FINFO=2, FLOG=3 };
71
72#include "errcode.h"
73
74#include "config.h"
75
76#if HAVE_REMSH
77#define RSYNC_RSH "remsh"
78#else
79#define RSYNC_RSH "rsh"
80#endif
81
82/* This tries to turn on large file support on some Unix platforms,
83 * making off_t be a 64-bit type, and so on.
84 *
85 * http://www.rs6000.ibm.com/doc_link/en_US/a_doc_lib/aixprggd/genprogc/prg_lrg_files.htm
86 */
87#define _LARGE_FILES 1
88
89#include <sys/types.h>
90
91#ifdef HAVE_UNISTD_H
92#include <unistd.h>
93#endif
94#include <stdio.h>
95#include <stddef.h>
96
97#ifdef HAVE_SYS_PARAM_H
98#include <sys/param.h>
99#endif
100
101#ifdef HAVE_STDLIB_H
102#include <stdlib.h>
103#endif
104
105#ifdef HAVE_SYS_SOCKET_H
106#include <sys/socket.h>
107#endif
108
109#ifdef HAVE_STRING_H
110#include <string.h>
111#endif
112
113#ifdef HAVE_MALLOC_H
114#include <malloc.h>
115#endif
116
117#ifdef TIME_WITH_SYS_TIME
118#include <sys/time.h>
119#include <time.h>
120#else
121#ifdef HAVE_SYS_TIME_H
122#include <sys/time.h>
123#else
124#include <time.h>
125#endif
126#endif
127
128#ifdef HAVE_FCNTL_H
129#include <fcntl.h>
130#else
131#ifdef HAVE_SYS_FCNTL_H
132#include <sys/fcntl.h>
133#endif
134#endif
135
136#include <sys/stat.h>
137
138#ifdef HAVE_SYS_IOCTL_H
139#include <sys/ioctl.h>
140#endif
141
142#ifdef HAVE_SYS_FILIO_H
143#include <sys/filio.h>
144#endif
145
146#include <signal.h>
147#ifdef HAVE_SYS_WAIT_H
148#include <sys/wait.h>
149#endif
150#ifdef HAVE_CTYPE_H
151#include <ctype.h>
152#endif
153#ifdef HAVE_GRP_H
154#include <grp.h>
155#endif
156#include <errno.h>
157
158#ifdef HAVE_UTIME_H
159#include <utime.h>
160#endif
161
162#ifdef HAVE_SYS_SELECT_H
163#include <sys/select.h>
164#endif
165
166#ifdef HAVE_SYS_MODE_H
167/* apparently AIX needs this for S_ISLNK */
168#ifndef S_ISLNK
169#include <sys/mode.h>
170#endif
171#endif
172
173#ifdef HAVE_FNMATCH
174#include <fnmatch.h>
175#else
176#include "lib/fnmatch.h"
177#endif
178
179#ifdef HAVE_GLOB_H
180#include <glob.h>
181#endif
182
183/* these are needed for the uid/gid mapping code */
184#include <pwd.h>
185#include <grp.h>
186
187#include <stdarg.h>
188#include <netinet/in.h>
189#include <arpa/inet.h>
190#include <netdb.h>
191#include <syslog.h>
192#include <sys/file.h>
193
194#if HAVE_DIRENT_H
195# include <dirent.h>
196#else
197# define dirent direct
198# if HAVE_SYS_NDIR_H
199# include <sys/ndir.h>
200# endif
201# if HAVE_SYS_DIR_H
202# include <sys/dir.h>
203# endif
204# if HAVE_NDIR_H
205# include <ndir.h>
206# endif
207#endif
208
209#ifdef HAVE_COMPAT_H
210#include <compat.h>
211#endif
212
213
214#define BOOL int
215
216#ifndef uchar
217#define uchar unsigned char
218#endif
219
220#if HAVE_UNSIGNED_CHAR
221#define schar signed char
222#else
223#define schar char
224#endif
225
226#ifndef int32
227#if (SIZEOF_INT == 4)
228#define int32 int
229#elif (SIZEOF_LONG == 4)
230#define int32 long
231#elif (SIZEOF_SHORT == 4)
232#define int32 short
233#else
234/* I hope this works */
235#define int32 int
236#define LARGE_INT32
237#endif
238#endif
239
240#ifndef uint32
241#define uint32 unsigned int32
242#endif
243
244#if HAVE_OFF64_T
245#define OFF_T off64_t
246#define STRUCT_STAT struct stat64
247#else
248#define OFF_T off_t
249#define STRUCT_STAT struct stat
250#endif
251
252#if HAVE_OFF64_T
253#define int64 off64_t
254#elif (SIZEOF_LONG == 8)
255#define int64 long
256#elif (SIZEOF_INT == 8)
257#define int64 int
258#elif HAVE_LONGLONG
259#define int64 long long
260#else
261#define int64 off_t
262#define NO_INT64
263#endif
264
265#if HAVE_SHORT_INO_T
266#define INO_T uint32
267#else
268#define INO_T ino_t
269#endif
270
271#ifndef MIN
272#define MIN(a,b) ((a)<(b)?(a):(b))
273#endif
274
275#ifndef MAX
276#define MAX(a,b) ((a)>(b)?(a):(b))
277#endif
278
279#ifndef MAXHOSTNAMELEN
280#define MAXHOSTNAMELEN 256
281#endif
282
283/* the length of the md4 checksum */
284#define MD4_SUM_LENGTH 16
285#define SUM_LENGTH 16
286
287#ifndef MAXPATHLEN
288#define MAXPATHLEN 1024
289#endif
290
291#ifndef INADDR_NONE
292#define INADDR_NONE 0xffffffff
293#endif
294
295struct file_struct {
296 unsigned flags;
297 time_t modtime;
298 OFF_T length;
299 mode_t mode;
300 INO_T inode;
301 dev_t dev;
302 dev_t rdev;
303 uid_t uid;
304 gid_t gid;
305 char *basename;
306 char *dirname;
307 char *basedir;
308 char *link;
309 char *sum;
310};
311
312
313#define ARENA_SIZE (32 * 1024)
314
315struct string_area {
316 char *base;
317 char *end;
318 char *current;
319 struct string_area *next;
320};
321
322struct file_list {
323 int count;
324 int malloced;
325 struct file_struct **files;
326 struct string_area *string_area;
327};
328
329struct sum_buf {
330 OFF_T offset; /* offset in file of this chunk */
331 int len; /* length of chunk of file */
332 int i; /* index of this chunk */
333 uint32 sum1; /* simple checksum */
334 char sum2[SUM_LENGTH]; /* checksum */
335};
336
337struct sum_struct {
338 OFF_T flength; /* total file length */
339 int count; /* how many chunks */
340 int remainder; /* flength % block_length */
341 int n; /* block_length */
342 struct sum_buf *sums; /* points to info for each chunk */
343};
344
345struct map_struct {
346 char *p;
347 int fd,p_size,p_len;
348 OFF_T file_size, p_offset, p_fd_offset;
349};
350
351struct exclude_struct {
352 char *pattern;
353 int regular_exp;
354 int fnmatch_flags;
355 int include;
356 int directory;
357 int local;
358};
359
360struct stats {
361 int64 total_size;
362 int64 total_transferred_size;
363 int64 total_written;
364 int64 total_read;
365 int64 literal_data;
366 int64 matched_data;
367 int flist_size;
368 int num_files;
369 int num_transferred_files;
370};
371
372
373/* we need this function because of the silly way in which duplicate
374 entries are handled in the file lists - we can't change this
375 without breaking existing versions */
376static inline int flist_up(struct file_list *flist, int i)
377{
378 while (!flist->files[i]->basename) i++;
379 return i;
380}
381
382#include "byteorder.h"
383#include "version.h"
384#include "proto.h"
385#include "lib/mdfour.h"
386
387#if !HAVE_STRERROR
388extern char *sys_errlist[];
389#define strerror(i) sys_errlist[i]
390#endif
391
392#ifndef HAVE_STRCHR
393# define strchr index
394# define strrchr rindex
395#endif
396
397#ifndef HAVE_ERRNO_DECL
398extern int errno;
399#endif
400
401#define SUPPORT_LINKS HAVE_READLINK
402#define SUPPORT_HARD_LINKS HAVE_LINK
403
404#ifndef HAVE_LCHOWN
405#define lchown chown
406#endif
407
408#define SIGNAL_CAST (RETSIGTYPE (*)())
409
410#ifndef EWOULDBLOCK
411#define EWOULDBLOCK EAGAIN
412#endif
413
414#ifndef STDIN_FILENO
415#define STDIN_FILENO 0
416#endif
417
418#ifndef STDOUT_FILENO
419#define STDOUT_FILENO 1
420#endif
421
422#ifndef STDERR_FILENO
423#define STDERR_FILENO 2
424#endif
425
426#ifndef S_IWUSR
427#define S_IWUSR 0200
428#endif
429
430#ifndef _S_IFMT
431#define _S_IFMT 0170000
432#endif
433
434#ifndef _S_IFLNK
435#define _S_IFLNK 0120000
436#endif
437
438#ifndef S_ISLNK
439#define S_ISLNK(mode) (((mode) & (_S_IFMT)) == (_S_IFLNK))
440#endif
441
442#ifndef S_ISBLK
443#define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
444#endif
445
446#ifndef S_ISCHR
447#define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
448#endif
449
450#ifndef S_ISSOCK
451#ifdef _S_IFSOCK
452#define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
453#else
454#define S_ISSOCK(mode) (0)
455#endif
456#endif
457
458#ifndef S_ISFIFO
459#ifdef _S_IFIFO
460#define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
461#else
462#define S_ISFIFO(mode) (0)
463#endif
464#endif
465
466#ifndef S_ISDIR
467#define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
468#endif
469
470#ifndef S_ISREG
471#define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
472#endif
473
474/* work out what fcntl flag to use for non-blocking */
475#ifdef O_NONBLOCK
476# define NONBLOCK_FLAG O_NONBLOCK
477#elif defined(SYSV)
478# define NONBLOCK_FLAG O_NDELAY
479#else
480# define NONBLOCK_FLAG FNDELAY
481#endif
482
483
484#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) || S_ISFIFO(mode))
485
486#ifndef ACCESSPERMS
487#define ACCESSPERMS 0777
488#endif
489/* Initial mask on permissions given to temporary files. Mask off setuid
490 bits and group access because of potential race-condition security
491 holes, and mask other access because mode 707 is bizarre */
492#define INITACCESSPERMS 0700
493
494/* handler for null strings in printf format */
495#define NS(s) ((s)?(s):"<NULL>")
496
497/* use magic gcc attributes to catch format errors */
498 void rprintf(enum logcode , const char *, ...)
499#ifdef __GNUC__
500 __attribute__ ((format (printf, 2, 3)))
501#endif
502;
503
504/* This is just like rprintf, but it also tries to print some
505 * representation of the error code. Normally errcode = errno. */
506void rsyserr(enum logcode, int, const char *, ...)
507#ifdef __GNUC__
508 __attribute__ ((format (printf, 3, 4)))
509#endif
510 ;
511
512#ifdef REPLACE_INET_NTOA
513#define inet_ntoa rep_inet_ntoa
514#endif
515
516
517#ifndef HAVE_STRLCPY
518size_t strlcpy(char *d, const char *s, size_t bufsize);
519#endif
520
521#ifndef HAVE_STRLCAT
522size_t strlcat(char *d, const char *s, size_t bufsize);
523#endif
524
525#ifndef WEXITSTATUS
526#define WEXITSTATUS(stat) ((int)(((stat)>>8)&0xFF))
527#endif
528
529#define exit_cleanup(code) _exit_cleanup(code, __FILE__, __LINE__)