1 eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
2 & eval 'exec perl -wS "$0" $argv:q'
4 # Determine whether two files have the same extents by comparing
5 # the logical block numbers and lengths from filefrag -v for each.
8 # This helper function, f, extracts logical block number and lengths.
9 # f() { awk '/^ *[0-9]/ {printf "%d %d ",$2,NF<5?$NF:$5} END {print ""}'; }
10 # { filefrag -v j1 | f; filefrag -v j2 | f; } | ./filefrag-extent-compare
14 (my $ME = $0) =~ s|.*/||;
19 or die "$ME: expected exactly two input lines; got $n_lines\n";
21 my @A = split ' ', $line[0];
22 my @B = split ' ', $line[1];
24 and die "$ME: unexpected input: odd number of numbers; expected even\n";
28 foreach my $i (0..@A/2-1) { $a[$i] = { L_BLK => $A[2*$i], LEN => $A[2*$i+1] } };
29 foreach my $i (0..@B/2-1) { $b[$i] = { L_BLK => $B[2*$i], LEN => $B[2*$i+1] } };
31 # Merge adjacent extents in array E.
41 $e->[$i]->{L_BLK} + $e->[$i]->{LEN} != $e->[$i+1]->{L_BLK}
44 $e->[$i]->{LEN} += $e->[$i+1]->{LEN};
54 or die "$ME: extent counts differ, even after adjustment\n";
57 while (defined $a[$i])
59 my $start_match = $a[$i]->{L_BLK} == $b[$i]->{L_BLK};
60 my $len_match = $a[$i]->{LEN} == $b[$i]->{LEN};
61 if ( ! ($start_match && ($len_match || $i == (@a - 1))))
63 # On XFS on Linux kernel 2.6.38, it was seen that the size of the
64 # last extent can vary, and can extend beyond the length of the file.
65 # So we ignore the length of the last extent, because if the
66 # file is the wrong length we'll get failures elsewhere.
67 die "$ME: differing extent:\n"
68 . " [$i]=$a[$i]->{L_BLK} $a[$i]->{LEN}\n"
69 . " [$i]=$b[$i]->{L_BLK} $b[$i]->{LEN}\n";
74 ### Setup "GNU" style for perl-mode and cperl-mode.
77 ## perl-indent-level: 2
78 ## perl-continued-statement-offset: 2
79 ## perl-continued-brace-offset: 0
80 ## perl-brace-offset: 0
81 ## perl-brace-imaginary-offset: 0
82 ## perl-label-offset: -2
83 ## perl-extra-newline-before-brace: t
84 ## perl-merge-trailing-else: nil