1 This patch is the start of storing/using checksum information from
2 extended attribute values. The rsync code only reads the values
3 at the moment. There is also a perl script that can create them.
5 To use this patch, run these commands for a successful build:
7 patch -p1 <patches/checksum-xattr.diff
8 ./configure (optional if already run)
11 diff --git a/flist.c b/flist.c
12 index 09b4fc5..3295724 100644
15 @@ -1268,7 +1268,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
18 if (always_checksum && am_sender && S_ISREG(st.st_mode)) {
19 - file_checksum(thisname, tmp_sum, st.st_size);
20 + if (!get_sum_xattr(thisname, &st, tmp_sum))
21 + file_checksum(thisname, tmp_sum, st.st_size);
22 if (sender_keeps_checksum)
23 extra_len += SUM_EXTRA_CNT * EXTRA_LEN;
25 diff --git a/generator.c b/generator.c
26 index 12007a1..2587bc9 100644
29 @@ -531,7 +531,8 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
30 of the file time to determine whether to sync */
31 if (always_checksum > 0 && S_ISREG(st->st_mode)) {
32 char sum[MAX_DIGEST_LEN];
33 - file_checksum(fn, sum, st->st_size);
34 + if (!get_sum_xattr(fn, st, sum))
35 + file_checksum(fn, sum, st->st_size);
36 return memcmp(sum, F_SUM(file), checksum_len) == 0;
39 diff --git a/support/xsums b/support/xsums
41 index 0000000..31d2537
49 +use Cwd qw(abs_path cwd);
52 +use File::ExtAttr ':all';
54 +our($recurse_opt, $help_opt);
57 +&Getopt::Long::Configure('bundling');
58 +&usage if !&GetOptions(
59 + 'recurse|r' => \$recurse_opt,
60 + 'verbose|v+' => \$verbosity,
61 + 'help|h' => \$help_opt,
64 +my $start_dir = cwd();
67 +@dirs = '.' unless @dirs;
74 +my $md4 = Digest::MD4->new;
75 +my $md5 = Digest::MD5->new;
78 + my $dir = shift @dirs;
81 + warn "Unable to chdir to $dir: $!\n";
84 + if (!opendir(DP, '.')) {
85 + warn "Unable to opendir $dir: $!\n";
91 + $reldir =~ s#^$start_dir(/|$)# $1 ? '' : '.' #eo;
92 + print "scanning $reldir\n";
96 + while (defined(my $fn = readdir(DP))) {
97 + next if $fn =~ /^\.\.?$/ || -l $fn;
99 + push(@subdirs, "$dir/$fn");
104 + my($size,$mtime) = (stat(_))[7,9];
106 + my $sum4 = getfattr($fn, 'rsync.%md4');
107 + my $sum5 = getfattr($fn, 'rsync.%md5');
109 + foreach ($sum4, $sum5) {
111 + if (length($_) == 24) {
112 + my($sz,$mt,$sum) = unpack('V2a16', $_);
113 + if ($sz != ($size & 0xFFFFFFFF)
114 + || $mt != ($mtime & 0xFFFFFFFF)) {
124 + if (!defined($sum4) || !defined($sum5)) {
125 + if (!open(IN, $fn)) {
126 + print STDERR "Unable to read $fn: $!\n";
130 + while (sysread(IN, $_, 64*1024)) {
136 + $sum4 = $md4->digest;
137 + $sum5 = $md5->digest;
138 + print " $fn\n" if $verbosity > 1;
140 + my $szmt = pack('V2', $size, $mtime); # 32-bits, may truncate
141 + setfattr($fn, 'rsync.%md4', $szmt.$sum4);
142 + setfattr($fn, 'rsync.%md5', $szmt.$sum5);
143 + #utime $mtime, $mtime, $fn; # Set mtime if it changes.
149 + unshift(@dirs, sort @subdirs) if $recurse_opt;
155 +Usage: rsyncsums [OPTIONS] [DIRS]
158 + -r, --recurse Update checksums in subdirectories too.
159 + -v, --verbose Mention what we're doing. Repeat for more info.
160 + -h, --help Display this help message.
163 diff --git a/xattrs.c b/xattrs.c
164 index 2d0e050..f364a2a 100644
167 @@ -34,6 +34,8 @@ extern int read_only;
168 extern int list_only;
169 extern int preserve_xattrs;
170 extern int checksum_seed;
171 +extern int checksum_len;
172 +extern int protocol_version;
174 #define RSYNC_XAL_INITIAL 5
175 #define RSYNC_XAL_LIST_INITIAL 100
176 @@ -69,6 +71,10 @@ extern int checksum_seed;
177 #define XACC_ACL_ATTR RSYNC_PREFIX "%" XACC_ACL_SUFFIX
178 #define XDEF_ACL_SUFFIX "dacl"
179 #define XDEF_ACL_ATTR RSYNC_PREFIX "%" XDEF_ACL_SUFFIX
180 +#define MD4_SUFFIX "md4"
181 +#define MD4_ATTR RSYNC_PREFIX "%" MD4_SUFFIX
182 +#define MD5_SUFFIX "md5"
183 +#define MD5_ATTR RSYNC_PREFIX "%" MD5_SUFFIX
187 @@ -239,7 +245,9 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
189 && (strcmp(name+RPRE_LEN+1, XSTAT_SUFFIX) == 0
190 || strcmp(name+RPRE_LEN+1, XACC_ACL_SUFFIX) == 0
191 - || strcmp(name+RPRE_LEN+1, XDEF_ACL_SUFFIX) == 0)))
192 + || strcmp(name+RPRE_LEN+1, XDEF_ACL_SUFFIX) == 0
193 + || strcmp(name+RPRE_LEN+1, MD4_SUFFIX) == 0
194 + || strcmp(name+RPRE_LEN+1, MD5_SUFFIX) == 0)))
198 @@ -895,6 +903,39 @@ int del_def_xattr_acl(const char *fname)
202 +int get_sum_xattr(const char *fname, STRUCT_STAT *stp, char *sum)
204 + const char *mdattr = protocol_version >= 30
205 + ? MD5_ATTR : MD4_ATTR;
207 + uint32 file_length, mtime;
210 + len = sys_lgetxattr(fname, mdattr, buf, sizeof buf);
212 + if (errno == ENOTSUP || errno == ENOATTR)
214 + rsyserr(FERROR_XFER, errno, "failed to read xattr %s for %s",
215 + mdattr, full_fname(fname));
218 + if (len != 4 + 4 + checksum_len) {
219 + rprintf(FERROR, "Corrupt %s xattr attached to %s -- skipping\n",
220 + mdattr, full_fname(fname));
224 + file_length = IVAL(buf, 0); /* 32-bit values -- trunctions are OK */
225 + mtime = IVAL(buf, 4);
227 + if ((uint32)stp->st_size != file_length || (uint32)stp->st_mtime != mtime)
230 + memcpy(sum, buf + 8, checksum_len);
235 int get_stat_xattr(const char *fname, int fd, STRUCT_STAT *fst, STRUCT_STAT *xst)
237 int mode, rdev_major, rdev_minor, uid, gid, len;