+struct file_struct {
+ 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 */
+ uint32 unum; /* An unsigned number */
+ } extras[1];
+ time_t modtime; /* When the item was last modified */
+ const char *dirname; /* The dir info inside the transfer */
+ union {
+ const char *root; /* Sender-side dir info outside transfer */
+ int32 depth; /* Receiver-side directory depth info */
+ } dir;
+ uint32 len32; /* Lowest 32 bits of the file's length */
+ unsigned short mode; /* The item's type and permissions */
+ unsigned short flags; /* This item MUST remain last! */
+};
+
+extern int flist_extra_cnt;
+extern int preserve_uid;
+extern int preserve_gid;
+
+#define FILE_STRUCT_LEN (offsetof(struct file_struct, flags) \
+ + sizeof (unsigned short))
+#define EXTRA_LEN (sizeof (union flist_extras))
+#define SUM_EXTRA_CNT ((MD4_SUM_LENGTH + EXTRA_LEN - 1) / EXTRA_LEN)
+
+#define REQ_EXTRA(f,ndx) ((f)->extras - (ndx - 1))
+#define OPT_EXTRA(f,bump) ((f)->extras - flist_extra_cnt - (bump))
+#define LEN64_BUMP(f) ((f)->flags & FLAG_LENGTH64 ? 1 : 0)
+#define HLINK_BUMP(f) (F_IS_HLINKED(f) ? 1 : 0)
+
+/* Basename (AKA filename) and length applies to all items */
+#define F_BASENAME(f) ((const char*)(f) + FILE_STRUCT_LEN)
+#define F_LENGTH(f) ((OFF_T)(f)->len32 + ((f)->flags & FLAG_LENGTH64 \
+ ? (OFF_T)OPT_EXTRA(f, 0)->unum << 32 : 0u))
+
+/* If there is a symlink string, it is always right after the basename */
+#define F_SYMLINK(f) (F_BASENAME(f) + strlen(F_BASENAME(f)) + 1)
+
+/* When the associated option is on, all entries will have these present: */
+#define F_UID(f) REQ_EXTRA(f, preserve_uid)->uid
+#define F_GID(f) REQ_EXTRA(f, preserve_gid)->gid
+
+/* These are per-entry optional and mutally exclusive: */
+#define F_IDEV(f) OPT_EXTRA(f, LEN64_BUMP(f))->idev
+#define F_HLIST(f) OPT_EXTRA(f, LEN64_BUMP(f))->hlist
+
+/* These are per-entry optional, but always both or neither:
+ * (Note: a device doesn't need to use LEN64_BUMP(f).) */
+#define F_DMAJOR(f) OPT_EXTRA(f, HLINK_BUMP(f))->unum
+#define F_DMINOR(f) OPT_EXTRA(f, HLINK_BUMP(f) + 1)->unum
+
+/* The sum is only present on regular files. */
+#define F_SUM(f) ((const char*)OPT_EXTRA(f, LEN64_BUMP(f) + HLINK_BUMP(f) \
+ + SUM_EXTRA_CNT - 1))
+
+/* A couple bool-type utility functions: */
+#define F_IS_HLINKED(f) ((f)->flags & FLAG_HLINKED)
+#define F_IS_ACTIVE(f) F_BASENAME(f)[0]
+
+/*
+ * Start the flist array at FLIST_START entries and grow it
+ * by doubling until FLIST_LINEAR then grow by FLIST_LINEAR
+ */
+#define FLIST_START (32 * 1024)
+#define FLIST_LINEAR (FLIST_START * 512)
+
+/*
+ * 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
+ * freed allocations freeing whole extents.
+ */
+#define FILE_EXTENT (256 * 1024)
+#define HLINK_EXTENT (128 * 1024)
+
+#define WITH_HLINK 1
+#define WITHOUT_HLINK 0
+