132
135
#define WRITE_SIZE (32*1024)
133
136
#define CHUNK_SIZE (32*1024)
134
137
#define MAX_MAP_SIZE (256*1024)
135
#define IO_BUFFER_SIZE (4092)
138
#define IO_BUFFER_SIZE (32*1024)
136
139
#define MAX_BLOCK_SIZE ((int32)1 << 17)
138
141
/* For compatibility with older rsyncs */
139
142
#define OLD_MAX_BLOCK_SIZE ((int32)1 << 29)
144
#define ROUND_UP_1024(siz) ((siz) & (1024-1) ? ((siz) | (1024-1)) + 1 : (siz))
141
146
#define IOERR_GENERAL (1<<0) /* For backward compatibility, this must == 1 */
142
147
#define IOERR_VANISHED (1<<1)
143
148
#define IOERR_DEL_LIMIT (1<<2)
231
236
MSG_ERROR_UTF8=FERROR_UTF8, /* sibling logging */
232
237
MSG_LOG=FLOG, MSG_CLIENT=FCLIENT, /* sibling logging */
233
238
MSG_REDO=9, /* reprocess indicated flist index */
234
MSG_FLIST=20, /* extra file list over sibling socket */
235
MSG_FLIST_EOF=21,/* we've transmitted all the file lists */
239
MSG_STATS=10, /* message has stats data for generator */
236
240
MSG_IO_ERROR=22,/* the sending side had an I/O error */
237
MSG_NOOP=42, /* a do-nothing message */
241
MSG_IO_TIMEOUT=33,/* tell client about a daemon's timeout value */
242
MSG_NOOP=42, /* a do-nothing message (legacy protocol-30 only) */
243
MSG_ERROR_EXIT=86, /* synchronize an error exit (siblings and protocol >= 31) */
238
244
MSG_SUCCESS=100,/* successfully updated indicated flist index */
239
245
MSG_DELETED=101,/* successfully deleted a file on receiving side */
240
246
MSG_NO_SEND=102,/* sender failed to open a file we wanted */
241
MSG_DONE=86 /* current phase is done */
244
249
#define NDX_DONE -1
245
250
#define NDX_FLIST_EOF -2
251
#define NDX_DEL_STATS -3
246
252
#define NDX_FLIST_OFFSET -101
254
/* For calling delete_item() and delete_dir_contents(). */
255
#define DEL_NO_UID_WRITE (1<<0) /* file/dir has our uid w/o write perm */
256
#define DEL_RECURSE (1<<1) /* if dir, delete all contents */
257
#define DEL_DIR_IS_EMPTY (1<<2) /* internal delete_FUNCTIONS use only */
258
#define DEL_FOR_FILE (1<<3) /* making room for a replacement file */
259
#define DEL_FOR_DIR (1<<4) /* making room for a replacement dir */
260
#define DEL_FOR_SYMLINK (1<<5) /* making room for a replacement symlink */
261
#define DEL_FOR_DEVICE (1<<6) /* making room for a replacement device */
262
#define DEL_FOR_SPECIAL (1<<7) /* making room for a replacement special */
263
#define DEL_FOR_BACKUP (1<<8) /* the delete is for a backup operation */
265
#define DEL_MAKE_ROOM (DEL_FOR_FILE|DEL_FOR_DIR|DEL_FOR_SYMLINK|DEL_FOR_DEVICE|DEL_FOR_SPECIAL)
268
DR_SUCCESS = 0, DR_FAILURE, DR_AT_LIMIT, DR_NOT_EMPTY
271
/* Defines for make_path() */
272
#define MKP_DROP_NAME (1<<0) /* drop trailing filename or trailing slash */
273
#define MKP_SKIP_SLASH (1<<1) /* skip one or more leading slashes */
275
/* Defines for maybe_send_keepalive() */
276
#define MSK_ALLOW_FLUSH (1<<0)
277
#define MSK_ACTIVE_RECEIVER (1<<1)
248
279
#include "errcode.h"
250
281
#include "config.h"
634
673
#define ACLS_NEED_MASK 1
676
#if defined HAVE_FALLOCATE || HAVE_SYS_FALLOCATE
677
#ifdef HAVE_LINUX_FALLOC_H
678
#include <linux/falloc.h>
680
#ifdef FALLOC_FL_KEEP_SIZE
681
#define SUPPORT_PREALLOCATION 1
682
#elif defined HAVE_FTRUNCATE
683
#define SUPPORT_PREALLOCATION 1
684
#define PREALLOCATE_NEEDS_TRUNCATE 1
686
#else /* !fallocate */
687
#if defined HAVE_EFFICIENT_POSIX_FALLOCATE && defined HAVE_FTRUNCATE
688
#define SUPPORT_PREALLOCATION 1
689
#define PREALLOCATE_NEEDS_TRUNCATE 1
637
693
union file_extras {
674
732
#define F_LENGTH(f) ((int64)(f)->len32)
676
734
#define F_LENGTH(f) ((int64)(f)->len32 + ((f)->flags & FLAG_LENGTH64 \
677
? (int64)OPT_EXTRA(f, 0)->unum << 32 : 0))
735
? (int64)OPT_EXTRA(f, NSEC_BUMP(f))->unum << 32 : 0))
738
#define F_MOD_NSEC(f) ((f)->flags & FLAG_MOD_NSEC ? OPT_EXTRA(f, 0)->unum : 0)
680
740
/* If there is a symlink string, it is always right after the basename */
681
741
#define F_SYMLINK(f) ((f)->basename + strlen((f)->basename) + 1)
694
754
#define F_NDX(f) REQ_EXTRA(f, unsort_ndx)->num
696
756
/* These items are per-entry optional: */
697
#define F_HL_GNUM(f) OPT_EXTRA(f, LEN64_BUMP(f))->num /* non-dirs */
698
#define F_HL_PREV(f) OPT_EXTRA(f, LEN64_BUMP(f)+inc_recurse)->num /* non-dirs */
699
#define F_DIR_NODE_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) \
757
#define F_HL_GNUM(f) OPT_EXTRA(f, START_BUMP(f))->num /* non-dirs */
758
#define F_HL_PREV(f) OPT_EXTRA(f, START_BUMP(f)+inc_recurse)->num /* non-dirs */
759
#define F_DIR_NODE_P(f) (&OPT_EXTRA(f, START_BUMP(f) \
700
760
+ DIRNODE_EXTRA_CNT - 1)->num) /* sender dirs */
701
#define F_DIR_RELNAMES_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + DIRNODE_EXTRA_CNT \
761
#define F_DIR_RELNAMES_P(f) (&OPT_EXTRA(f, START_BUMP(f) + DIRNODE_EXTRA_CNT \
702
762
+ PTR_EXTRA_CNT - 1)->num) /* sender dirs */
703
#define F_DIR_DEFACL(f) OPT_EXTRA(f, LEN64_BUMP(f))->unum /* receiver dirs */
704
#define F_DIR_DEV_P(f) (&OPT_EXTRA(f, LEN64_BUMP(f) + ACL_BUMP(f) \
763
#define F_DIR_DEFACL(f) OPT_EXTRA(f, START_BUMP(f))->unum /* receiver dirs */
764
#define F_DIR_DEV_P(f) (&OPT_EXTRA(f, START_BUMP(f) + ACL_BUMP(f) \
705
765
+ DEV_EXTRA_CNT - 1)->unum) /* receiver dirs */
707
/* This optional item might follow an F_HL_*() item.
708
* (Note: a device doesn't need to check LEN64_BUMP(f).) */
709
#define F_RDEV_P(f) (&OPT_EXTRA(f, HLINK_BUMP(f) + DEV_EXTRA_CNT - 1)->unum)
767
/* This optional item might follow an F_HL_*() item. */
768
#define F_RDEV_P(f) (&OPT_EXTRA(f, START_BUMP(f) + HLINK_BUMP(f) + DEV_EXTRA_CNT - 1)->unum)
711
770
/* The sum is only present on regular files. */
712
#define F_SUM(f) ((char*)OPT_EXTRA(f, LEN64_BUMP(f) + HLINK_BUMP(f) \
771
#define F_SUM(f) ((char*)OPT_EXTRA(f, START_BUMP(f) + HLINK_BUMP(f) \
713
772
+ SUM_EXTRA_CNT - 1))
715
774
/* Some utility defines: */
794
853
int status; /* first errno from read errors */
797
#define MATCHFLG_WILD (1<<0) /* pattern has '*', '[', and/or '?' */
798
#define MATCHFLG_WILD2 (1<<1) /* pattern has '**' */
799
#define MATCHFLG_WILD2_PREFIX (1<<2) /* pattern starts with "**" */
800
#define MATCHFLG_WILD3_SUFFIX (1<<3) /* pattern ends with "***" */
801
#define MATCHFLG_ABS_PATH (1<<4) /* path-match on absolute path */
802
#define MATCHFLG_INCLUDE (1<<5) /* this is an include, not an exclude */
803
#define MATCHFLG_DIRECTORY (1<<6) /* this matches only directories */
804
#define MATCHFLG_WORD_SPLIT (1<<7) /* split rules on whitespace */
805
#define MATCHFLG_NO_INHERIT (1<<8) /* don't inherit these rules */
806
#define MATCHFLG_NO_PREFIXES (1<<9) /* parse no prefixes from patterns */
807
#define MATCHFLG_MERGE_FILE (1<<10)/* specifies a file to merge */
808
#define MATCHFLG_PERDIR_MERGE (1<<11)/* merge-file is searched per-dir */
809
#define MATCHFLG_EXCLUDE_SELF (1<<12)/* merge-file name should be excluded */
810
#define MATCHFLG_FINISH_SETUP (1<<13)/* per-dir merge file needs setup */
811
#define MATCHFLG_NEGATE (1<<14)/* rule matches when pattern does not */
812
#define MATCHFLG_CVS_IGNORE (1<<15)/* rule was -C or :C */
813
#define MATCHFLG_SENDER_SIDE (1<<16)/* rule applies to the sending side */
814
#define MATCHFLG_RECEIVER_SIDE (1<<17)/* rule applies to the receiving side */
815
#define MATCHFLG_CLEAR_LIST (1<<18)/* this item is the "!" token */
816
#define MATCHFLG_PERISHABLE (1<<19)/* perishable if parent dir goes away */
818
#define MATCHFLGS_FROM_CONTAINER (MATCHFLG_ABS_PATH | MATCHFLG_INCLUDE \
819
| MATCHFLG_DIRECTORY | MATCHFLG_SENDER_SIDE \
820
| MATCHFLG_NEGATE | MATCHFLG_RECEIVER_SIDE \
821
| MATCHFLG_PERISHABLE)
823
struct filter_struct {
856
#define FILTRULE_WILD (1<<0) /* pattern has '*', '[', and/or '?' */
857
#define FILTRULE_WILD2 (1<<1) /* pattern has '**' */
858
#define FILTRULE_WILD2_PREFIX (1<<2) /* pattern starts with "**" */
859
#define FILTRULE_WILD3_SUFFIX (1<<3) /* pattern ends with "***" */
860
#define FILTRULE_ABS_PATH (1<<4) /* path-match on absolute path */
861
#define FILTRULE_INCLUDE (1<<5) /* this is an include, not an exclude */
862
#define FILTRULE_DIRECTORY (1<<6) /* this matches only directories */
863
#define FILTRULE_WORD_SPLIT (1<<7) /* split rules on whitespace */
864
#define FILTRULE_NO_INHERIT (1<<8) /* don't inherit these rules */
865
#define FILTRULE_NO_PREFIXES (1<<9) /* parse no prefixes from patterns */
866
#define FILTRULE_MERGE_FILE (1<<10)/* specifies a file to merge */
867
#define FILTRULE_PERDIR_MERGE (1<<11)/* merge-file is searched per-dir */
868
#define FILTRULE_EXCLUDE_SELF (1<<12)/* merge-file name should be excluded */
869
#define FILTRULE_FINISH_SETUP (1<<13)/* per-dir merge file needs setup */
870
#define FILTRULE_NEGATE (1<<14)/* rule matches when pattern does not */
871
#define FILTRULE_CVS_IGNORE (1<<15)/* rule was -C or :C */
872
#define FILTRULE_SENDER_SIDE (1<<16)/* rule applies to the sending side */
873
#define FILTRULE_RECEIVER_SIDE (1<<17)/* rule applies to the receiving side */
874
#define FILTRULE_CLEAR_LIST (1<<18)/* this item is the "!" token */
875
#define FILTRULE_PERISHABLE (1<<19)/* perishable if parent dir goes away */
877
#define FILTRULES_SIDES (FILTRULE_SENDER_SIDE | FILTRULE_RECEIVER_SIDE)
879
typedef struct filter_struct {
824
880
struct filter_struct *next;
829
885
struct filter_list_struct *mergelist;
833
struct filter_list_struct {
834
struct filter_struct *head;
835
struct filter_struct *tail;
889
typedef struct filter_list_struct {
892
filter_rule *parent_dirscan_head;
836
893
char *debug_type;
840
897
int64 total_size;
846
903
int64 flist_buildtime;
847
904
int64 flist_xfertime;
848
905
int64 flist_size;
850
int num_transferred_files;
906
int num_files, num_dirs, num_symlinks, num_devices, num_specials;
907
int created_files, created_dirs, created_symlinks, created_devices, created_specials;
908
int deleted_files, deleted_dirs, deleted_symlinks, deleted_devices, deleted_specials;
853
912
struct chmod_mode_struct;
884
943
#define INIT_XBUF(xb, str, ln, sz) (xb).buf = (str), (xb).len = (ln), (xb).size = (sz), (xb).pos = 0
885
#define INIT_XBUF_STRLEN(xb, str) (xb).buf = (str), (xb).len = strlen((xb).buf), (xb).size = (-1), (xb).pos = 0
944
#define INIT_XBUF_STRLEN(xb, str) (xb).buf = (str), (xb).len = strlen((xb).buf), (xb).size = (size_t)-1, (xb).pos = 0
886
945
/* This one is used to make an output xbuf based on a char[] buffer: */
887
946
#define INIT_CONST_XBUF(xb, bf) (xb).buf = (bf), (xb).size = sizeof (bf), (xb).len = (xb).pos = 0
889
948
#define ICB_EXPAND_OUT (1<<0)
890
949
#define ICB_INCLUDE_BAD (1<<1)
891
950
#define ICB_INCLUDE_INCOMPLETE (1<<2)
951
#define ICB_CIRCULAR_OUT (1<<3)
952
#define ICB_INIT (1<<4)
954
#define IOBUF_KEEP_BUFS 0
955
#define IOBUF_FREE_BUFS 1
957
#define MPLX_SWITCHING IOBUF_KEEP_BUFS
958
#define MPLX_ALL_DONE IOBUF_FREE_BUFS
959
#define MPLX_TO_BUFFERED 2
893
961
#define RL_EOL_NULLS (1<<0)
894
962
#define RL_DUMP_COMMENTS (1<<1)
1155
1226
#define FD_ZERO(fdsetp) memset(fdsetp, 0, sizeof (fd_set))
1229
extern short info_levels[], debug_levels[];
1231
#define INFO_GTE(flag, lvl) (info_levels[INFO_##flag] >= (lvl))
1232
#define INFO_EQ(flag, lvl) (info_levels[INFO_##flag] == (lvl))
1233
#define DEBUG_GTE(flag, lvl) (debug_levels[DEBUG_##flag] >= (lvl))
1234
#define DEBUG_EQ(flag, lvl) (debug_levels[DEBUG_##flag] == (lvl))
1236
#define INFO_BACKUP 0
1237
#define INFO_COPY (INFO_BACKUP+1)
1238
#define INFO_DEL (INFO_COPY+1)
1239
#define INFO_FLIST (INFO_DEL+1)
1240
#define INFO_MISC (INFO_FLIST+1)
1241
#define INFO_MOUNT (INFO_MISC+1)
1242
#define INFO_NAME (INFO_MOUNT+1)
1243
#define INFO_PROGRESS (INFO_NAME+1)
1244
#define INFO_REMOVE (INFO_PROGRESS+1)
1245
#define INFO_SKIP (INFO_REMOVE+1)
1246
#define INFO_STATS (INFO_SKIP+1)
1247
#define INFO_SYMSAFE (INFO_STATS+1)
1249
#define COUNT_INFO (INFO_SYMSAFE+1)
1252
#define DEBUG_BACKUP (DEBUG_ACL+1)
1253
#define DEBUG_BIND (DEBUG_BACKUP+1)
1254
#define DEBUG_CHDIR (DEBUG_BIND+1)
1255
#define DEBUG_CONNECT (DEBUG_CHDIR+1)
1256
#define DEBUG_CMD (DEBUG_CONNECT+1)
1257
#define DEBUG_DEL (DEBUG_CMD+1)
1258
#define DEBUG_DELTASUM (DEBUG_DEL+1)
1259
#define DEBUG_DUP (DEBUG_DELTASUM+1)
1260
#define DEBUG_EXIT (DEBUG_DUP+1)
1261
#define DEBUG_FILTER (DEBUG_EXIT+1)
1262
#define DEBUG_FLIST (DEBUG_FILTER+1)
1263
#define DEBUG_FUZZY (DEBUG_FLIST+1)
1264
#define DEBUG_GENR (DEBUG_FUZZY+1)
1265
#define DEBUG_HASH (DEBUG_GENR+1)
1266
#define DEBUG_HLINK (DEBUG_HASH+1)
1267
#define DEBUG_ICONV (DEBUG_HLINK+1)
1268
#define DEBUG_IO (DEBUG_ICONV+1)
1269
#define DEBUG_OWN (DEBUG_IO+1)
1270
#define DEBUG_PROTO (DEBUG_OWN+1)
1271
#define DEBUG_RECV (DEBUG_PROTO+1)
1272
#define DEBUG_SEND (DEBUG_RECV+1)
1273
#define DEBUG_TIME (DEBUG_SEND+1)
1275
#define COUNT_DEBUG (DEBUG_TIME+1)
1160
1277
#ifndef HAVE_INET_NTOP
1161
1278
const char *inet_ntop(int af, const void *src, char *dst, size_t size);