Applied to the main code as option --outbuf=N|L|B.
[rsync-patches.git] / link-by-hash.diff
index ae06c75a679f20b300b383f66a44f98577f1d7f4..e0b7078ac653fa45566ead8d4532122753f163b7 100644 (file)
@@ -1,9 +1,9 @@
 Jason M. Felice wrote:
 
-This patch adds the --link-by-hash=DIR option, which hard links received
-files in a link farm arranged by MD4 file hash.  The result is that the system
-will only store one copy of the unique contents of each file, regardless of
-the file's name.
+This patch adds the --link-by-hash=DIR option, which hard links received files
+in a link farm arranged by MD4 or MD5 file hash.  The result is that the system
+will only store one copy of the unique contents of each file, regardless of the
+file's name.
 
 To use this patch, run these commands for a successful build:
 
@@ -12,7 +12,7 @@ To use this patch, run these commands for a successful build:
     ./configure
     make
 
-based-on: 28b519c93b6db30b6520d46f8cd65160213fddd2
+based-on: 60ef39705797c9df7069297eb4ed5feab5e88f29
 diff --git a/Makefile.in b/Makefile.in
 --- a/Makefile.in
 +++ b/Makefile.in
@@ -25,31 +25,88 @@ diff --git a/Makefile.in b/Makefile.in
  DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
  popt_OBJS=popt/findme.o  popt/popt.o  popt/poptconfig.o \
        popt/popthelp.o popt/poptparse.o
-diff --git a/flist.c b/flist.c
---- a/flist.c
-+++ b/flist.c
-@@ -72,6 +72,7 @@ extern int unsort_ndx;
- extern uid_t our_uid;
- extern struct stats stats;
- extern char *filesfrom_host;
-+extern char *link_by_hash_dir;
- extern char *usermap, *groupmap;
+diff --git a/checksum.c b/checksum.c
+--- a/checksum.c
++++ b/checksum.c
+@@ -21,6 +21,7 @@
  
- extern char curr_dir[MAXPATHLEN];
-@@ -910,7 +911,7 @@ static struct file_struct *recv_file_entry(int f, struct file_list *flist, int x
-               extra_len += EXTRA_LEN;
- #endif
+ #include "rsync.h"
++extern int checksum_len;
+ extern int checksum_seed;
+ extern int protocol_version;
  
--      if (always_checksum && S_ISREG(mode))
-+      if ((always_checksum || link_by_hash_dir) && S_ISREG(mode))
-               extra_len += SUM_EXTRA_CNT * EXTRA_LEN;
+@@ -221,3 +222,24 @@ int sum_end(char *sum)
  
- #if SIZEOF_INT64 >= 8
+       return MD4_DIGEST_LEN;
+ }
++
++const char *sum_as_hex(const char *sum)
++{
++      static char buf[MAX_DIGEST_LEN*2+1];
++      int i, x1, x2;
++      char *c = buf + checksum_len*2;
++
++      assert(c - buf < (int)sizeof buf);
++
++      *c = '\0';
++
++      for (i = checksum_len; --i >= 0; ) {
++              x1 = CVAL(sum, i);
++              x2 = x1 >> 4;
++              x1 &= 0xF;
++              *--c = x1 <= 9 ? x1 + '0' : x1 + 'a' - 10;
++              *--c = x2 <= 9 ? x2 + '0' : x2 + 'a' - 10;
++      }
++
++      return buf;
++}
+diff --git a/clientserver.c b/clientserver.c
+--- a/clientserver.c
++++ b/clientserver.c
+@@ -50,6 +50,7 @@ extern int logfile_format_has_i;
+ extern int logfile_format_has_o_or_i;
+ extern char *bind_address;
+ extern char *config_file;
++extern char *link_by_hash_dir;
+ extern char *logfile_format;
+ extern char *files_from;
+ extern char *tmpdir;
+@@ -551,6 +552,9 @@ static int rsync_module(int f_in, int f_out, int i, const char *addr, const char
+               return -1;
+       }
++      if (*lp_link_by_hash_dir(i))
++              link_by_hash_dir = lp_link_by_hash_dir(i);
++
+       if (am_daemon && am_server) {
+               rprintf(FLOG, "rsync allowed access on module %s from %s (%s)\n",
+                       name, host, addr);
+diff --git a/compat.c b/compat.c
+--- a/compat.c
++++ b/compat.c
+@@ -55,6 +55,7 @@ extern char *partial_dir;
+ extern char *dest_option;
+ extern char *files_from;
+ extern char *filesfrom_host;
++extern char *link_by_hash_dir;
+ extern filter_rule_list filter_list;
+ extern int need_unsorted_flist;
+ #ifdef ICONV_OPTION
+@@ -328,4 +329,8 @@ void setup_protocol(int f_out,int f_in)
+       } else {
+               checksum_seed = read_int(f_in);
+       }
++      if (!am_sender && link_by_hash_dir && protocol_version < 30 && checksum_seed != 1) {
++              rprintf(FERROR, "You must specify --checksum-seed=1 when using --link-by-hash with an old version of rsync.\n");
++              exit_cleanup(RERR_PROTOCOL);
++      }
+ }
 diff --git a/hashlink.c b/hashlink.c
 new file mode 100644
 --- /dev/null
 +++ b/hashlink.c
