*** empty log message ***
[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"
22#define RSYNC_RSH "rsh"
23#define RSYNC_NAME "rsync"
24#define BACKUP_SUFFIX "~"
25
4fe159a8
AT
26#define FILE_VALID 1
27#define SAME_MODE (1<<1)
dc5ddbcc 28#define SAME_RDEV (1<<2)
4fe159a8
AT
29#define SAME_UID (1<<3)
30#define SAME_GID (1<<4)
31#define SAME_DIR (1<<5)
32#define SAME_NAME SAME_DIR
33#define LONG_NAME (1<<6)
34#define SAME_TIME (1<<7)
35
c627d613 36/* update this if you make incompatible changes */
aae43eb3 37#define PROTOCOL_VERSION 12
182dca5c 38#define MIN_PROTOCOL_VERSION 10
7bec6a5c 39#define MAX_PROTOCOL_VERSION 20
c627d613 40
dc5ddbcc
AT
41#define SPARSE_WRITE_SIZE (4*1024)
42#define WRITE_SIZE (32*1024)
34ccb63e 43#define CHUNK_SIZE (32*1024)
d9bea2dd 44#define MAX_MAP_SIZE (4*1024*1024)
c627d613 45
58d433ab
AT
46#define BLOCKING_TIMEOUT 10
47
dc5ddbcc
AT
48#define FERROR stderr
49#define FINFO (am_server?stderr:stdout)
7bec6a5c 50
c627d613
AT
51#include "config.h"
52
53#include <sys/types.h>
54#ifdef HAVE_UNISTD_H
55#include <unistd.h>
56#endif
57#include <stdio.h>
58
59#ifdef HAVE_SYS_PARAM_H
60#include <sys/param.h>
61#endif
62
63#ifdef STDC_HEADERS
64# include <stdlib.h>
65# include <string.h>
66#endif
67
68#ifdef HAVE_COMPAT_H
69#include <compat.h>
70#endif
71
72#ifdef HAVE_MALLOC_H
73#include <malloc.h>
74#endif
75
76#ifdef TIME_WITH_SYS_TIME
77#include <sys/time.h>
78#include <time.h>
79#else
80#ifdef HAVE_SYS_TIME_H
81#include <sys/time.h>
82#else
83#include <time.h>
84#endif
85#endif
86
87#ifdef HAVE_FCNTL_H
88#include <fcntl.h>
89#else
90#ifdef HAVE_SYS_FCNTL_H
91#include <sys/fcntl.h>
92#endif
93#endif
94
95#include <sys/stat.h>
96
94481d91
AT
97#ifdef HAVE_SYS_IOCTL_H
98#include <sys/ioctl.h>
99#endif
100
101#ifdef HAVE_SYS_FILIO_H
102#include <sys/filio.h>
103#endif
104
c627d613
AT
105#include <signal.h>
106#ifdef HAVE_SYS_WAIT_H
107#include <sys/wait.h>
108#endif
109#ifdef HAVE_CTYPE_H
110#include <ctype.h>
111#endif
112#ifdef HAVE_GRP_H
113#include <grp.h>
114#endif
115#include <errno.h>
116
7bec6a5c 117#ifdef HAVE_MMAP
c627d613 118#include <sys/mman.h>
7bec6a5c
AT
119#endif
120
c627d613
AT
121#ifdef HAVE_UTIME_H
122#include <utime.h>
123#endif
124
125#ifdef HAVE_FNMATCH
126#include <fnmatch.h>
127#else
128#include "lib/fnmatch.h"
129#endif
130
131#ifdef HAVE_GETOPT_LONG
132#include <getopt.h>
133#else
134#include "lib/getopt.h"
135#endif
136
137
138#ifndef S_ISLNK
139#define S_ISLNK(mode) (((mode) & S_IFLNK) == S_IFLNK)
140#endif
141
142#ifndef uchar
143#define uchar unsigned char
144#endif
145
146#ifndef int32
147#if (SIZEOF_INT == 4)
148#define int32 int
149#elif (SIZEOF_LONG == 4)
150#define int32 long
151#elif (SIZEOF_SHORT == 4)
152#define int32 short
153#endif
154#endif
155
156#ifndef uint32
157#define uint32 unsigned int32
158#endif
159
160
161#ifndef MIN
162#define MIN(a,b) ((a)<(b)?(a):(b))
163#endif
164
165#ifndef MAX
166#define MAX(a,b) ((a)>(b)?(a):(b))
167#endif
168
169/* the length of the md4 checksum */
170#define SUM_LENGTH 16
171
172#ifndef MAXPATHLEN
173#define MAXPATHLEN 1024
174#endif
175
176struct file_struct {
177 time_t modtime;
178 off_t length;
179 mode_t mode;
dc5ddbcc 180 ino_t inode;
c627d613 181 dev_t dev;
dc5ddbcc 182 dev_t rdev;
c627d613
AT
183 uid_t uid;
184 gid_t gid;
185 char *name;
186 char *dir;
187 char *link;
188 char sum[SUM_LENGTH];
189};
190
191struct file_list {
192 int count;
193 int malloced;
194 struct file_struct *files;
195};
196
197struct sum_buf {
198 off_t offset; /* offset in file of this chunk */
199 int len; /* length of chunk of file */
200 int i; /* index of this chunk */
201 uint32 sum1; /* simple checksum */
202 char sum2[SUM_LENGTH]; /* md4 checksum */
203};
204
205struct sum_struct {
206 off_t flength; /* total file length */
207 int count; /* how many chunks */
208 int remainder; /* flength % block_length */
209 int n; /* block_length */
210 struct sum_buf *sums; /* points to info for each chunk */
211};
212
213
214#include "byteorder.h"
215#include "version.h"
216#include "proto.h"
217#include "md4.h"
218
219#if !HAVE_STRERROR
220extern char *sys_errlist[];
221#define strerror(i) sys_errlist[i]
222#endif
223
224#ifndef HAVE_STRCHR
225# define strchr index
226# define strrchr rindex
227#endif
228
229#if HAVE_DIRENT_H
230# include <dirent.h>
231#else
232# define dirent direct
233# if HAVE_SYS_NDIR_H
234# include <sys/ndir.h>
235# endif
236# if HAVE_SYS_DIR_H
237# include <sys/dir.h>
238# endif
239# if HAVE_NDIR_H
240# include <ndir.h>
241# endif
242#endif
243
244#ifndef HAVE_ERRNO_DECL
245extern int errno;
246#endif
247
248#ifndef HAVE_BCOPY
249#define bcopy(src,dest,n) memcpy(dest,src,n)
250#endif
251
252#ifndef HAVE_BZERO
253#define bzero(buf,n) memset(buf,0,n)
254#endif
255
256#define SUPPORT_LINKS (HAVE_READLINK && defined(S_ISLNK))
dc5ddbcc 257#define SUPPORT_HARD_LINKS HAVE_LINK
c627d613 258
7bec6a5c
AT
259#ifndef S_ISLNK
260#define S_ISLNK(x) 0
261#endif
262
c627d613
AT
263#if !SUPPORT_LINKS
264#define lstat stat
265#endif
ac1eb754
AT
266
267#define SIGNAL_CAST (RETSIGTYPE (*)())
720b47f2
AT
268
269#ifndef EWOULDBLOCK
270#define EWOULDBLOCK EAGAIN
271#endif
182dca5c
AT
272
273#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode))
7bec6a5c 274