Subject: bug#6131: [PATCH]: fiemap support for efficient sparse file copy

From: Jim Meyering <[email-masked]>
Date: Wed, 02 Jun 2010 09:27:53 +0200

Jim Meyering wrote:
...
>>> Do you know of a tool other than filefrag that I could use?
>> nope.
>>>
>>> It looks like a small script could filter filefrag -v output, detect
>>> split extents and rewrite to make the output match what's expected.
>>> Probably not worth it, though, since this is already a very fragile test.
>
> I went ahead and did it, after all.
> Here's the script, filefrag-extent-compare.
> With it, this test should pass when run on any of those four
> file system types.

Not quite.
Parsing filefrag -v output is part of what is fragile.

Here are two examples:

==> ff1 <==
Filesystem type is: ef53
File size of j1 is 49152 (12 blocks, blocksize 4096)
 ext logical physical expected length flags
   0       3 10256380               3
   1       9 10740733 10256382      3 eof

==> ff2 <==
Filesystem type is: ef53
File size of j2 is 49152 (12 blocks, blocksize 4096)
 ext logical physical expected length flags
   0       3 10283520               3
   1       9 10283523               3 eof
                       ^^^^^^
Note the missing "expected" number.
That doesn't happen often, but it's enough to cause occasional
false-positive failures, since the awk filter counts fields.
I don't dare try to count columns, because those physical block
numbers are likely to have width greater than 8 some of the time.

Instead, I adjusted the filter to remove the "eof"
and let the existing awk code handle the rest:

# Extract logical block number and length pairs from filefrag -v output.
# The initial sed is to remove the "eof" from the normally-empty "flags" field.
# That is required when that final extent has no number in the "expected" field.
f()
{
  sed 's/ eof$//' $@ \
    | awk '/^ *[0-9]/ {printf "%d %d ", $2 ,NF < 5 ? $NF : $5 } END {print ""}'
}

I'll post a new patch soon.