-@@ -0,0 +1,339 @@
+@@ -0,0 +1,334 @@
 +/*
 +   Copyright (C) Cronosys, LLC 2004
 +
@@ -73,37 +130,26 @@ new file mode 100644
 +#include "rsync.h"
 +
 +extern char *link_by_hash_dir;
++extern char sender_file_sum[MAX_DIGEST_LEN];
 +
 +#ifdef HAVE_LINK
 +
-+char *make_hash_name(struct file_struct *file)
++/* This function is always called after a file is received, so the
++ * sender_file_sum buffer has whatever the last checksum was for the
++ * transferred file. */
++static char *make_hash_name(void)
 +{
-+      char hash[33], *dst;
-+      uchar c, *src = (uchar*)F_SUM(file);
-+      int i;
-+
-+      for (dst = hash, i = 0; i < 4; i++, src++) {
-+              c = *src >> 4;
-+              *(dst++) = (c >= 10) ? (c - 10 + 'a') : (c + '0');
-+              c = *src & 0x0f;
-+              *(dst++) = (c >= 10) ? (c - 10 + 'a') : (c + '0');
-+      }
-+      *dst++ = '/';
-+      for (i = 0; i < 12; i++, src++) {
-+              c = *src >> 4;
-+              *(dst++) = (c >= 10) ? (c - 10 + 'a') : (c + '0');
-+              c = *src & 0x0f;
-+              *(dst++) = (c >= 10) ? (c - 10 + 'a') : (c + '0');
-+      }
-+      *dst = 0;
++      const char *hex = sum_as_hex(sender_file_sum);
++      char *dst;
 +
-+      if (asprintf(&dst,"%s/%s",link_by_hash_dir,hash) < 0)
++      if (asprintf(&dst, "%s/%.8s/%s", link_by_hash_dir, hex, hex+8) < 0)
 +              out_of_memory("make_hash_name");
++
 +      return dst;
 +}
 +
 +
-+void kill_hashfile(struct hashfile_struct *hashfile)
++static void kill_hashfile(struct hashfile_struct *hashfile)
 +{
 +      if (!hashfile)
 +              return;
@@ -113,7 +159,7 @@ new file mode 100644
 +}
 +
 +
