were moved out of file_struct into an optional member-var setup.
- Renamed and reorganized the FLAG_* defines.
- Use NDX_DONE instead of a literal -1 when sending/checking the
end-of-phase index value.
#include "rsync.h"
extern int verbose;
-extern int backup_dir_len;
-extern unsigned int backup_dir_remainder;
-extern char backup_dir_buf[MAXPATHLEN];
-extern char *backup_suffix;
-extern char *backup_dir;
-
extern int am_root;
extern int preserve_devices;
extern int preserve_specials;
extern int preserve_links;
extern int safe_symlinks;
+extern int backup_dir_len;
+extern int flist_extra_ndx;
+extern int file_struct_len;
+extern unsigned int backup_dir_remainder;
+extern char backup_dir_buf[MAXPATHLEN];
+extern char *backup_suffix;
+extern char *backup_dir;
/* make a complete pathname for backup file */
char *get_backup_name(const char *fname)
if (!(file = make_file(fname, NULL, NULL, 0, NO_FILTERS)))
return 1; /* the file could have disappeared */
- if (!(buf = get_backup_name(fname)))
+ if (!(buf = get_backup_name(fname))) {
+ unmake_file(file);
return 0;
+ }
/* Check to see if this is a device file, or link */
if ((am_root && preserve_devices && IS_DEVICE(file->mode))
|| (preserve_specials && IS_SPECIAL(file->mode))) {
+ dev_t rdev = MAKEDEV(F_DMAJOR(file), F_DMINOR(file));
do_unlink(buf);
- if (do_mknod(buf, file->mode, file->u.rdev) < 0
+ if (do_mknod(buf, file->mode, rdev) < 0
&& (errno != ENOENT || make_bak_dir(buf) < 0
- || do_mknod(buf, file->mode, file->u.rdev) < 0)) {
+ || do_mknod(buf, file->mode, rdev) < 0)) {
rsyserr(FERROR, errno, "mknod %s failed",
full_fname(buf));
} else if (verbose > 2) {
#ifdef SUPPORT_LINKS
if (!kept && preserve_links && S_ISLNK(file->mode)) {
- if (safe_symlinks && unsafe_symlink(file->u.link, buf)) {
+ const char *sl = F_SYMLINK(file);
+ if (safe_symlinks && unsafe_symlink(sl, buf)) {
if (verbose) {
rprintf(FINFO, "ignoring unsafe symlink %s -> %s\n",
- full_fname(buf), file->u.link);
+ full_fname(buf), sl);
}
kept = 1;
} else {
do_unlink(buf);
- if (do_symlink(file->u.link, buf) < 0
+ if (do_symlink(sl, buf) < 0
&& (errno != ENOENT || make_bak_dir(buf) < 0
- || do_symlink(file->u.link, buf) < 0)) {
+ || do_symlink(sl, buf) < 0)) {
rsyserr(FERROR, errno, "link %s -> \"%s\"",
- full_fname(buf),
- file->u.link);
+ full_fname(buf), sl);
}
do_unlink(fname);
kept = 1;
if (!kept && !S_ISREG(file->mode)) {
rprintf(FINFO, "make_bak: skipping non-regular file %s\n",
fname);
+ unmake_file(file);
return 1;
}
}
}
set_file_attrs(buf, file, NULL, 0);
- free(file);
+ unmake_file(file);
if (verbose > 1) {
rprintf(FINFO, "backed up %s to %s\n",
extern int do_compression;
extern int def_compress_level;
extern int protocol_version;
+extern int flist_extra_ndx;
extern char *batch_name;
extern struct filter_list_struct filter_list;
+static int tweaked_preserve_uid;
+static int tweaked_preserve_gid;
static int tweaked_compress_level;
static int *flag_ptr[] = {
&recurse, /* 0 */
- &preserve_uid, /* 1 */
- &preserve_gid, /* 2 */
+ &tweaked_preserve_uid, /* 1 */
+ &tweaked_preserve_gid, /* 2 */
&preserve_links, /* 3 */
&preserve_devices, /* 4 */
&preserve_hard_links, /* 5 */
{
int i, flags;
+ tweaked_preserve_uid = preserve_uid != 0;
+ tweaked_preserve_gid = preserve_gid != 0;
#if Z_DEFAULT_COMPRESSION == -1
tweaked_compress_level = do_compression ? def_compress_level + 2 : 0;
#else
xfer_dirs = 0;
}
+ if (tweaked_preserve_uid) {
+ if (!preserve_uid)
+ preserve_uid = flist_extra_ndx++;
+ } else
+ preserve_uid = 0;
+ if (tweaked_preserve_gid) {
+ if (!preserve_gid)
+ preserve_gid = flist_extra_ndx++;
+ } else
+ preserve_gid = 0;
if (tweaked_compress_level == 0 || tweaked_compress_level == 2)
do_compression = 0;
else {
extern int preserve_gid;
extern int relative_paths;
extern int implied_dirs;
+extern int flist_extra_ndx;
extern int ignore_perishable;
extern int non_perishable_cnt;
extern int prune_empty_dirs;
int io_error;
int checksum_len;
dev_t filesystem_dev; /* used to implement -x */
-unsigned int file_struct_len;
+int file_struct_len;
+
+/* The tmp_* vars are used as a cache area by make_file() to store data
+ * that the sender doesn't need to remember in its file list. The data
+ * will survive just long enough to be used by send_file_entry(). */
+static dev_t tmp_rdev;
+static struct idev tmp_idev;
+static char tmp_sum[MD4_SUM_LENGTH];
static char empty_sum[MD4_SUM_LENGTH];
static int flist_count_offset;
rprintf(FINFO, "%s %11.0f %s %s -> %s\n",
permbuf,
(double)f->length, timestring(f->modtime),
- f_name(f, NULL), f->u.link);
+ f_name(f, NULL), F_SYMLINK(f));
} else
#endif
{
f_name(file, fname);
- flags = file->flags & XMIT_TOP_DIR;
+ flags = file->flags & FLAG_TOP_DIR; /* FLAG_TOP_DIR == XMIT_TOP_DIR */
if (file->mode == mode)
flags |= XMIT_SAME_MODE;
if ((preserve_devices && IS_DEVICE(mode))
|| (preserve_specials && IS_SPECIAL(mode))) {
if (protocol_version < 28) {
- if (file->u.rdev == rdev)
+ if (tmp_rdev == rdev)
flags |= XMIT_SAME_RDEV_pre28;
else
- rdev = file->u.rdev;
+ rdev = tmp_rdev;
} else {
- rdev = file->u.rdev;
+ rdev = tmp_rdev;
if ((uint32)major(rdev) == rdev_major)
flags |= XMIT_SAME_RDEV_MAJOR;
else
}
} else if (protocol_version < 28)
rdev = MAKEDEV(0, 0);
- if (file->uid == uid)
- flags |= XMIT_SAME_UID;
- else
- uid = file->uid;
- if (file->gid == gid)
- flags |= XMIT_SAME_GID;
- else
- gid = file->gid;
+ if (preserve_uid) {
+ if (F_UID(file) == uid)
+ flags |= XMIT_SAME_UID;
+ else
+ uid = F_UID(file);
+ }
+ if (preserve_gid) {
+ if (F_GID(file) == gid)
+ flags |= XMIT_SAME_GID;
+ else
+ gid = F_GID(file);
+ }
if (file->modtime == modtime)
flags |= XMIT_SAME_TIME;
else
modtime = file->modtime;
#ifdef SUPPORT_HARD_LINKS
- if (file->link_u.idev) {
- if (file->F_DEV == dev) {
+ if (tmp_idev.dev != 0) {
+ if (tmp_idev.dev == dev) {
if (protocol_version >= 28)
flags |= XMIT_SAME_DEV;
} else
- dev = file->F_DEV;
+ dev = tmp_idev.dev;
flags |= XMIT_HAS_IDEV_DATA;
}
#endif
#ifdef SUPPORT_LINKS
if (preserve_links && S_ISLNK(mode)) {
- int len = strlen(file->u.link);
+ const char *sl = F_SYMLINK(file);
+ int len = strlen(sl);
write_int(f, len);
- write_buf(f, file->u.link, len);
+ write_buf(f, sl, len);
}
#endif
#ifdef SUPPORT_HARD_LINKS
- if (file->link_u.idev) {
+ if (tmp_idev.dev != 0) {
if (protocol_version < 26) {
/* 32-bit dev_t and ino_t */
write_int(f, (int32)dev);
- write_int(f, (int32)file->F_INODE);
+ write_int(f, (int32)tmp_idev.ino);
} else {
/* 64-bit dev_t and ino_t */
if (!(flags & XMIT_SAME_DEV))
write_longint(f, dev);
- write_longint(f, file->F_INODE);
+ write_longint(f, tmp_idev.ino);
}
}
#endif
if (always_checksum && (S_ISREG(mode) || protocol_version < 28)) {
const char *sum;
if (S_ISREG(mode))
- sum = file->u.sum;
+ sum = tmp_sum;
else {
/* Prior to 28, we sent a useless set of nulls. */
sum = empty_sum;
strlcpy(lastname, fname, MAXPATHLEN);
}
-static struct file_struct *receive_file_entry(struct file_list *flist,
- unsigned short flags, int f)
+static struct file_struct *recv_file_entry(struct file_list *flist,
+ unsigned short flags, int f)
{
static time_t modtime;
static mode_t mode;
char thisname[MAXPATHLEN];
unsigned int l1 = 0, l2 = 0;
int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
+ int extra_len = (flist_extra_ndx-1) * sizeof (union flist_extras);
OFF_T file_length;
char *basename, *dirname, *bp;
struct file_struct *file;
if (l2 >= MAXPATHLEN - l1) {
rprintf(FERROR,
- "overflow: flags=0x%x l1=%d l2=%d lastname=%s\n",
- flags, l1, l2, lastname);
- overflow_exit("receive_file_entry");
+ "overflow: flags=0x%x l1=%d l2=%d lastname=%s [%s]\n",
+ flags, l1, l2, lastname, who_am_i());
+ overflow_exit("recv_file_entry");
}
strlcpy(thisname, lastname, l1 + 1);
rdev_minor = read_int(f);
rdev = MAKEDEV(rdev_major, rdev_minor);
}
+ extra_len += 2 * sizeof (union flist_extras);
} else if (protocol_version < 28)
rdev = MAKEDEV(0, 0);
if (linkname_len <= 0 || linkname_len > MAXPATHLEN) {
rprintf(FERROR, "overflow: linkname_len=%d\n",
linkname_len - 1);
- overflow_exit("receive_file_entry");
+ overflow_exit("recv_file_entry");
}
}
else
#endif
linkname_len = 0;
+#ifdef SUPPORT_HARD_LINKS
+ if (preserve_hard_links && protocol_version < 28 && S_ISREG(mode))
+ flags |= XMIT_HAS_IDEV_DATA;
+ if (flags & XMIT_HAS_IDEV_DATA) {
+ extra_len += sizeof (union flist_extras);
+ assert(flist->hlink_pool != NULL);
+ }
+#endif
+
sum_len = always_checksum && S_ISREG(mode) ? MD4_SUM_LENGTH : 0;
alloc_len = file_struct_len + dirname_len + basename_len
- + linkname_len + sum_len;
- bp = pool_alloc(flist->file_pool, alloc_len, "receive_file_entry");
+ + linkname_len + sum_len + extra_len;
+ bp = pool_alloc(flist->file_pool, alloc_len, "recv_file_entry");
+ memset(bp, 0, file_struct_len + extra_len);
+ bp += extra_len;
file = (struct file_struct *)bp;
- memset(bp, 0, file_struct_len);
- bp += file_struct_len;
+ bp += file_struct_len + linkname_len + sum_len;
+#ifdef SUPPORT_HARD_LINKS
+ if (flags & XMIT_HAS_IDEV_DATA)
+ file->flags |= FLAG_HLINK_INFO;
+#endif
file->modtime = modtime;
file->length = file_length;
file->mode = mode;
- file->uid = uid;
- file->gid = gid;
+ if (preserve_uid)
+ F_UID(file) = uid;
+ if (preserve_gid)
+ F_GID(file) = gid;
if (dirname_len) {
file->dirname = lastdir = bp;
&& lastname[del_hier_name_len-1] == '.'
&& lastname[del_hier_name_len-2] == '/')
del_hier_name_len -= 2;
- file->flags |= FLAG_TOP_DIR | FLAG_DEL_HERE;
+ file->flags |= FLAG_TOP_DIR | FLAG_XFER_DIR;
} else if (in_del_hier) {
if (!relative_paths || !del_hier_name_len
|| (l1 >= del_hier_name_len
&& lastname[del_hier_name_len] == '/'))
- file->flags |= FLAG_DEL_HERE;
+ file->flags |= FLAG_XFER_DIR;
else
in_del_hier = 0;
}
bp += basename_len;
if ((preserve_devices && IS_DEVICE(mode))
- || (preserve_specials && IS_SPECIAL(mode)))
- file->u.rdev = rdev;
+ || (preserve_specials && IS_SPECIAL(mode))) {
+ F_DMAJOR(file) = major(rdev);
+ F_DMINOR(file) = minor(rdev);
+ }
#ifdef SUPPORT_LINKS
if (linkname_len) {
- file->u.link = bp;
+ bp = F_SYMLINK(file);
read_sbuf(f, bp, linkname_len - 1);
if (sanitize_paths)
sanitize_path(bp, bp, "", lastdir_depth, NULL);
- bp += linkname_len;
}
#endif
#ifdef SUPPORT_HARD_LINKS
- if (preserve_hard_links && protocol_version < 28 && S_ISREG(mode))
- flags |= XMIT_HAS_IDEV_DATA;
if (flags & XMIT_HAS_IDEV_DATA) {
- int64 inode;
+ struct idev *idevp = pool_talloc(flist->hlink_pool, struct idev,
+ 1, "inode_table");
+ F_IDEV(file) = idevp;
if (protocol_version < 26) {
- dev = read_int(f);
- inode = read_int(f);
+ idevp->dev = read_int(f);
+ idevp->ino = read_int(f);
} else {
if (!(flags & XMIT_SAME_DEV))
dev = read_longint(f);
- inode = read_longint(f);
- }
- if (flist->hlink_pool) {
- file->link_u.idev = pool_talloc(flist->hlink_pool,
- struct idev, 1, "inode_table");
- file->F_INODE = inode;
- file->F_DEV = dev;
+ idevp->dev = dev;
+ idevp->ino = read_longint(f);
}
}
#endif
if (always_checksum && (sum_len || protocol_version < 28)) {
- char *sum;
- if (sum_len) {
- file->u.sum = sum = bp;
- /*bp += sum_len;*/
- } else {
+ if (sum_len)
+ bp = F_SUM(file);
+ else {
/* Prior to 28, we get a useless set of nulls. */
- sum = empty_sum;
+ bp = tmp_sum;
}
- read_buf(f, sum, checksum_len);
+ read_buf(f, bp, checksum_len);
}
return file;
* important case. Some systems may not have d_type.
**/
struct file_struct *make_file(const char *fname, struct file_list *flist,
- STRUCT_STAT *stp, unsigned short flags,
- int filter_level)
+ STRUCT_STAT *stp, int flags, int filter_level)
{
static char *lastdir;
static int lastdir_len = -1;
struct file_struct *file;
STRUCT_STAT st;
- char sum[SUM_LENGTH];
char thisname[MAXPATHLEN];
char linkname[MAXPATHLEN];
- int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
+ int alloc_len, basename_len, dirname_len, linkname_len;
+ int extra_len = (flist_extra_ndx-1) * sizeof (union flist_extras);
char *basename, *dirname, *bp;
if (!flist || !flist->count) /* Ignore lastdir when invalid. */
if (sanitize_paths)
sanitize_path(thisname, thisname, "", 0, NULL);
- memset(sum, 0, SUM_LENGTH);
-
if (stp && S_ISDIR(stp->st_mode)) {
st = *stp; /* Needed for "symlink/." with --relative. */
*linkname = '\0'; /* make IBM code checker happy */
}
return NULL;
}
- flags |= FLAG_MOUNT_POINT;
+ flags |= FLAG_MOUNT_DIR;
}
if (is_excluded(thisname, S_ISDIR(st.st_mode) != 0, filter_level)) {
linkname_len = 0;
#endif
- sum_len = always_checksum && am_sender && S_ISREG(st.st_mode)
- ? MD4_SUM_LENGTH : 0;
-
alloc_len = file_struct_len + dirname_len + basename_len
- + linkname_len + sum_len;
+ + linkname_len + extra_len;
if (flist)
bp = pool_alloc(flist->file_pool, alloc_len, "make_file");
else {
out_of_memory("make_file");
}
+ memset(bp, 0, file_struct_len + extra_len);
+ bp += extra_len;
file = (struct file_struct *)bp;
- memset(bp, 0, file_struct_len);
- bp += file_struct_len;
+ bp += file_struct_len + linkname_len;
+
+#ifdef SUPPORT_HARD_LINKS
+ if (preserve_hard_links && flist) {
+ if (protocol_version >= 28
+ ? (!S_ISDIR(st.st_mode) && st.st_nlink > 1)
+ : S_ISREG(st.st_mode)) {
+ tmp_idev.dev = st.st_dev;
+ tmp_idev.ino = st.st_ino;
+ } else
+ tmp_idev.dev = tmp_idev.ino = 0;
+ }
+#endif
file->flags = flags;
file->modtime = st.st_mtime;
file->length = st.st_size;
file->mode = st.st_mode;
- file->uid = st.st_uid;
- file->gid = st.st_gid;
-
-#ifdef SUPPORT_HARD_LINKS
- if (flist && flist->hlink_pool) {
- if (protocol_version < 28) {
- if (S_ISREG(st.st_mode))
- file->link_u.idev = pool_talloc(
- flist->hlink_pool, struct idev, 1,
- "inode_table");
- } else {
- if (!S_ISDIR(st.st_mode) && st.st_nlink > 1)
- file->link_u.idev = pool_talloc(
- flist->hlink_pool, struct idev, 1,
- "inode_table");
- }
- }
- if (file->link_u.idev) {
- file->F_DEV = st.st_dev;
- file->F_INODE = st.st_ino;
- }
-#endif
+ if (preserve_uid)
+ F_UID(file) = st.st_uid;
+ if (preserve_gid)
+ F_GID(file) = st.st_gid;
if (dirname_len) {
file->dirname = lastdir = bp;
#ifdef HAVE_STRUCT_STAT_ST_RDEV
if ((preserve_devices && IS_DEVICE(st.st_mode))
|| (preserve_specials && IS_SPECIAL(st.st_mode)))
- file->u.rdev = st.st_rdev;
+ tmp_rdev = st.st_rdev;
#endif
#ifdef SUPPORT_LINKS
- if (linkname_len) {
- file->u.link = bp;
- memcpy(bp, linkname, linkname_len);
- bp += linkname_len;
- }
+ if (linkname_len)
+ memcpy(F_SYMLINK(file), linkname, linkname_len);
#endif
- if (sum_len) {
- file->u.sum = bp;
- file_checksum(thisname, bp, st.st_size);
- /*bp += sum_len;*/
- }
+ if (always_checksum && am_sender && S_ISREG(st.st_mode))
+ file_checksum(thisname, tmp_sum, st.st_size);
file->dir.root = flist_dir;
file->modtime = st2.st_mtime;
file->length = st2.st_size;
file->mode = st2.st_mode;
- file->uid = st2.st_uid;
- file->gid = st2.st_gid;
- file->u.link = NULL;
+ if (preserve_uid)
+ F_UID(file) = st2.st_uid;
+ if (preserve_gid)
+ F_GID(file) = st2.st_gid;
} else
file->mode = save_mode;
}
if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode))
stats.total_size += st.st_size;
+ if (basename_len == 0+1)
+ return NULL;
+
return file;
}
+/* Only called for temporary file_struct entries. */
+void unmake_file(struct file_struct *file)
+{
+ union flist_extras *start = (union flist_extras *)file
+ - (flist_extra_ndx - 1);
+ free(start);
+}
+
static struct file_struct *send_file_name(int f, struct file_list *flist,
char *fname, STRUCT_STAT *stp,
unsigned short flags)
maybe_emit_filelist_progress(flist->count + flist_count_offset);
flist_expand(flist);
-
- if (file->basename[0]) {
- flist->files[flist->count++] = file;
- send_file_entry(file, f);
- }
+ flist->files[flist->count++] = file;
+ send_file_entry(file, f);
return file;
}
char is_dot_dir = fbuf[ol-1] == '.' && (ol == 1 || fbuf[ol-2] == '/');
if (S_ISDIR(file->mode)
- && !(file->flags & FLAG_MOUNT_POINT) && f_name(file, fbuf)) {
+ && !(file->flags & FLAG_MOUNT_DIR) && f_name(file, fbuf)) {
void *save_filters;
unsigned int len = strlen(fbuf);
if (len > 1 && fbuf[len-1] == '/')
start_write = stats.total_written;
gettimeofday(&start_tv, NULL);
- flist = flist_new(WITH_HLINK, "send_file_list");
+ flist = flist_new(0, "send_file_list");
io_start_buffering_out();
if (filesfrom_fd >= 0) {
stats.flist_xfertime = (int64)(end_tv.tv_sec - start_tv.tv_sec) * 1000
+ (end_tv.tv_usec - start_tv.tv_usec) / 1000;
- if (flist->hlink_pool) {
- pool_destroy(flist->hlink_pool);
- flist->hlink_pool = NULL;
- }
-
/* Sort the list without removing any duplicates. This allows the
* receiving side to ask for any name they like, which gives us the
* flexibility to change the way we unduplicate names in the future
* without causing a compatibility problem with older versions. */
clean_flist(flist, 0, 0);
- send_uid_list(f);
+ if (!numeric_ids)
+ send_uid_list(f);
/* send the io_error flag */
write_int(f, lp_ignore_errors(module_id) ? 0 : io_error);
flist = flist_new(WITH_HLINK, "recv_file_list");
- flist->count = 0;
- flist->malloced = 1000;
- flist->files = new_array(struct file_struct *, flist->malloced);
- if (!flist->files)
- goto oom;
while ((flags = read_byte(f)) != 0) {
struct file_struct *file;
if (protocol_version >= 28 && (flags & XMIT_EXTENDED_FLAGS))
flags |= read_byte(f) << 8;
- file = receive_file_entry(flist, flags, f);
+ file = recv_file_entry(flist, flags, f);
if (S_ISREG(file->mode) || S_ISLNK(file->mode))
stats.total_size += file->length;
f_name(file, NULL));
}
}
- receive_file_entry(NULL, 0, 0); /* Signal that we're done. */
+ recv_file_entry(NULL, 0, 0); /* Signal that we're done. */
if (verbose > 2)
rprintf(FINFO, "received %d names\n", flist->count);
stats.num_files = flist->count;
return flist;
-
- oom:
- out_of_memory("recv_file_list");
- return NULL; /* not reached */
}
static int file_compare(struct file_struct **file1, struct file_struct **file2)
* Free up any resources a file_struct has allocated
* and clear the file.
*/
-void clear_file(struct file_struct *file, struct file_list *flist)
+void clear_file(struct file_struct *file)
{
- if (flist->hlink_pool && file->link_u.idev)
- pool_free(flist->hlink_pool, 0, file->link_u.idev);
memset(file, 0, file_struct_len);
/* In an empty entry, dir.depth is an offset to the next non-empty
* entry. Likewise for length in the opposite direction. We assume
if (!flist)
out_of_memory(msg);
- memset(flist, 0, sizeof (struct file_list));
+ memset(flist, 0, sizeof flist[0]);
if (!(flist->file_pool = pool_create(FILE_EXTENT, 0, out_of_memory, POOL_INTERN)))
out_of_memory(msg);
/* Make sure we don't lose track of a user-specified
* top directory. */
flist->files[keep]->flags |= flist->files[drop]->flags
- & (FLAG_TOP_DIR|FLAG_DEL_HERE);
+ & (FLAG_TOP_DIR|FLAG_XFER_DIR);
- clear_file(flist->files[drop], flist);
+ clear_file(flist->files[drop]);
if (keep == i) {
if (flist->low == drop) {
if (fp->dir.depth >= 0)
break;
prev_i = -fp->dir.depth-1;
- clear_file(fp, flist);
+ clear_file(fp);
}
prev_depth = file->dir.depth;
if (is_excluded(f_name(file, fbuf), 1,
if (fp->dir.depth >= 0)
break;
prev_i = -fp->dir.depth-1;
- clear_file(fp, flist);
+ clear_file(fp);
}
for (i = flist->low; i <= flist->high; i++) {
for (i = 0; i < flist->count; i++) {
file = flist->files[i];
- if ((am_root || am_sender) && preserve_uid)
- snprintf(uidbuf, sizeof uidbuf, " uid=%ld", (long)file->uid);
- else
+ if ((am_root || am_sender) && preserve_uid) {
+ snprintf(uidbuf, sizeof uidbuf, " uid=%ld",
+ (long)F_UID(file));
+ } else
*uidbuf = '\0';
- if (preserve_gid && file->gid != GID_NONE)
- snprintf(gidbuf, sizeof gidbuf, " gid=%ld", (long)file->gid);
- else
+ if (preserve_gid && F_GID(file) != GID_NONE) {
+ snprintf(gidbuf, sizeof gidbuf, " gid=%ld",
+ (long)F_GID(file));
+ } else
*gidbuf = '\0';
if (!am_sender)
snprintf(depthbuf, sizeof depthbuf, "%d", file->dir.depth);
extern int delete_after;
extern int module_id;
extern int ignore_errors;
+extern int flist_extra_ndx;
extern int remove_source_files;
extern int delay_updates;
extern int update_only;
extern int max_delete;
extern int force_delete;
extern int one_file_system;
+extern int file_struct_len;
extern struct stats stats;
extern dev_t filesystem_dev;
extern char *backup_dir;
for (j = dirlist->count; j--; ) {
struct file_struct *fp = dirlist->files[j];
- if (fp->flags & FLAG_MOUNT_POINT) {
+ if (fp->flags & FLAG_MOUNT_DIR) {
if (verbose > 1) {
rprintf(FINFO,
"mount point, %s, pins parent directory\n",
struct file_struct *fp = dirlist->files[i];
if (!fp->basename)
continue;
- if (fp->flags & FLAG_MOUNT_POINT) {
+ if (fp->flags & FLAG_MOUNT_DIR) {
if (verbose > 1)
rprintf(FINFO, "cannot delete mount point: %s\n",
f_name(fp, NULL));
for (j = 0; j < flist->count; j++) {
struct file_struct *file = flist->files[j];
- if (!(file->flags & FLAG_DEL_HERE))
+ if (!(file->flags & FLAG_XFER_DIR))
continue;
f_name(file, fbuf);
&& (st->st_mode & CHMOD_BITS) != (file->mode & CHMOD_BITS))
return 0;
- if (am_root && preserve_uid && st->st_uid != file->uid)
+ if (am_root && preserve_uid && st->st_uid != F_UID(file))
return 0;
- if (preserve_gid && file->gid != GID_NONE && st->st_gid != file->gid)
+ if (preserve_gid && F_GID(file) != GID_NONE && st->st_gid != F_GID(file))
return 0;
return 1;
iflags |= ITEM_REPORT_TIME;
if ((file->mode & CHMOD_BITS) != (st->st_mode & CHMOD_BITS))
iflags |= ITEM_REPORT_PERMS;
- if (preserve_uid && am_root && file->uid != st->st_uid)
+ if (preserve_uid && am_root && F_UID(file) != st->st_uid)
iflags |= ITEM_REPORT_OWNER;
- if (preserve_gid && file->gid != GID_NONE
- && st->st_gid != file->gid)
+ if (preserve_gid && F_GID(file) != GID_NONE
+ && st->st_gid != F_GID(file))
iflags |= ITEM_REPORT_GROUP;
} else
iflags |= ITEM_IS_NEW;
if (always_checksum && S_ISREG(st->st_mode)) {
char sum[MD4_SUM_LENGTH];
file_checksum(fn, sum, st->st_size);
- return memcmp(sum, file->u.sum, checksum_len) == 0;
+ return memcmp(sum, F_SUM(file), checksum_len) == 0;
}
if (size_only)
int len, suf_len;
uint32 dist;
- if (!S_ISREG(fp->mode) || !fp->length
- || fp->flags & FLAG_NO_FUZZY)
+ if (!S_ISREG(fp->mode) || !fp->length || fp->flags & FLAG_SENT)
continue;
name = fp->basename;
continue;
file = the_file_list->files[ndx];
- if (!file->link_u.links)
+ if (!IS_HLINKED(file))
continue;
- hard_link_cluster(file, ndx, itemizing, code);
+ hard_link_cluster(file, ndx, itemizing, code, -1);
}
}
if (hard_link_one(file, ndx, fname, 0, stp,
cmpbuf, 1, i, code) < 0)
goto try_a_copy;
- if (preserve_hard_links && file->link_u.links) {
- if (dry_run)
- file->link_u.links->link_dest_used = j + 1;
- hard_link_cluster(file, ndx, itemizing, code);
- }
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, j);
} else
#endif
if (itemizing)
rprintf(code, "%s%s\n", fname,
match_level == 3 ? " is uptodate" : "");
}
- if (preserve_hard_links && file->link_u.links)
- hard_link_cluster(file, ndx, itemizing, code);
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, j);
return -2;
}
break;
case TYPE_SPECIAL:
case TYPE_DEVICE:
- if (stp->st_rdev != file->u.rdev)
+ if (stp->st_rdev != MAKEDEV(F_DMAJOR(file), F_DMINOR(file)))
continue;
break;
#ifdef SUPPORT_LINKS
if ((len = readlink(cmpbuf, lnk, MAXPATHLEN-1)) <= 0)
continue;
lnk[len] = '\0';
- if (strcmp(lnk, file->u.link) != 0)
+ if (strcmp(lnk, F_SYMLINK(file)) != 0)
continue;
break;
#endif
cmpbuf, fname);
return j;
}
- if (preserve_hard_links && file->link_u.links)
- hard_link_cluster(file, ndx, itemizing, code);
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, -1);
} else
#endif
match_level = 2;
rsyserr(FERROR, errno,
"recv_generator: mkdir %s failed",
full_fname(fname));
- file->flags |= FLAG_MISSING;
+ file->flags |= FLAG_MISSING_DIR;
if (ndx+1 < the_file_list->count
&& the_file_list->files[ndx+1]->dir.depth > file->dir.depth) {
rprintf(FERROR,
if (real_ret != 0 && one_file_system)
real_st.st_dev = filesystem_dev;
if (delete_during && f_out != -1 && !phase && dry_run < 2
- && (file->flags & FLAG_DEL_HERE))
+ && (file->flags & FLAG_XFER_DIR))
delete_in_dir(the_file_list, fname, file, &real_st);
return;
}
- if (preserve_hard_links && file->link_u.links
+ if (preserve_hard_links && IS_HLINKED(file)
&& hard_link_check(file, ndx, fname, statret, &st,
itemizing, code, HL_CHECK_MASTER))
return;
if (preserve_links && S_ISLNK(file->mode)) {
#ifdef SUPPORT_LINKS
- if (safe_symlinks && unsafe_symlink(file->u.link, fname)) {
+ const char *sl = F_SYMLINK(file);
+ if (safe_symlinks && unsafe_symlink(sl, fname)) {
if (verbose) {
if (the_file_list->count == 1)
fname = f_name(file, NULL);
rprintf(FINFO,
"ignoring unsafe symlink %s -> \"%s\"\n",
- full_fname(fname), file->u.link);
+ full_fname(fname), sl);
}
return;
}
if (!S_ISLNK(st.st_mode))
statret = -1;
else if ((len = readlink(fname, lnk, MAXPATHLEN-1)) > 0
- && strncmp(lnk, file->u.link, len) == 0
- && file->u.link[len] == '\0') {
+ && strncmp(lnk, sl, len) == 0 && sl[len] == '\0') {
/* The link is pointing to the right place. */
if (itemizing)
itemize(file, ndx, 0, &st, 0, 0, NULL);
set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
- if (preserve_hard_links && file->link_u.links)
- hard_link_cluster(file, ndx, itemizing, code);
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, -1);
if (remove_source_files == 1)
goto return_with_success;
return;
} else if (j >= 0)
statret = 1;
}
- if (preserve_hard_links && file->link_u.links
+ if (preserve_hard_links && IS_HLINKED(file)
&& hard_link_check(file, ndx, fname, -1, &st,
itemizing, code, HL_SKIP))
return;
- if (do_symlink(file->u.link, fname) != 0) {
+ if (do_symlink(sl, fname) != 0) {
rsyserr(FERROR, errno, "symlink %s -> \"%s\" failed",
- full_fname(fname), file->u.link);
+ full_fname(fname), sl);
} else {
set_file_attrs(fname, file, NULL, 0);
if (itemizing) {
ITEM_LOCAL_CHANGE, 0, NULL);
}
if (code != FNONE && verbose)
- rprintf(code, "%s -> %s\n", fname, file->u.link);
- if (preserve_hard_links && file->link_u.links)
- hard_link_cluster(file, ndx, itemizing, code);
+ rprintf(code, "%s -> %s\n", fname, sl);
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, -1);
/* This does not check remove_source_files == 1
* because this is one of the items that the old
* --remove-sent-files option would remove. */
if ((am_root && preserve_devices && IS_DEVICE(file->mode))
|| (preserve_specials && IS_SPECIAL(file->mode))) {
+ dev_t rdev = MAKEDEV(F_DMAJOR(file), F_DMINOR(file));
if (statret == 0) {
char *t;
if (IS_DEVICE(file->mode)) {
}
if (statret == 0
&& (st.st_mode & ~CHMOD_BITS) == (file->mode & ~CHMOD_BITS)
- && st.st_rdev == file->u.rdev) {
+ && st.st_rdev == rdev) {
/* The device or special file is identical. */
if (itemizing)
itemize(file, ndx, 0, &st, 0, 0, NULL);
set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
- if (preserve_hard_links && file->link_u.links)
- hard_link_cluster(file, ndx, itemizing, code);
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, -1);
if (remove_source_files == 1)
goto return_with_success;
return;
} else if (j >= 0)
statret = 1;
}
- if (preserve_hard_links && file->link_u.links
+ if (preserve_hard_links && IS_HLINKED(file)
&& hard_link_check(file, ndx, fname, -1, &st,
itemizing, code, HL_SKIP))
return;
if (verbose > 2) {
rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
- fname, (int)file->mode, (int)file->u.rdev);
+ fname, (int)file->mode, (int)rdev);
}
- if (do_mknod(fname, file->mode, file->u.rdev) < 0) {
+ if (do_mknod(fname, file->mode, rdev) < 0) {
rsyserr(FERROR, errno, "mknod %s failed",
full_fname(fname));
} else {
}
if (code != FNONE && verbose)
rprintf(code, "%s\n", fname);
- if (preserve_hard_links && file->link_u.links)
- hard_link_cluster(file, ndx, itemizing, code);
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, -1);
if (remove_source_files == 1)
goto return_with_success;
}
}
if (statret != 0) {
- if (preserve_hard_links && file->link_u.links
+ if (preserve_hard_links && IS_HLINKED(file)
&& hard_link_check(file, ndx, fname, statret, &st,
itemizing, code, HL_SKIP))
return;
0, 0, NULL);
}
set_file_attrs(fname, file, &st, maybe_ATTRS_REPORT);
- if (preserve_hard_links && file->link_u.links)
- hard_link_cluster(file, ndx, itemizing, code);
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, -1);
if (remove_source_files != 1)
return;
return_with_success:
if (fuzzy_dirlist) {
int j = flist_find(fuzzy_dirlist, file);
if (j >= 0) /* don't use changing file as future fuzzy basis */
- fuzzy_dirlist->files[j]->flags |= FLAG_NO_FUZZY;
+ fuzzy_dirlist->files[j]->flags |= FLAG_SENT;
}
/* open the file */
full_fname(fnamecmp));
pretend_missing:
/* pretend the file didn't exist */
- if (preserve_hard_links && file->link_u.links
+ if (preserve_hard_links && IS_HLINKED(file)
&& hard_link_check(file, ndx, fname, statret, &st,
itemizing, code, HL_SKIP))
return;
if (robust_unlink(backupptr) && errno != ENOENT) {
rsyserr(FERROR, errno, "unlink %s",
full_fname(backupptr));
- free(back_file);
+ unmake_file(back_file);
close(fd);
return;
}
O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0600)) < 0) {
rsyserr(FERROR, errno, "open %s",
full_fname(backupptr));
- free(back_file);
+ unmake_file(back_file);
close(fd);
return;
}
}
if (!do_xfers) {
- if (preserve_hard_links && file->link_u.links)
- hard_link_cluster(file, ndx, itemizing, code);
+ if (preserve_hard_links && IS_HLINKED(file))
+ hard_link_cluster(file, ndx, itemizing, code, -1);
return;
}
if (read_batch)
rprintf(FINFO, "backed up %s to %s\n",
fname, backupptr);
}
- free(back_file);
+ unmake_file(back_file);
}
close(fd);
if (verbose > 2)
rprintf(FINFO,"generate_files phase=%d\n",phase);
- write_int(f_out, -1);
+ write_int(f_out, NDX_DONE);
/* files can cycle through the system more than once
* to catch initial checksum errors */
if (verbose > 2)
rprintf(FINFO,"generate_files phase=%d\n",phase);
- write_int(f_out, -1);
+ write_int(f_out, NDX_DONE);
/* Reduce round-trip lag-time for a useless delay-updates phase. */
if (protocol_version >= 29 && !delay_updates)
- write_int(f_out, -1);
+ write_int(f_out, NDX_DONE);
/* Read MSG_DONE for the redo phase (and any prior messages). */
get_redo_num(itemizing, code);
if (verbose > 2)
rprintf(FINFO, "generate_files phase=%d\n", phase);
if (delay_updates)
- write_int(f_out, -1);
+ write_int(f_out, NDX_DONE);
/* Read MSG_DONE for delay-updates phase & prior messages. */
get_redo_num(itemizing, code);
}
continue;
if (!need_retouch_dir_times && file->mode & S_IWUSR)
continue;
- if (file->flags & FLAG_MISSING) {
+ if (file->flags & FLAG_MISSING_DIR) {
int missing = file->dir.depth;
while (++i < flist->count) {
file = flist->files[i];
#include "rsync.h"
extern int verbose;
+extern int dry_run;
extern int do_xfers;
extern int link_dest;
extern int make_backups;
+extern int flist_extra_ndx;
extern int remove_source_files;
extern int stdout_format_has_i;
extern char *basis_dir[];
#define FINISHED_LINK (-2)
#define FPTR(i) (the_file_list->files[i])
-#define LINKED(p1,p2) (FPTR(p1)->F_DEV == FPTR(p2)->F_DEV \
- && FPTR(p1)->F_INODE == FPTR(p2)->F_INODE)
+#define LINKED(i1,i2) ((i1)->dev == (i2)->dev && (i1)->ino == (i2)->ino)
static int hlink_compare(int *int1, int *int2)
{
struct file_struct *f1 = FPTR(*int1);
struct file_struct *f2 = FPTR(*int2);
+ struct idev *i1 = F_IDEV(f1);
+ struct idev *i2 = F_IDEV(f2);
- if (f1->F_DEV != f2->F_DEV)
- return (int) (f1->F_DEV > f2->F_DEV ? 1 : -1);
+ if (i1->dev != i2->dev)
+ return (int)(i1->dev > i2->dev ? 1 : -1);
- if (f1->F_INODE != f2->F_INODE)
- return (int) (f1->F_INODE > f2->F_INODE ? 1 : -1);
+ if (i1->ino != i2->ino)
+ return (int)(i1->ino > i2->ino ? 1 : -1);
return f_name_cmp(f1, f2);
}
* linked, and replace the dev+inode data with the hlindex+next linked list. */
static void link_idev_data(void)
{
- int32 cur, from, to, start;
+ int32 from, to, start;
+ struct file_struct *file, *file_next;
+ struct idev *idev, *idev_next;
+ struct hlist *hl;
alloc_pool_t hlink_pool;
alloc_pool_t idev_pool = the_file_list->hlink_pool;
- hlink_pool = pool_create(128 * 1024, sizeof (struct hlink), out_of_memory, POOL_INTERN);
+ hlink_pool = pool_create(128 * 1024, sizeof (struct hlist), out_of_memory, POOL_INTERN);
for (from = to = 0; from < hlink_count; from++) {
start = from;
- while (1) {
- cur = hlink_list[from];
- if (from == hlink_count-1
- || !LINKED(cur, hlink_list[from+1]))
+ for (file = FPTR(hlink_list[from]), idev = F_IDEV(file);
+ from < hlink_count-1;
+ file = file_next, idev = idev_next)
+ {
+ file_next = FPTR(hlink_list[from+1]);
+ idev_next = F_IDEV(file_next);
+ if (!LINKED(idev, idev_next))
break;
- pool_free(idev_pool, 0, FPTR(cur)->link_u.idev);
- FPTR(cur)->link_u.links = pool_talloc(hlink_pool,
- struct hlink, 1, "hlink_list");
-
- FPTR(cur)->F_HLINDEX = to;
- FPTR(cur)->F_NEXT = hlink_list[++from];
- FPTR(cur)->link_u.links->link_dest_used = 0;
+ pool_free(idev_pool, 0, idev);
+ hl = pool_talloc(hlink_pool, struct hlist, 1,
+ "hlink_list");
+ hl->hlindex = to;
+ hl->next = hlink_list[++from];
+ hl->dest_used = 0;
+ F_HLIST(file) = hl;
}
- pool_free(idev_pool, 0, FPTR(cur)->link_u.idev);
+ pool_free(idev_pool, 0, idev);
if (from > start) {
int head = hlink_list[start];
- FPTR(cur)->link_u.links = pool_talloc(hlink_pool,
- struct hlink, 1, "hlink_list");
-
- FPTR(head)->flags |= FLAG_HLINK_TOL;
- FPTR(cur)->F_HLINDEX = to;
- FPTR(cur)->F_NEXT = head;
- FPTR(cur)->flags |= FLAG_HLINK_EOL;
- FPTR(cur)->link_u.links->link_dest_used = 0;
+ hl = pool_talloc(hlink_pool, struct hlist, 1,
+ "hlink_list");
+ FPTR(head)->flags |= FLAG_HLINK_FIRST;
+ hl->hlindex = to;
+ hl->next = head;
+ hl->dest_used = 0;
hlink_list[to++] = head;
+ file->flags |= FLAG_HLINK_LAST;
+ F_HLIST(file) = hl;
} else
- FPTR(cur)->link_u.links = NULL;
+ file->flags &= ~FLAG_HLINK_INFO;
}
if (!to) {
hlink_count = 0;
for (i = 0; i < the_file_list->count; i++) {
- if (FPTR(i)->link_u.idev)
+ if (IS_HLINKED(FPTR(i)))
hlink_list[hlink_count++] = i;
}
{
#ifdef SUPPORT_HARD_LINKS
int head;
- if (skip && !(file->flags & FLAG_HLINK_EOL))
- head = hlink_list[file->F_HLINDEX] = file->F_NEXT;
+ struct hlist *hl = F_HLIST(file);
+
+ if (skip && !(file->flags & FLAG_HLINK_LAST))
+ head = hlink_list[hl->hlindex] = hl->next;
else
- head = hlink_list[file->F_HLINDEX];
+ head = hlink_list[hl->hlindex];
if (ndx != head) {
struct file_struct *head_file = FPTR(head);
+ struct hlist *hf_hl = F_HLIST(head_file);
if (!stdout_format_has_i && verbose > 1) {
rprintf(FINFO, "\"%s\" is a hard link\n",
f_name(file, NULL));
}
- if (head_file->F_HLINDEX == FINISHED_LINK) {
+ if (hf_hl->hlindex == FINISHED_LINK) {
STRUCT_STAT st2, st3;
char toname[MAXPATHLEN];
- int ldu = head_file->link_u.links->link_dest_used;
+ int ldu = hf_hl->dest_used;
if (ldu) {
pathjoin(toname, MAXPATHLEN, basis_dir[ldu-1],
f_name(head_file, NULL));
SIVAL(numbuf, 0, ndx);
send_msg(MSG_SUCCESS, numbuf, 4);
}
- file->F_HLINDEX = FINISHED_LINK;
+ hl->hlindex = FINISHED_LINK;
} else
- file->F_HLINDEX = SKIPPED_LINK;
+ hl->hlindex = SKIPPED_LINK;
return 1;
}
#endif
void hard_link_cluster(struct file_struct *file, int master, int itemizing,
- enum logcode code)
+ enum logcode code, int dest_used)
{
#ifdef SUPPORT_HARD_LINKS
char hlink1[MAXPATHLEN];
char *hlink2;
STRUCT_STAT st1, st2;
int statret, ndx = master;
+ struct hlist *hl = F_HLIST(file);
- file->F_HLINDEX = FINISHED_LINK;
+ hl->hlindex = FINISHED_LINK;
+ if (dry_run)
+ hl->dest_used = dest_used + 1;
if (link_stat(f_name(file, hlink1), &st1, 0) < 0)
return;
- if (!(file->flags & FLAG_HLINK_TOL)) {
- while (!(file->flags & FLAG_HLINK_EOL)) {
- ndx = file->F_NEXT;
+ if (!(file->flags & FLAG_HLINK_FIRST)) {
+ while (!(file->flags & FLAG_HLINK_LAST)) {
+ ndx = hl->next;
file = FPTR(ndx);
+ hl = F_HLIST(file);
}
}
do {
- ndx = file->F_NEXT;
+ ndx = hl->next;
file = FPTR(ndx);
- if (file->F_HLINDEX != SKIPPED_LINK)
+ hl = F_HLIST(file);
+ if (hl->hlindex != SKIPPED_LINK)
continue;
hlink2 = f_name(file, NULL);
statret = link_stat(hlink2, &st2, 0);
SIVAL(numbuf, 0, ndx);
send_msg(MSG_SUCCESS, numbuf, 4);
}
- file->F_HLINDEX = FINISHED_LINK;
- } while (!(file->flags & FLAG_HLINK_EOL));
+ hl->hlindex = FINISHED_LINK;
+ } while (!(file->flags & FLAG_HLINK_LAST));
#endif
}
extern int allow_8bit_chars;
extern int protocol_version;
extern int preserve_times;
+extern int preserve_uid;
+extern int preserve_gid;
+extern int flist_extra_ndx;
+extern int file_struct_len;
extern int stdout_format_has_i;
extern int stdout_format_has_o_or_i;
extern int logfile_format_has_i;
case 'U':
strlcat(fmt, "ld", sizeof fmt);
snprintf(buf2, sizeof buf2, fmt,
- (long)file->uid);
+ preserve_uid ? (long)F_UID(file) : 0);
n = buf2;
break;
case 'G':
- if (file->gid == GID_NONE)
+ if (!preserve_gid || F_GID(file) == GID_NONE)
n = "DEFAULT";
else {
strlcat(fmt, "ld", sizeof fmt);
snprintf(buf2, sizeof buf2, fmt,
- (long)file->gid);
+ (long)F_GID(file));
n = buf2;
}
break;
if (hlink && *hlink) {
n = hlink;
strlcpy(buf2, " => ", sizeof buf2);
- } else if (S_ISLNK(file->mode) && file->u.link) {
- n = file->u.link;
+ } else if (S_ISLNK(file->mode)) {
+ n = F_SYMLINK(file);
strlcpy(buf2, " -> ", sizeof buf2);
} else {
n = "";
}
}
- if (i != -1) {
+ if (i != NDX_DONE) {
rprintf(FERROR, "Invalid packet at end of run (%d) [%s]\n",
i, who_am_i());
exit_cleanup(RERR_PROTOCOL);
io_flush(FULL_FLUSH);
if (protocol_version >= 24) {
/* send a final goodbye message */
- write_int(f_out, -1);
+ write_int(f_out, NDX_DONE);
}
io_flush(FULL_FLUSH);
int inplace = 0;
int delay_updates = 0;
long block_size = 0; /* "long" because popt can't set an int32. */
-
+int flist_extra_ndx = 1; /* index of optional file-list items */
/** Network address family. **/
#ifdef INET6
need_messages_from_generator = 1;
}
+ if (preserve_uid)
+ preserve_uid = flist_extra_ndx++;
+ if (preserve_gid)
+ preserve_gid = flist_extra_ndx++;
+
*argv = poptGetArgs(pc);
*argc = count_args(*argv);
extern int preserve_perms;
extern int basis_dir_cnt;
extern int make_backups;
+extern int flist_extra_ndx;
extern int cleanup_got_literal;
extern int remove_source_files;
extern int append_mode;
full_fname(fname), partialptr);
} else {
if (remove_source_files
- || (preserve_hard_links
- && file->link_u.links)) {
+ || (preserve_hard_links && IS_HLINKED(file))) {
SIVAL(numbuf, 0, i);
send_msg(MSG_SUCCESS,numbuf,4);
}
cleanup_disable();
i = read_int(f_in);
- if (i == -1) {
+ if (i == NDX_DONE) {
if (read_batch) {
get_next_gen_i(batch_gen_fd, next_gen_i,
flist->count);
if (recv_ok > 0) {
if (remove_source_files
- || (preserve_hard_links && file->link_u.links)) {
+ || (preserve_hard_links && IS_HLINKED(file))) {
SIVAL(numbuf, 0, i);
send_msg(MSG_SUCCESS, numbuf, 4);
}
updated = 1;
}
- change_uid = am_root && preserve_uid && st->st_uid != file->uid;
- change_gid = preserve_gid && file->gid != GID_NONE
- && st->st_gid != file->gid;
+ change_uid = am_root && preserve_uid && st->st_uid != F_UID(file);
+ change_gid = preserve_gid && F_GID(file) != GID_NONE
+ && st->st_gid != F_GID(file);
#if !defined HAVE_LCHOWN && !defined CHOWN_MODIFIES_SYMLINK
if (S_ISLNK(st->st_mode))
;
rprintf(FINFO,
"set uid of %s from %ld to %ld\n",
fname,
- (long)st->st_uid, (long)file->uid);
+ (long)st->st_uid, (long)F_UID(file));
}
if (change_gid) {
rprintf(FINFO,
"set gid of %s from %ld to %ld\n",
fname,
- (long)st->st_gid, (long)file->gid);
+ (long)st->st_gid, (long)F_GID(file));
}
}
if (do_lchown(fname,
- change_uid ? file->uid : st->st_uid,
- change_gid ? file->gid : st->st_gid) != 0) {
+ change_uid ? F_UID(file) : st->st_uid,
+ change_gid ? F_GID(file) : st->st_gid) != 0) {
/* shouldn't have attempted to change uid or gid
* unless have the privilege */
rsyserr(FERROR, errno, "%s %s failed",
/* These flags are used in the live flist data. */
-#define FLAG_TOP_DIR (1<<0)
-#define FLAG_SENT (1<<1) /* sender */
-#define FLAG_HLINK_EOL (1<<1) /* receiver/generator */
-#define FLAG_MOUNT_POINT (1<<2) /* sender/generator */
-#define FLAG_DEL_HERE (1<<3) /* receiver/generator */
-#define FLAG_HLINK_TOL (1<<4) /* receiver/generator */
-#define FLAG_NO_FUZZY (1<<5) /* generator */
-#define FLAG_MISSING (1<<6) /* generator */
+#define FLAG_TOP_DIR (1<<0) /* sender/receiver/generator */
+#define FLAG_SENT (1<<1) /* sender/generator */
+#define FLAG_XFER_DIR (1<<2) /* sender/receiver/generator */
+#define FLAG_MOUNT_DIR (1<<3) /* sender/generator */
+#define FLAG_MISSING_DIR (1<<4) /* generator (dirs only) */
+#define FLAG_HLINK_INFO (1<<5) /* receiver/generator */
+#define FLAG_HLINK_FIRST (1<<6) /* receiver/generator */
+#define FLAG_HLINK_LAST (1<<7) /* receiver/generator */
/* update this if you make incompatible changes */
#define PROTOCOL_VERSION 30
MSG_DONE=86 /* current phase is done */
};
+#define NDX_DONE -1
+
#include "errcode.h"
#include "config.h"
*/
struct idev {
- int64 inode;
+ int64 ino;
int64 dev;
};
#define HL_CHECK_MASTER 0
#define HL_SKIP 1
-struct hlink {
+struct hlist {
int32 next;
int32 hlindex;
- unsigned short link_dest_used;
+ unsigned short dest_used;
};
-#define F_DEV link_u.idev->dev
-#define F_INODE link_u.idev->inode
-
-#define F_HLINDEX link_u.links->hlindex
-#define F_NEXT link_u.links->next
-
struct file_struct {
- union {
- dev_t rdev; /* The device number, if this is a device */
- const char *sum;/* Only a normal file can have a checksum */
- const char *link;/* Points to symlink string, if a symlink */
- } u;
OFF_T length;
const char *basename; /* The current item's name (AKA filename) */
const char *dirname; /* The directory info inside the transfer */
const char *root;/* Sender-side dir info outside transfer */
int depth; /* Receiver-side directory depth info */
} dir;
- union {
- struct idev *idev;
- struct hlink *links;
- } link_u;
time_t modtime;
- uid_t uid;
- gid_t gid;
mode_t mode;
uchar flags; /* this item MUST remain last */
};
#define FLIST_START (32 * 1024)
#define FLIST_LINEAR (FLIST_START * 512)
+union flist_extras {
+ uid_t uid; /* the user ID number */
+ uid_t gid; /* the group ID number or GID_NONE */
+ struct idev *idev; /* The hard-link info during matching */
+ struct hlist *hlist; /* The hard-link info after matching */
+ int32 num; /* A general-purpose number */
+};
+
+#define FLIST_EXTRA(f,j) ((union flist_extras *)(f))[-(j)]
+#define IS_HLINKED(f) ((f)->flags & FLAG_HLINK_INFO)
+
+/* When enabled, all entries have these: */
+#define F_UID(f) FLIST_EXTRA(f, preserve_uid).uid
+#define F_GID(f) FLIST_EXTRA(f, preserve_gid).gid
+
+/* These are per-entry optional and mutally exclusive: */
+#define F_IDEV(f) FLIST_EXTRA(f, flist_extra_ndx).idev
+#define F_HLIST(f) FLIST_EXTRA(f, flist_extra_ndx).hlist
+
+/* These are per-entry optional, but always both or neither: */
+#define F_DMAJOR(f) FLIST_EXTRA(f, flist_extra_ndx + (IS_HLINKED(f)? 1 : 0)).num
+#define F_DMINOR(f) FLIST_EXTRA(f, flist_extra_ndx + (IS_HLINKED(f)? 2 : 1)).num
+
+/* This is the first string past the struct (mutually exclusive). */
+#define F_SYMLINK(f) ((char*)(f) + file_struct_len)
+#define F_SUM(f) F_SYMLINK(f)
+
/*
- * Extent size for allocation pools A minimum size of 128KB
+ * Extent size for allocation pools: A minimum size of 128KB
* is needed to mmap them so that freeing will release the
* space to the OS.
*
* Larger sizes reduce leftover fragments and speed free calls
- * (when they happen) Smaller sizes increase the chance of
+ * (when they happen). Smaller sizes increase the chance of
* freed allocations freeing whole extents.
*/
#define FILE_EXTENT (256 * 1024)
struct file_struct **files;
alloc_pool_t file_pool;
alloc_pool_t hlink_pool;
- int count;
- int malloced;
- int low, high;
+ int count, malloced;
+ int low, high; /* 0-relative index values excluding empties */
};
#define SUMFLG_SAME_OFFSET (1<<0)
#if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
#define snprintf rsync_snprintf
-int snprintf(char *str,size_t count,const char *fmt,...);
+int snprintf(char *str, size_t count, const char *fmt,...);
#endif
unsigned int offset;
i = read_int(f_in);
- if (i == -1) {
+ if (i == NDX_DONE) {
if (++phase > max_phase)
break;
csum_length = SUM_LENGTH;
if (verbose > 2)
rprintf(FINFO, "send_files phase=%d\n", phase);
- write_int(f_out, -1);
+ write_int(f_out, NDX_DONE);
/* For inplace: redo phase turns off the backup
* flag so that we do a regular inplace send. */
make_backups = 0;
match_report();
- write_int(f_out, -1);
+ write_int(f_out, NDX_DONE);
}
{
struct idlist *list;
- if (numeric_ids)
- return;
-
if (preserve_uid) {
int len;
/* we send sequences of uid/byte-length/name */
/* Now convert all the uids/gids from sender values to our values. */
if (am_root && preserve_uid && !numeric_ids) {
for (i = 0; i < flist->count; i++)
- flist->files[i]->uid = match_uid(flist->files[i]->uid);
+ F_UID(flist->files[i]) = match_uid(F_UID(flist->files[i]));
}
if (preserve_gid && (!am_root || !numeric_ids)) {
for (i = 0; i < flist->count; i++)
- flist->files[i]->gid = match_gid(flist->files[i]->gid);
+ F_GID(flist->files[i]) = match_gid(F_GID(flist->files[i]));
}
}