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