-+void kill_hashfiles(struct hashfile_struct *hashfiles)
++static void kill_hashfiles(struct hashfile_struct *hashfiles)
 +{
 +      struct hashfile_struct *iter, *next;
 +      if ((iter = hashfiles) != NULL) {
@@ -126,7 +172,7 @@ new file mode 100644
 +}
 +
 +
-+struct hashfile_struct *find_hashfiles(char *hashname, int64 size, long *fnbr)
++static struct hashfile_struct *find_hashfiles(char *hashname, int64 size, long *fnbr)
 +{
 +      DIR *d;
 +      struct dirent *di;
@@ -188,7 +234,7 @@ new file mode 100644
 +}
 +
 +
-+struct hashfile_struct *compare_hashfiles(int fd,struct hashfile_struct *files)
++static struct hashfile_struct *compare_hashfiles(int fd,struct hashfile_struct *files)
 +{
 +      int amt, hamt;
 +      char buffer[BUFSIZ], cmpbuffer[BUFSIZ];
@@ -273,7 +319,7 @@ new file mode 100644
 +int link_by_hash(const char *fnametmp, const char *fname, struct file_struct *file)
 +{
 +      STRUCT_STAT st;
-+      char *hashname = make_hash_name(file);
++      char *hashname = make_hash_name();
 +      int first = 0, rc;
 +      char *linkname;
 +      long last_fnbr;
@@ -304,7 +350,8 @@ new file mode 100644
 +              first = 1;
 +              if (asprintf(&linkname,"%s/0",hashname) < 0)
 +                      out_of_memory("link_by_hash");
-+              rprintf(FINFO, "(1) linkname = %s\n", linkname);
++              if (DEBUG_GTE(HASHLINK, 2))
++                      rprintf(FINFO, "(1) linkname = %s\n", linkname);
 +      } else {
 +              struct hashfile_struct *hashfiles, *hashfile;
 +
@@ -318,7 +365,8 @@ new file mode 100644
 +                      first = 1;
 +                      if (asprintf(&linkname,"%s/0",hashname) < 0)
 +                              out_of_memory("link_by_hash");
-+                      rprintf(FINFO, "(2) linkname = %s\n", linkname);
++                      if (DEBUG_GTE(HASHLINK, 2))
++                              rprintf(FINFO, "(2) linkname = %s\n", linkname);
 +              } else {
 +                      int fd;
 +                      /* Search for one identical to us. */
@@ -334,20 +382,22 @@ new file mode 100644
 +                      if (hashfile) {
 +                              first = 0;
 +                              linkname = strdup(hashfile->name);
-+                              rprintf(FINFO, "(3) linkname = %s\n", linkname);
++                              if (DEBUG_GTE(HASHLINK, 2))
++                                      rprintf(FINFO, "(3) linkname = %s\n", linkname);
 +                              kill_hashfile(hashfile);
 +                      } else {
 +                              first = 1;
 +                              if (asprintf(&linkname, "%s/%ld", hashname, last_fnbr + 1) < 0)
 +                                      out_of_memory("link_by_hash");
-+                              rprintf(FINFO, "(4) linkname = %s\n", linkname);
++                              if (DEBUG_GTE(HASHLINK, 2))
++                                      rprintf(FINFO, "(4) linkname = %s\n", linkname);
 +                      }
 +              }
 +      }
 +
 +      if (!first) {
-+              rprintf(FINFO, "link-by-hash (existing): \"%s\" -> %s\n",
-+                              linkname, full_fname(fname));
++              if (DEBUG_GTE(HASHLINK, 2))
++                      rprintf(FINFO, "link-by-hash (existing): \"%s\" -> %s\n", linkname, full_fname(fname));
 +              robust_unlink(fname);
 +              rc = do_link(linkname, fname);
 +              if (rc == -1) {
@@ -356,8 +406,10 @@ new file mode 100644
 +                              free(linkname);
 +                              if (asprintf(&linkname,"%s/%ld",hashname, last_fnbr + 1) < 0)
 +                                      out_of_memory("link_by_hash");
-+                              rprintf(FINFO, "(5) linkname = %s\n", linkname);
-+                              rprintf(FINFO,"link-by-hash: max link count exceeded, starting new file \"%s\".\n", linkname);
++                              if (DEBUG_GTE(HASHLINK, 2))
++                                      rprintf(FINFO, "(5) linkname = %s\n", linkname);
++                              if (DEBUG_GTE(HASHLINK, 1))
++                                      rprintf(FINFO, "link-by-hash: max link count exceeded, starting new file \"%s\".\n", linkname);
 +                      } else {
 +                              rsyserr(FERROR, errno, "link \"%s\" -> \"%s\"",
 +                                      linkname, full_fname(fname));
@@ -369,8 +421,8 @@ new file mode 100644
 +      }
 +
 +      if (first) {
-+              rprintf(FINFO, "link-by-hash (new): %s -> \"%s\"\n",
-+                              full_fname(fname),linkname);
++              if (DEBUG_GTE(HASHLINK, 2))
++                      rprintf(FINFO, "link-by-hash (new): %s -> \"%s\"\n", full_fname(fname),linkname);
 +
 +              rc = robust_rename(fnametmp, fname, NULL, 0644);
 +              if (rc != 0) {
@@ -389,6 +441,70 @@ new file mode 100644
 +      return rc;
 +}
 +#endif
+diff --git a/loadparm.c b/loadparm.c
+--- a/loadparm.c
++++ b/loadparm.c
+@@ -119,6 +119,7 @@ typedef struct {
+       char *include;
+       char *include_from;
+       char *incoming_chmod;
++      char *link_by_hash_dir;
+       char *lock_file;
+       char *log_file;
+       char *log_format;
+@@ -195,6 +196,7 @@ static const all_vars Defaults = {
+  /* include; */                       NULL,
+  /* include_from; */          NULL,
+  /* incoming_chmod; */                NULL,
++ /* link_by_hash_dir; */      NULL,
+  /* lock_file; */             DEFAULT_LOCK_FILE,
+  /* log_file; */              NULL,
+  /* log_format; */            "%o %h [%a] %m (%u) %f %l",
+@@ -336,6 +338,7 @@ static struct parm_struct parm_table[] =
+  {"include from",      P_STRING, P_LOCAL, &Vars.l.include_from,        NULL,0},
+  {"include",           P_STRING, P_LOCAL, &Vars.l.include,             NULL,0},
+  {"incoming chmod",    P_STRING, P_LOCAL, &Vars.l.incoming_chmod,      NULL,0},
++ {"link by hash dir",  P_STRING, P_LOCAL, &Vars.l.link_by_hash_dir,    NULL,0},
+  {"list",              P_BOOL,   P_LOCAL, &Vars.l.list,                NULL,0},
+  {"lock file",         P_STRING, P_LOCAL, &Vars.l.lock_file,           NULL,0},
+  {"log file",          P_STRING, P_LOCAL, &Vars.l.log_file,            NULL,0},
+@@ -464,6 +467,7 @@ FN_LOCAL_STRING(lp_hosts_deny, hosts_deny)
+ FN_LOCAL_STRING(lp_include, include)
+ FN_LOCAL_STRING(lp_include_from, include_from)
+ FN_LOCAL_STRING(lp_incoming_chmod, incoming_chmod)
++FN_LOCAL_STRING(lp_link_by_hash_dir, link_by_hash_dir)
+ FN_LOCAL_STRING(lp_lock_file, lock_file)
+ FN_LOCAL_STRING(lp_log_file, log_file)
+ FN_LOCAL_STRING(lp_log_format, log_format)
+diff --git a/log.c b/log.c
+--- a/log.c
++++ b/log.c
+@@ -683,23 +683,14 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
+                       if (protocol_version >= 30
+                        && (iflags & ITEM_TRANSFER
+                         || (always_checksum && S_ISREG(file->mode)))) {
+-                              int i, x1, x2;
+                               const char *sum = iflags & ITEM_TRANSFER
+                                               ? sender_file_sum : F_SUM(file);
+-                              c = buf2 + checksum_len*2;
+-                              *c = '\0';
+-                              for (i = checksum_len; --i >= 0; ) {
+-                                      x1 = CVAL(sum, i);
+-                                      x2 = x1 >> 4;
+-                                      x1 &= 0xF;
+-                                      *--c = x1 <= 9 ? x1 + '0' : x1 + 'a' - 10;
+-                                      *--c = x2 <= 9 ? x2 + '0' : x2 + 'a' - 10;
+-                              }
++                              n = sum_as_hex(sum);
+                       } else {
+                               memset(buf2, ' ', checksum_len*2);
+                               buf2[checksum_len*2] = '\0';
++                              n = buf2;
+                       }
+-                      n = buf2;
+                       break;
+               case 'i':
+                       if (iflags & ITEM_DELETED) {
 diff --git a/options.c b/options.c
 --- a/options.c
 +++ b/options.c
@@ -400,7 +516,24 @@ diff --git a/options.c b/options.c
  char *config_file = NULL;
  char *shell_cmd = NULL;
  char *logfile_name = NULL;
-@@ -758,6 +759,7 @@ void usage(enum logcode F)
+@@ -208,7 +209,7 @@ static const char *debug_verbosity[] = {
+       /*2*/ "BIND,CMD,CONNECT,DEL,DELTASUM,DUP,FILTER,FLIST,ICONV",
+       /*3*/ "ACL,BACKUP,CONNECT2,DELTASUM2,DEL2,EXIT,FILTER2,FLIST2,FUZZY,GENR,OWN,RECV,SEND,TIME",
+       /*4*/ "CMD2,DELTASUM3,DEL3,EXIT2,FLIST3,ICONV2,OWN2,PROTO,TIME2",
+-      /*5*/ "CHDIR,DELTASUM4,FLIST4,FUZZY2,HASH,HLINK",
++      /*5*/ "CHDIR,DELTASUM4,FLIST4,FUZZY2,HASH,HASHLINK,HLINK",
+ };
+ #define MAX_VERBOSITY ((int)(sizeof debug_verbosity / sizeof debug_verbosity[0]) - 1)
+@@ -278,6 +279,7 @@ static struct output_struct debug_words[COUNT_DEBUG+1] = {
+       DEBUG_WORD(FUZZY, W_REC, "Debug fuzzy scoring (levels 1-2)"),
+       DEBUG_WORD(GENR, W_REC, "Debug generator functions"),
+       DEBUG_WORD(HASH, W_SND|W_REC, "Debug hashtable code"),
++      DEBUG_WORD(HASHLINK, W_REC, "Debug hashlink code (levels 1-2)"),
+       DEBUG_WORD(HLINK, W_SND|W_REC, "Debug hard-link actions (levels 1-3)"),
+       DEBUG_WORD(ICONV, W_CLI|W_SRV, "Debug iconv character conversions (levels 1-2)"),
+       DEBUG_WORD(IO, W_CLI|W_SRV, "Debug I/O routines (levels 1-4)"),
+@@ -759,6 +761,7 @@ void usage(enum logcode F)
    rprintf(F,"     --compare-dest=DIR      also compare destination files relative to DIR\n");
    rprintf(F,"     --copy-dest=DIR         ... and include copies of unchanged files\n");
    rprintf(F,"     --link-dest=DIR         hardlink to files in DIR when unchanged\n");
@@ -408,7 +541,7 @@ diff --git a/options.c b/options.c
    rprintf(F," -z, --compress              compress file data during the transfer\n");
    rprintf(F,"     --compress-level=NUM    explicitly set compression level\n");
    rprintf(F,"     --skip-compress=LIST    skip compressing files with a suffix in LIST\n");
-@@ -810,7 +812,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
+@@ -811,7 +814,7 @@ enum {OPT_VERSION = 1000, OPT_DAEMON, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
        OPT_FILTER, OPT_COMPARE_DEST, OPT_COPY_DEST, OPT_LINK_DEST, OPT_HELP,
        OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW, OPT_MIN_SIZE, OPT_CHMOD,
        OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_ONLY_WRITE_BATCH, OPT_MAX_SIZE,
@@ -417,15 +550,25 @@ diff --git a/options.c b/options.c
        OPT_USERMAP, OPT_GROUPMAP, OPT_CHOWN, OPT_BWLIMIT,
        OPT_SERVER, OPT_REFUSED_BASE = 9000};
  
-@@ -954,6 +956,7 @@ static struct poptOption long_options[] = {
+@@ -955,6 +958,7 @@ static struct poptOption long_options[] = {
    {"compare-dest",     0,  POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
    {"copy-dest",        0,  POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
    {"link-dest",        0,  POPT_ARG_STRING, 0, OPT_LINK_DEST, 0, 0 },
 +  {"link-by-hash",     0,  POPT_ARG_STRING, 0, OPT_LINK_BY_HASH, 0, 0},
-   {"fuzzy",           'y', POPT_ARG_VAL,    &fuzzy_basis, 1, 0, 0 },
+   {"fuzzy",           'y', POPT_ARG_NONE,   0, 'y', 0, 0 },
    {"no-fuzzy",         0,  POPT_ARG_VAL,    &fuzzy_basis, 0, 0, 0 },
    {"no-y",             0,  POPT_ARG_VAL,    &fuzzy_basis, 0, 0, 0 },
-@@ -1780,6 +1783,21 @@ int parse_arguments(int *argc_p, const char ***argv_p)
+@@ -1299,6 +1303,9 @@ int parse_arguments(int *argc_p, const char ***argv_p)
+               iconv_opt = strdup(arg);
+ #endif
++      if (*lp_link_by_hash_dir(module_id))
++              set_refuse_options("link-by-hash");
++
+       /* TODO: Call poptReadDefaultConfig; handle errors. */
+       /* The context leaks in case of an error, but if there's a
+@@ -1785,6 +1792,21 @@ int parse_arguments(int *argc_p, const char ***argv_p)
                        return 0;
  #endif
  
@@ -447,7 +590,7 @@ diff --git a/options.c b/options.c
                default:
                        /* A large opt value means that set_refuse_options()
                         * turned this option off. */
-@@ -2662,6 +2680,11 @@ void server_options(char **args, int *argc_p)
+@@ -2675,6 +2697,11 @@ void server_options(char **args, int *argc_p)
        } else if (inplace)
                args[ac++] = "--inplace";
  
@@ -459,80 +602,6 @@ diff --git a/options.c b/options.c
        if (files_from && (!am_sender || filesfrom_host)) {
                if (filesfrom_host) {
                        args[ac++] = "--files-from";
-diff --git a/receiver.c b/receiver.c
---- a/receiver.c
-+++ b/receiver.c
-@@ -217,11 +217,13 @@ int open_tmpfile(char *fnametmp, const char *fname, struct file_struct *file)
- }
- static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
--                      const char *fname, int fd, OFF_T total_size)
-+                      const char *fname, int fd, OFF_T total_size,
-+                      const char *md4)
- {
-       static char file_sum1[MAX_DIGEST_LEN];
-       struct map_struct *mapbuf;
-       struct sum_struct sum;
-+      md_context mdfour_data;
-       int32 len;
-       OFF_T offset = 0;
-       OFF_T offset2;
-@@ -257,6 +259,9 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
-       } else
-               mapbuf = NULL;
-+      if (md4)
-+              mdfour_begin(&mdfour_data);
-+
-       sum_init(checksum_seed);
-       if (append_mode > 0) {
-@@ -304,6 +309,8 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
-                       cleanup_got_literal = 1;
-                       sum_update(data, i);
-+                      if (md4)
-+                              mdfour_update(&mdfour_data, (uchar*)data, i);
-                       if (fd != -1 && write_file(fd,data,i) != i)
-                               goto report_write_error;
-@@ -331,6 +338,8 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
-                       see_token(map, len);
-                       sum_update(map, len);
-+                      if (md4)
-+                              mdfour_update(&mdfour_data, (uchar*)map, len);
-               }
-               if (updating_basis_or_equiv) {
-@@ -384,6 +393,9 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
-       if (sum_end(file_sum1) != checksum_len)
-               overflow_exit("checksum_len"); /* Impossible... */
-+      if (md4)
-+              mdfour_result(&mdfour_data, (uchar*)md4);
-+
-       if (mapbuf)
-               unmap_file(mapbuf);
-@@ -398,7 +410,7 @@ static int receive_data(int f_in, char *fname_r, int fd_r, OFF_T size_r,
- static void discard_receive_data(int f_in, OFF_T length)
- {
--      receive_data(f_in, NULL, -1, 0, NULL, -1, length);
-+      receive_data(f_in, NULL, -1, 0, NULL, -1, length, NULL);
- }
- static void handle_delayed_updates(char *local_name)
-@@ -828,7 +840,7 @@ int recv_files(int f_in, int f_out, char *local_name)
-               /* recv file data */
-               recv_ok = receive_data(f_in, fnamecmp, fd1, st.st_size,
--                                     fname, fd2, F_LENGTH(file));
-+                                     fname, fd2, F_LENGTH(file), F_SUM(file));
-               log_item(log_code, file, iflags, NULL);
 diff --git a/rsync.c b/rsync.c
 --- a/rsync.c
 +++ b/rsync.c
@@ -561,7 +630,7 @@ diff --git a/rsync.c b/rsync.c
 diff --git a/rsync.h b/rsync.h
 --- a/rsync.h
 +++ b/rsync.h
-@@ -899,6 +899,14 @@ struct stats {
+@@ -909,6 +909,14 @@ struct stats {
        int xferred_files;
  };
  
@@ -576,10 +645,20 @@ diff --git a/rsync.h b/rsync.h
  struct chmod_mode_struct;
  
  struct flist_ndx_item {
+@@ -1263,7 +1271,8 @@ extern short info_levels[], debug_levels[];
+ #define DEBUG_FUZZY (DEBUG_FLIST+1)
+ #define DEBUG_GENR (DEBUG_FUZZY+1)
+ #define DEBUG_HASH (DEBUG_GENR+1)
+-#define DEBUG_HLINK (DEBUG_HASH+1)
++#define DEBUG_HASHLINK (DEBUG_HASH+1)
++#define DEBUG_HLINK (DEBUG_HASHLINK+1)
+ #define DEBUG_ICONV (DEBUG_HLINK+1)
+ #define DEBUG_IO (DEBUG_ICONV+1)
+ #define DEBUG_OWN (DEBUG_IO+1)
 diff --git a/rsync.yo b/rsync.yo
 --- a/rsync.yo
 +++ b/rsync.yo
-@@ -402,6 +402,7 @@ to the detailed description below for a complete description.  verb(
+@@ -416,6 +416,7 @@ to the detailed description below for a complete description.  verb(
       --compare-dest=DIR      also compare received files relative to DIR
       --copy-dest=DIR         ... and include copies of unchanged files
       --link-dest=DIR         hardlink to files in DIR when unchanged
@@ -587,3 +666,40 @@ diff --git a/rsync.yo b/rsync.yo
   -z, --compress              compress file data during the transfer
       --compress-level=NUM    explicitly set compression level
       --skip-compress=LIST    skip compressing files with suffix in LIST
+@@ -1830,6 +1831,19 @@ bf(--link-dest) from working properly for a non-super-user when bf(-o) was
+ specified (or implied by bf(-a)).  You can work-around this bug by avoiding
+ the bf(-o) option when sending to an old rsync.
++dit(bf(--link-by-hash=DIR)) This option hard links the destination files into
++em(DIR), a link farm arranged by MD5 file hash (or sometimes MD4). The result
++is that the system will only store one copy of the unique contents of each
++file, regardless of the file's name.
++
++For a modern rsync (3.0.0 and newer), the link farm's directory hierarchy is
++determined by the file's MD5 hash.  It is recommended that you don't use this
++option with any rsync older than that.  However, if you really need to be able
++to interact with an older rsync on the sending side, you can use the options
++bf(--checksum-seed=1) and bf(--protocol=29) to force a consistent MD4 file
++checksum that will be used instead of MD5.  Note that this MD4 checksum is not
++compatible with older versions of this patch (prior to 3.1.0).
++
+ dit(bf(-z, --compress)) With this option, rsync compresses the file data
+ as it is sent to the destination machine, which reduces the amount of data
+ being transmitted -- something that is useful over a slow connection.
+diff --git a/rsyncd.conf.yo b/rsyncd.conf.yo
+--- a/rsyncd.conf.yo
++++ b/rsyncd.conf.yo
+@@ -283,6 +283,13 @@ message telling them to try later.  The default is 0, which means no limit.
+ A negative value disables the module.
+ See also the "lock file" parameter.
++dit(bf(link by hash dir)) When the "link by hash dir" parameter is set to a
++non-empty string, received files will be hard linked into em(DIR), a link farm
++arranged by MD5 file hash (or sometimes MD4). See the bf(--link-by-hash) option
++for a full explaination.  If this parameter is set it will disable the
++bf(--link-by-hash) command-line option. The default is for this parameter to be
++unset.
++
+ dit(bf(log file)) When the "log file" parameter is set to a non-empty
+ string, the rsync daemon will log messages to the indicated file rather
+ than using syslog. This is particularly useful on systems (such as AIX)