rsync.h

説明を見る。
00001 /*
00002    Copyright (C) by Andrew Tridgell 1996, 2000
00003    Copyright (C) Paul Mackerras 1996
00004    Copyright (C) 2001, 2002 by Martin Pool <mbp@samba.org>
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 
00022 #define False 0
00023 #define True 1
00024 
00025 #define BLOCK_SIZE 700
00026 #define RSYNC_RSH_ENV "RSYNC_RSH"
00027 #define RSYNC_RSH_IO_ENV "RSYNC_RSH_IO"
00028 
00029 #define RSYNC_NAME "rsync"
00030 /* RSYNCD_SYSCONF is now set in config.h */
00031 #define RSYNCD_USERCONF "rsyncd.conf"
00032 
00033 #define DEFAULT_LOCK_FILE "/var/run/rsyncd.lock"
00034 #define URL_PREFIX "rsync://"
00035 
00036 #define BACKUP_SUFFIX "~"
00037 
00038 /* a non-zero CHAR_OFFSET makes the rolling sum stronger, but is
00039    incompatible with older versions :-( */
00040 #define CHAR_OFFSET 0
00041 
00042 /* These flags are only used during the flist transfer. */
00043 
00044 #define XMIT_TOP_DIR (1<<0)
00045 #define XMIT_SAME_MODE (1<<1)
00046 #define XMIT_EXTENDED_FLAGS (1<<2)
00047 #define XMIT_SAME_RDEV_pre28 XMIT_EXTENDED_FLAGS /* Only in protocols < 28 */
00048 #define XMIT_SAME_UID (1<<3)
00049 #define XMIT_SAME_GID (1<<4)
00050 #define XMIT_SAME_NAME (1<<5)
00051 #define XMIT_LONG_NAME (1<<6)
00052 #define XMIT_SAME_TIME (1<<7)
00053 #define XMIT_SAME_RDEV_MAJOR (1<<8)
00054 #define XMIT_HAS_IDEV_DATA (1<<9)
00055 #define XMIT_SAME_DEV (1<<10)
00056 #define XMIT_RDEV_MINOR_IS_SMALL (1<<11)
00057 
00058 /* These flags are used in the live flist data. */
00059 
00060 #define FLAG_TOP_DIR (1<<0)
00061 #define FLAG_SENT (1<<1)        /* sender */
00062 #define FLAG_HLINK_EOL (1<<1)   /* receiver/generator */
00063 #define FLAG_MOUNT_POINT (1<<2) /* sender/generator */
00064 #define FLAG_DEL_HERE (1<<3)    /* receiver/generator */
00065 #define FLAG_HLINK_TOL (1<<4)   /* receiver/generator */
00066 #define FLAG_NO_FUZZY (1<<5)    /* generator */
00067 
00068 /* update this if you make incompatible changes */
00069 #define PROTOCOL_VERSION 29
00070 
00071 /* We refuse to interoperate with versions that are not in this range.
00072  * Note that we assume we'll work with later versions: the onus is on
00073  * people writing them to make sure that they don't send us anything
00074  * we won't understand.
00075  *
00076  * Interoperation with old but supported protocol versions
00077  * should cause a warning to be printed.  At a future date
00078  * the old protocol will become the minimum and
00079  * compatibility code removed.
00080  *
00081  * There are two possible explanations for the limit at
00082  * MAX_PROTOCOL_VERSION: either to allow new major-rev versions that
00083  * do not interoperate with us, and (more likely) so that we can
00084  * detect an attempt to connect rsync to a non-rsync server, which is
00085  * unlikely to begin by sending a byte between MIN_PROTOCL_VERSION and
00086  * MAX_PROTOCOL_VERSION. */
00087 
00088 #define MIN_PROTOCOL_VERSION 20
00089 #define OLD_PROTOCOL_VERSION 25
00090 #define MAX_PROTOCOL_VERSION 40
00091 
00092 #define RSYNC_PORT 873
00093 
00094 #define SPARSE_WRITE_SIZE (1024)
00095 #define WRITE_SIZE (32*1024)
00096 #define CHUNK_SIZE (32*1024)
00097 #define MAX_MAP_SIZE (256*1024)
00098 #define IO_BUFFER_SIZE (4092)
00099 #define MAX_BLOCK_SIZE ((int32)1 << 29)
00100 
00101 #define IOERR_GENERAL   (1<<0) /* For backward compatibility, this must == 1 */
00102 #define IOERR_VANISHED  (1<<1)
00103 #define IOERR_DEL_LIMIT (1<<2)
00104 
00105 #define MAX_ARGS 1000
00106 #define MAX_BASIS_DIRS 20
00107 #define MAX_SERVER_ARGS (MAX_BASIS_DIRS*2 + 100)
00108 
00109 #define MPLEX_BASE 7
00110 
00111 #define NO_FILTERS      0
00112 #define SERVER_FILTERS  1
00113 #define ALL_FILTERS     2
00114 
00115 #define XFLG_FATAL_ERRORS       (1<<0)
00116 #define XFLG_OLD_PREFIXES       (1<<1)
00117 #define XFLG_ANCHORED2ABS       (1<<2)
00118 #define XFLG_ABS_IF_SLASH       (1<<3)
00119 
00120 #define ATTRS_REPORT            (1<<0)
00121 #define ATTRS_SKIP_MTIME        (1<<1)
00122 
00123 #define FULL_FLUSH      1
00124 #define NORMAL_FLUSH    0
00125 
00126 #define PDIR_CREATE     1
00127 #define PDIR_DELETE     0
00128 
00129 /* Note: 0x00 - 0x7F are used for basis_dir[] indexes! */
00130 #define FNAMECMP_BASIS_DIR_LOW  0x00 /* Must remain 0! */
00131 #define FNAMECMP_BASIS_DIR_HIGH 0x7F
00132 #define FNAMECMP_FNAME          0x80
00133 #define FNAMECMP_PARTIAL_DIR    0x81
00134 #define FNAMECMP_BACKUP         0x82
00135 #define FNAMECMP_FUZZY          0x83
00136 
00137 /* For use by the itemize_changes code */
00138 #define ITEM_REPORT_ATIME (1<<0)
00139 #define ITEM_REPORT_CHECKSUM (1<<1)
00140 #define ITEM_REPORT_SIZE (1<<2)
00141 #define ITEM_REPORT_TIME (1<<3)
00142 #define ITEM_REPORT_PERMS (1<<4)
00143 #define ITEM_REPORT_OWNER (1<<5)
00144 #define ITEM_REPORT_GROUP (1<<6)
00145 #define ITEM_REPORT_ACL (1<<7)
00146 #define ITEM_REPORT_XATTR (1<<8)
00147 #define ITEM_BASIS_TYPE_FOLLOWS (1<<11)
00148 #define ITEM_XNAME_FOLLOWS (1<<12)
00149 #define ITEM_IS_NEW (1<<13)
00150 #define ITEM_LOCAL_CHANGE (1<<14)
00151 #define ITEM_TRANSFER (1<<15)
00152 /* These are outside the range of the transmitted flags. */
00153 #define ITEM_MISSING_DATA (1<<16)          /* used by log_formatted() */
00154 #define ITEM_DELETED (1<<17)               /* used by log_formatted() */
00155 
00156 #define SIGNIFICANT_ITEM_FLAGS (~(\
00157         ITEM_BASIS_TYPE_FOLLOWS | ITEM_XNAME_FOLLOWS | ITEM_LOCAL_CHANGE))
00158 
00159 
00160 /* Log-message categories.  Only FERROR and FINFO get sent over the socket.
00161  * FLOG and FCLIENT are only used on the daemon side for custom logging,
00162  * while FNAME is only used on the client side. */
00163 enum logcode { FERROR=1, FINFO=2, FLOG=3, FCLIENT=4, FNAME=5, FSOCKERR=6 };
00164 
00165 /* Messages types that are sent over the message channel.  The logcode
00166  * values must all be present here with identical numbers. */
00167 enum msgcode {
00168         MSG_DATA=0,     /* raw data on the multiplexed stream */
00169         MSG_ERROR=FERROR, MSG_INFO=FINFO, /* remote logging */
00170         MSG_LOG=FLOG, MSG_SOCKERR=FSOCKERR, /* sibling logging */
00171         MSG_REDO=9,     /* reprocess indicated flist index */
00172         MSG_SUCCESS=100,/* successfully updated indicated flist index */
00173         MSG_DELETED=101,/* successfully deleted a file on receiving side */
00174         MSG_DONE=86     /* current phase is done */
00175 };
00176 
00177 #include "errcode.h"
00178 
00179 #include "config.h"
00180 
00181 /* The default RSYNC_RSH is always set in config.h. */
00182 
00183 #include <stdio.h>
00184 #ifdef HAVE_SYS_TYPES_H
00185 # include <sys/types.h>
00186 #endif
00187 #ifdef HAVE_SYS_STAT_H
00188 # include <sys/stat.h>
00189 #endif
00190 #ifdef STDC_HEADERS
00191 # include <stdlib.h>
00192 # include <stddef.h>
00193 #else
00194 # ifdef HAVE_STDLIB_H
00195 #  include <stdlib.h>
00196 # endif
00197 #endif
00198 #ifdef HAVE_STRING_H
00199 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
00200 #  include <memory.h>
00201 # endif
00202 # include <string.h>
00203 #endif
00204 #ifdef HAVE_STRINGS_H
00205 # include <strings.h>
00206 #endif
00207 #ifdef HAVE_UNISTD_H
00208 # include <unistd.h>
00209 #endif
00210 
00211 #ifdef HAVE_SYS_PARAM_H
00212 #include <sys/param.h>
00213 #endif
00214 
00215 #if defined HAVE_MALLOC_H && (defined HAVE_MALLINFO || !defined HAVE_STDLIB_H)
00216 #include <malloc.h>
00217 #endif
00218 
00219 #ifdef HAVE_SYS_SOCKET_H
00220 #include <sys/socket.h>
00221 #endif
00222 
00223 #ifdef TIME_WITH_SYS_TIME
00224 #include <sys/time.h>
00225 #include <time.h>
00226 #else
00227 #ifdef HAVE_SYS_TIME_H
00228 #include <sys/time.h>
00229 #else
00230 #include <time.h>
00231 #endif
00232 #endif
00233 
00234 #ifdef HAVE_FCNTL_H
00235 #include <fcntl.h>
00236 #else
00237 #ifdef HAVE_SYS_FCNTL_H
00238 #include <sys/fcntl.h>
00239 #endif
00240 #endif
00241 
00242 #ifdef HAVE_SYS_IOCTL_H
00243 #include <sys/ioctl.h>
00244 #endif
00245 
00246 #ifdef HAVE_SYS_FILIO_H
00247 #include <sys/filio.h>
00248 #endif
00249 
00250 #include <signal.h>
00251 #ifdef HAVE_SYS_WAIT_H
00252 #include <sys/wait.h>
00253 #endif
00254 #ifdef HAVE_CTYPE_H
00255 #include <ctype.h>
00256 #endif
00257 #ifdef HAVE_GRP_H
00258 #include <grp.h>
00259 #endif
00260 #include <errno.h>
00261 
00262 #ifdef HAVE_UTIME_H
00263 #include <utime.h>
00264 #endif
00265 
00266 #ifdef HAVE_SYS_SELECT_H
00267 #include <sys/select.h>
00268 #endif
00269 
00270 #ifdef HAVE_SYS_MODE_H
00271 /* apparently AIX needs this for S_ISLNK */
00272 #ifndef S_ISLNK
00273 #include <sys/mode.h>
00274 #endif
00275 #endif
00276 
00277 #ifdef HAVE_GLOB_H
00278 #include <glob.h>
00279 #endif
00280 
00281 /* these are needed for the uid/gid mapping code */
00282 #include <pwd.h>
00283 #include <grp.h>
00284 
00285 #include <stdarg.h>
00286 #include <netinet/in.h>
00287 #include <arpa/inet.h>
00288 #include <netdb.h>
00289 #include <syslog.h>
00290 #include <sys/file.h>
00291 
00292 #ifdef HAVE_DIRENT_H
00293 # include <dirent.h>
00294 #else
00295 # define dirent direct
00296 # ifdef HAVE_SYS_NDIR_H
00297 #  include <sys/ndir.h>
00298 # endif
00299 # ifdef HAVE_SYS_DIR_H
00300 #  include <sys/dir.h>
00301 # endif
00302 # ifdef HAVE_NDIR_H
00303 #  include <ndir.h>
00304 # endif
00305 #endif
00306 
00307 #ifdef MAJOR_IN_MKDEV
00308 #include <sys/mkdev.h>
00309 # if !defined makedev && (defined mkdev || defined _WIN32 || defined __WIN32__)
00310 #  define makedev mkdev
00311 # endif
00312 #elif defined MAJOR_IN_SYSMACROS
00313 #include <sys/sysmacros.h>
00314 #endif
00315 
00316 #ifdef HAVE_COMPAT_H
00317 #include <compat.h>
00318 #endif
00319 
00320 #ifdef HAVE_LIMITS_H
00321 # include <limits.h>
00322 #endif
00323 
00324 #include <assert.h>
00325 
00326 #include "lib/pool_alloc.h"
00327 
00328 #define BOOL int
00329 
00330 #ifndef uchar
00331 #define uchar unsigned char
00332 #endif
00333 
00334 #ifdef SIGNED_CHAR_OK
00335 #define schar signed char
00336 #else
00337 #define schar char
00338 #endif
00339 
00340 /* Find a variable that is either exactly 32-bits or longer.
00341  * If some code depends on 32-bit truncation, it will need to
00342  * take special action in a "#if SIZEOF_INT32 > 4" section. */
00343 #ifndef int32
00344 #if SIZEOF_INT == 4
00345 # define int32 int
00346 # define SIZEOF_INT32 4
00347 #elif SIZEOF_LONG == 4
00348 # define int32 long
00349 # define SIZEOF_INT32 4
00350 #elif SIZEOF_SHORT == 4
00351 # define int32 short
00352 # define SIZEOF_INT32 4
00353 #elif SIZEOF_INT > 4
00354 # define int32 int
00355 # define SIZEOF_INT32 SIZEOF_INT
00356 #elif SIZEOF_LONG > 4
00357 # define int32 long
00358 # define SIZEOF_INT32 SIZEOF_LONG
00359 #else
00360 # error Could not find a 32-bit integer variable
00361 #endif
00362 #else
00363 # define SIZEOF_INT32 4
00364 #endif
00365 
00366 #ifndef uint32
00367 #define uint32 unsigned int32
00368 #endif
00369 
00370 #if SIZEOF_OFF_T == 8 || !SIZEOF_OFF64_T || !defined HAVE_STRUCT_STAT64
00371 #define OFF_T off_t
00372 #define STRUCT_STAT struct stat
00373 #else
00374 #define OFF_T off64_t
00375 #define STRUCT_STAT struct stat64
00376 #define USE_STAT64_FUNCS 1
00377 #endif
00378 
00379 /* CAVEAT: on some systems, int64 will really be a 32-bit integer IFF
00380  * that's the maximum size the file system can handle and there is no
00381  * 64-bit type available.  The rsync source must therefore take steps
00382  * to ensure that any code that really requires a 64-bit integer has
00383  * it (e.g. the checksum code uses two 32-bit integers for its 64-bit
00384  * counter). */
00385 #if SIZEOF_OFF64_T == 8
00386 # define int64 off64_t
00387 # define SIZEOF_INT64 8
00388 #elif SIZEOF_LONG == 8
00389 # define int64 long
00390 # define SIZEOF_INT64 8
00391 #elif SIZEOF_INT == 8
00392 # define int64 int
00393 # define SIZEOF_INT64 8
00394 #elif SIZEOF_LONG_LONG == 8
00395 # define int64 long long
00396 # define SIZEOF_INT64 8
00397 #elif SIZEOF_OFF_T == 8
00398 # define int64 off_t
00399 # define SIZEOF_INT64 8
00400 #elif SIZEOF_INT > 8
00401 # define int64 int
00402 # define SIZEOF_INT64 SIZEOF_INT
00403 #elif SIZEOF_LONG > 8
00404 # define int64 long
00405 # define SIZEOF_INT64 SIZEOF_LONG
00406 #elif SIZEOF_LONG_LONG > 8
00407 # define int64 long long
00408 # define SIZEOF_INT64 SIZEOF_LONG_LONG
00409 #else
00410 /* As long as it gets... */
00411 # define int64 off_t
00412 # define SIZEOF_INT64 SIZEOF_OFF_T
00413 #endif
00414 
00415 /* Starting from protocol version 26, we always use 64-bit
00416  * ino_t and dev_t internally, even if this platform does not
00417  * allow files to have 64-bit inums.  That's because the
00418  * receiver needs to find duplicate (dev,ino) tuples to detect
00419  * hardlinks, and it might have files coming from a platform
00420  * that has 64-bit inums.
00421  *
00422  * The only exception is if we're on a platform with no 64-bit type at
00423  * all.
00424  *
00425  * Because we use read_longint() to get these off the wire, if you
00426  * transfer devices or hardlinks with dev or inum > 2**32 to a machine
00427  * with no 64-bit types then you will get an overflow error.  Probably
00428  * not many people have that combination of machines, and you can
00429  * avoid it by not preserving hardlinks or not transferring device
00430  * nodes.  It's not clear that any other behaviour is better.
00431  *
00432  * Note that if you transfer devices from a 64-bit-devt machine (say,
00433  * Solaris) to a 32-bit-devt machine (say, Linux-2.2/x86) then the
00434  * device numbers will be truncated.  But it's a kind of silly thing
00435  * to do anyhow.
00436  *
00437  * FIXME: I don't think the code in flist.c has ever worked on a system
00438  * where dev_t is a struct.
00439  */
00440 
00441 struct idev {
00442         int64 inode;
00443         int64 dev;
00444 };
00445 
00446 #ifndef MIN
00447 #define MIN(a,b) ((a)<(b)?(a):(b))
00448 #endif
00449 
00450 #ifndef MAX
00451 #define MAX(a,b) ((a)>(b)?(a):(b))
00452 #endif
00453 
00454 #ifndef MAXHOSTNAMELEN
00455 #define MAXHOSTNAMELEN 256
00456 #endif
00457 
00458 /* the length of the md4 checksum */
00459 #define MD4_SUM_LENGTH 16
00460 #define SUM_LENGTH 16
00461 #define SHORT_SUM_LENGTH 2
00462 #define BLOCKSUM_BIAS 10
00463 
00464 #ifndef MAXPATHLEN
00465 #define MAXPATHLEN 1024
00466 #endif
00467 
00468 /* We want a roomy line buffer that can hold more than MAXPATHLEN,
00469  * and significantly more than an overly short MAXPATHLEN. */
00470 #if MAXPATHLEN < 4096
00471 #define BIGPATHBUFLEN (4096+1024)
00472 #else
00473 #define BIGPATHBUFLEN (MAXPATHLEN+1024)
00474 #endif
00475 
00476 #ifndef NAME_MAX
00477 #define NAME_MAX 255
00478 #endif
00479 
00480 #ifndef INADDR_NONE
00481 #define INADDR_NONE 0xffffffff
00482 #endif
00483 
00484 #ifndef IN_LOOPBACKNET
00485 #define IN_LOOPBACKNET 127
00486 #endif
00487 
00488 #define GID_NONE ((gid_t)-1)
00489 
00490 #define HL_CHECK_MASTER 0
00491 #define HL_SKIP         1
00492 
00493 struct hlink {
00494         int next;
00495         int hlindex;
00496 };
00497 
00498 #define F_DEV   link_u.idev->dev
00499 #define F_INODE link_u.idev->inode
00500 
00501 #define F_HLINDEX link_u.links->hlindex
00502 #define F_NEXT  link_u.links->next
00503 
00504 struct file_struct {
00505         union {
00506                 dev_t rdev;     /* The device number, if this is a device */
00507                 char *sum;      /* Only a normal file can have a checksum */
00508                 char *link;     /* Points to symlink string, if a symlink */
00509         } u;
00510         OFF_T length;
00511         char *basename;         /* The current item's name (AKA filename) */
00512         char *dirname;          /* The directory info inside the transfer */
00513         union {
00514                 char *root;     /* Sender-side dir info outside transfer */
00515                 int depth;      /* Receiver-side directory depth info */
00516         } dir;
00517         union {
00518                 struct idev *idev;
00519                 struct hlink *links;
00520         } link_u;
00521         time_t modtime;
00522         uid_t uid;
00523         gid_t gid;
00524         mode_t mode;
00525         uchar flags;    /* this item MUST remain last */
00526 };
00527 
00528 /*
00529  * Start the flist array at FLIST_START entries and grow it
00530  * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
00531  */
00532 #define FLIST_START     (32 * 1024)
00533 #define FLIST_LINEAR    (FLIST_START * 512)
00534 
00535 /*
00536  * Extent size for allocation pools A minimum size of 128KB
00537  * is needed to mmap them so that freeing will release the
00538  * space to the OS.
00539  *
00540  * Larger sizes reduce leftover fragments and speed free calls
00541  * (when they happen) Smaller sizes increase the chance of
00542  * freed allocations freeing whole extents.
00543  */
00544 #define FILE_EXTENT     (256 * 1024)
00545 #define HLINK_EXTENT    (128 * 1024)
00546 
00547 #define WITH_HLINK      1
00548 #define WITHOUT_HLINK   0
00549 
00550 struct file_list {
00551         struct file_struct **files;
00552         alloc_pool_t file_pool;
00553         alloc_pool_t hlink_pool;
00554         int count;
00555         int malloced;
00556         int low, high;
00557 };
00558 
00559 #define SUMFLG_SAME_OFFSET      (1<<0)
00560 
00561 struct sum_buf {
00562         OFF_T offset;           /**< offset in file of this chunk */
00563         int32 len;              /**< length of chunk of file */
00564         uint32 sum1;            /**< simple checksum */
00565         int32 chain;            /**< next hash-table collision */
00566         short flags;            /**< flag bits */
00567         char sum2[SUM_LENGTH];  /**< checksum  */
00568 };
00569 
00570 struct sum_struct {
00571         OFF_T flength;          /**< total file length */
00572         struct sum_buf *sums;   /**< points to info for each chunk */
00573         int32 count;            /**< how many chunks */
00574         int32 blength;          /**< block_length */
00575         int32 remainder;        /**< flength % block_length */
00576         int s2length;           /**< sum2_length */
00577 };
00578 
00579 struct map_struct {
00580         OFF_T file_size;        /* File size (from stat)                */
00581         OFF_T p_offset;         /* Window start                         */
00582         OFF_T p_fd_offset;      /* offset of cursor in fd ala lseek     */
00583         char *p;                /* Window pointer                       */
00584         int32 p_size;           /* Largest window size we allocated     */
00585         int32 p_len;            /* Latest (rounded) window size         */
00586         int32 def_window_size;  /* Default window size                  */
00587         int fd;                 /* File Descriptor                      */
00588         int status;             /* first errno from read errors         */
00589 };
00590 
00591 #define MATCHFLG_WILD           (1<<0) /* pattern has '*', '[', and/or '?' */
00592 #define MATCHFLG_WILD2          (1<<1) /* pattern has '**' */
00593 #define MATCHFLG_WILD2_PREFIX   (1<<2) /* pattern starts with "**" */
00594 #define MATCHFLG_WILD3_SUFFIX   (1<<3) /* pattern ends with "***" */
00595 #define MATCHFLG_ABS_PATH       (1<<4) /* path-match on absolute path */
00596 #define MATCHFLG_INCLUDE        (1<<5) /* this is an include, not an exclude */
00597 #define MATCHFLG_DIRECTORY      (1<<6) /* this matches only directories */
00598 #define MATCHFLG_WORD_SPLIT     (1<<7) /* split rules on whitespace */
00599 #define MATCHFLG_NO_INHERIT     (1<<8) /* don't inherit these rules */
00600 #define MATCHFLG_NO_PREFIXES    (1<<9) /* parse no prefixes from patterns */
00601 #define MATCHFLG_MERGE_FILE     (1<<10)/* specifies a file to merge */
00602 #define MATCHFLG_PERDIR_MERGE   (1<<11)/* merge-file is searched per-dir */
00603 #define MATCHFLG_EXCLUDE_SELF   (1<<12)/* merge-file name should be excluded */
00604 #define MATCHFLG_FINISH_SETUP   (1<<13)/* per-dir merge file needs setup */
00605 #define MATCHFLG_NEGATE         (1<<14)/* rule matches when pattern does not */
00606 #define MATCHFLG_CVS_IGNORE     (1<<15)/* rule was -C or :C */
00607 #define MATCHFLG_SENDER_SIDE    (1<<16)/* rule applies to the sending side */
00608 #define MATCHFLG_RECEIVER_SIDE  (1<<17)/* rule applies to the receiving side */
00609 #define MATCHFLG_CLEAR_LIST     (1<<18)/* this item is the "!" token */
00610 
00611 #define MATCHFLGS_FROM_CONTAINER (MATCHFLG_ABS_PATH | MATCHFLG_INCLUDE \
00612                                 | MATCHFLG_DIRECTORY | MATCHFLG_SENDER_SIDE \
00613                                 | MATCHFLG_NEGATE | MATCHFLG_RECEIVER_SIDE)
00614 
00615 struct filter_struct {
00616         struct filter_struct *next;
00617         char *pattern;
00618         uint32 match_flags;
00619         union {
00620                 int slash_cnt;
00621                 struct filter_list_struct *mergelist;
00622         } u;
00623 };
00624 
00625 struct filter_list_struct {
00626         struct filter_struct *head;
00627         struct filter_struct *tail;
00628         char *debug_type;
00629 };
00630 
00631 struct stats {
00632         int64 total_size;
00633         int64 total_transferred_size;
00634         int64 total_written;
00635         int64 total_read;
00636         int64 literal_data;
00637         int64 matched_data;
00638         int64 flist_buildtime;
00639         int64 flist_xfertime;
00640         int flist_size;
00641         int num_files;
00642         int num_transferred_files;
00643         int current_file_index;
00644 };
00645 
00646 struct chmod_mode_struct;
00647 
00648 #include "byteorder.h"
00649 #include "lib/mdfour.h"
00650 #include "lib/wildmatch.h"
00651 #include "lib/permstring.h"
00652 #include "lib/addrinfo.h"
00653 
00654 #if !defined __GNUC__ || defined __APPLE__
00655 /* Apparently the OS X port of gcc gags on __attribute__.
00656  *
00657  * <http://www.opensource.apple.com/bugs/X/gcc/2512150.html> */
00658 #define __attribute__(x)
00659 #endif
00660 
00661 #define UNUSED(x) x __attribute__((__unused__))
00662 
00663 #if HAVE_POSIX_ACLS|HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|\
00664     HAVE_HPUX_ACLS|HAVE_IRIX_ACLS|HAVE_AIX_ACLS|HAVE_TRU64_ACLS
00665 #define SUPPORT_ACLS 1
00666 #endif
00667 
00668 #if HAVE_UNIXWARE_ACLS|HAVE_SOLARIS_ACLS|HAVE_HPUX_ACLS
00669 #define ACLS_NEED_MASK 1
00670 #endif
00671 
00672 #if defined SUPPORT_ACLS && defined HAVE_SYS_ACL_H
00673 #include <sys/acl.h>
00674 #endif
00675 #include "smb_acls.h"
00676 
00677 #ifdef HAVE_LINUX_XATTRS
00678 #define SUPPORT_XATTRS 1
00679 #endif
00680 
00681 #if defined SUPPORT_XATTRS && defined HAVE_ATTR_XATTR_H
00682 #include <attr/xattr.h>
00683 #endif
00684 
00685 #include "proto.h"
00686 
00687 /* We have replacement versions of these if they're missing. */
00688 #ifndef HAVE_ASPRINTF
00689 int asprintf(char **ptr, const char *format, ...);
00690 #endif
00691 
00692 #ifndef HAVE_VASPRINTF
00693 int vasprintf(char **ptr, const char *format, va_list ap);
00694 #endif
00695 
00696 #if !defined HAVE_VSNPRINTF || !defined HAVE_C99_VSNPRINTF
00697 #define vsnprintf rsync_vsnprintf
00698 int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
00699 #endif
00700 
00701 #if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
00702 #define snprintf rsync_snprintf
00703 int snprintf(char *str,size_t count,const char *fmt,...);
00704 #endif
00705 
00706 
00707 #ifndef HAVE_STRERROR
00708 extern char *sys_errlist[];
00709 #define strerror(i) sys_errlist[i]
00710 #endif
00711 
00712 #ifndef HAVE_STRCHR
00713 # define strchr                 index
00714 # define strrchr                rindex
00715 #endif
00716 
00717 #ifndef HAVE_ERRNO_DECL
00718 extern int errno;
00719 #endif
00720 
00721 #ifdef HAVE_READLINK
00722 #define SUPPORT_LINKS 1
00723 #endif
00724 #ifdef HAVE_LINK
00725 #define SUPPORT_HARD_LINKS 1
00726 #endif
00727 
00728 #ifdef HAVE_SIGACTION
00729 #define SIGACTION(n,h) sigact.sa_handler=(h), sigaction((n),&sigact,NULL)
00730 #define signal(n,h) we_need_to_call_SIGACTION_not_signal(n,h)
00731 #else
00732 #define SIGACTION(n,h) signal(n,h)
00733 #endif
00734 
00735 #ifndef EWOULDBLOCK
00736 #define EWOULDBLOCK EAGAIN
00737 #endif
00738 
00739 #ifndef STDIN_FILENO
00740 #define STDIN_FILENO 0
00741 #endif
00742 
00743 #ifndef STDOUT_FILENO
00744 #define STDOUT_FILENO 1
00745 #endif
00746 
00747 #ifndef STDERR_FILENO
00748 #define STDERR_FILENO 2
00749 #endif
00750 
00751 #ifndef S_IRUSR
00752 #define S_IRUSR 0400
00753 #endif
00754 
00755 #ifndef S_IWUSR
00756 #define S_IWUSR 0200
00757 #endif
00758 
00759 #ifndef ACCESSPERMS
00760 #define ACCESSPERMS 0777
00761 #endif
00762 
00763 #ifndef S_ISVTX
00764 #define S_ISVTX 0
00765 #endif
00766 
00767 #define CHMOD_BITS (S_ISUID | S_ISGID | S_ISVTX | ACCESSPERMS)
00768 
00769 #ifndef _S_IFMT
00770 #define _S_IFMT        0170000
00771 #endif
00772 
00773 #ifndef _S_IFLNK
00774 #define _S_IFLNK  0120000
00775 #endif
00776 
00777 #ifndef S_ISLNK
00778 #define S_ISLNK(mode) (((mode) & (_S_IFMT)) == (_S_IFLNK))
00779 #endif
00780 
00781 #ifndef S_ISBLK
00782 #define S_ISBLK(mode) (((mode) & (_S_IFMT)) == (_S_IFBLK))
00783 #endif
00784 
00785 #ifndef S_ISCHR
00786 #define S_ISCHR(mode) (((mode) & (_S_IFMT)) == (_S_IFCHR))
00787 #endif
00788 
00789 #ifndef S_ISSOCK
00790 #ifdef _S_IFSOCK
00791 #define S_ISSOCK(mode) (((mode) & (_S_IFMT)) == (_S_IFSOCK))
00792 #else
00793 #define S_ISSOCK(mode) (0)
00794 #endif
00795 #endif
00796 
00797 #ifndef S_ISFIFO
00798 #ifdef _S_IFIFO
00799 #define S_ISFIFO(mode) (((mode) & (_S_IFMT)) == (_S_IFIFO))
00800 #else
00801 #define S_ISFIFO(mode) (0)
00802 #endif
00803 #endif
00804 
00805 #ifndef S_ISDIR
00806 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
00807 #endif
00808 
00809 #ifndef S_ISREG
00810 #define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
00811 #endif
00812 
00813 /* work out what fcntl flag to use for non-blocking */
00814 #ifdef O_NONBLOCK
00815 # define NONBLOCK_FLAG O_NONBLOCK
00816 #elif defined SYSV
00817 # define NONBLOCK_FLAG O_NDELAY
00818 #else
00819 # define NONBLOCK_FLAG FNDELAY
00820 #endif
00821 
00822 #ifndef INADDR_LOOPBACK
00823 #define INADDR_LOOPBACK 0x7f000001
00824 #endif
00825 
00826 #ifndef INADDR_NONE
00827 #define INADDR_NONE 0xffffffff
00828 #endif
00829 
00830 #define IS_SPECIAL(mode) (S_ISSOCK(mode) || S_ISFIFO(mode))
00831 #define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode))
00832 
00833 /* Initial mask on permissions given to temporary files.  Mask off setuid
00834      bits and group access because of potential race-condition security
00835      holes, and mask other access because mode 707 is bizarre */
00836 #define INITACCESSPERMS 0700
00837 
00838 /* handler for null strings in printf format */
00839 #define NS(s) ((s)?(s):"<NULL>")
00840 
00841 /* Convenient wrappers for malloc and realloc.  Use them. */
00842 #define new(type) ((type *)malloc(sizeof(type)))
00843 #define new_array(type, num) ((type *)_new_array(sizeof(type), (num)))
00844 #define realloc_array(ptr, type, num) ((type *)_realloc_array((ptr), sizeof(type), (num)))
00845 
00846 /* use magic gcc attributes to catch format errors */
00847  void rprintf(enum logcode , const char *, ...)
00848      __attribute__((format (printf, 2, 3)))
00849 ;
00850 
00851 /* This is just like rprintf, but it also tries to print some
00852  * representation of the error code.  Normally errcode = errno. */
00853 void rsyserr(enum logcode, int, const char *, ...)
00854      __attribute__((format (printf, 3, 4)))
00855      ;
00856 
00857 /* Make sure that the O_BINARY flag is defined. */
00858 #ifndef O_BINARY
00859 #define O_BINARY 0
00860 #endif
00861 
00862 #ifndef HAVE_STRLCPY
00863 size_t strlcpy(char *d, const char *s, size_t bufsize);
00864 #endif
00865 
00866 #ifndef HAVE_STRLCAT
00867 size_t strlcat(char *d, const char *s, size_t bufsize);
00868 #endif
00869 
00870 #ifndef WEXITSTATUS
00871 #define WEXITSTATUS(stat)       ((int)(((stat)>>8)&0xFF))
00872 #endif
00873 
00874 #define exit_cleanup(code) _exit_cleanup(code, __FILE__, __LINE__)
00875 
00876 #ifdef HAVE_GETEUID
00877 #define MY_UID() geteuid()
00878 #else
00879 #define MY_UID() getuid()
00880 #endif
00881 
00882 #ifdef HAVE_GETEGID
00883 #define MY_GID() getegid()
00884 #else
00885 #define MY_GID() getgid()
00886 #endif
00887 
00888 extern int verbose;
00889 
00890 #ifndef HAVE_INET_NTOP
00891 const char *inet_ntop(int af, const void *src, char *dst, size_t size);
00892 #endif
00893 
00894 #ifndef HAVE_INET_PTON
00895 int inet_pton(int af, const char *src, void *dst);
00896 #endif
00897 
00898 #ifdef MAINTAINER_MODE
00899 const char *get_panic_action(void);
00900 #endif

rsyncに対してSat Dec 5 19:45:42 2009に生成されました。  doxygen 1.4.7