diff mbox

[V2] filefrag: count 0 extents properly when verbose

Message ID 4DC2EA94.8040100@redhat.com
State Accepted, archived
Headers show

Commit Message

Eric Sandeen May 5, 2011, 6:21 p.m. UTC
# rm -f a; touch a; filefrag a
/boot/a: 0 extents found

works properly, but

# rm -f a; touch a; filefrag -v a
Filesystem type is: ef53
Filesystem cylinder groups is approximately 61
File size of a is 0 (0 blocks, blocksize 1024)
 ext logical physical expected length flags
a: 1 extent found

yields 1 extent when it should be 0.

Fix this up by special-casing no extents returned in verbose
mode; skip printing the header for the columns too, since there
are no columns to print.

Also, in nonverbose mode we can set fm_extent_count to 0
so that FIEMAP will just query the extent count without gathering
details; clarify this with a comment.

Addresses-redhat-bugzilla: 653234
Signed-off-by: Eric Sandeen <sandeen@redhat.com>


--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Theodore Ts'o May 7, 2011, 10:45 p.m. UTC | #1
On Thu, May 05, 2011 at 01:21:08PM -0500, Eric Sandeen wrote:
> # rm -f a; touch a; filefrag a
> /boot/a: 0 extents found
> 
> works properly, but
> 
> # rm -f a; touch a; filefrag -v a
> Filesystem type is: ef53
> Filesystem cylinder groups is approximately 61
> File size of a is 0 (0 blocks, blocksize 1024)
>  ext logical physical expected length flags
> a: 1 extent found
> 
> yields 1 extent when it should be 0.
> 
> Fix this up by special-casing no extents returned in verbose
> mode; skip printing the header for the columns too, since there
> are no columns to print.
> 
> Also, in nonverbose mode we can set fm_extent_count to 0
> so that FIEMAP will just query the extent count without gathering
> details; clarify this with a comment.
> 
> Addresses-redhat-bugzilla: 653234
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Thanks, 

applied to the maint branch (which will then get pulled to
master/next) of e2fsprogs.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Andreas Dilger May 8, 2011, 3:35 a.m. UTC | #2
I was going to comment on this on Friday and supply a new patch but got distracted. There is actually a cleaner way to implement this, by initializing the extent count to zero, and always incrementing it inside the inner loop. That simplifies the case when there are no extents returned by FIEMAP.

I'm sure I'll get around to sending an updated patch at some point, and will clean up this section at the same time. 

Cheers, Andreas

On 2011-05-07, at 4:45 PM, Ted Ts'o <tytso@mit.edu> wrote:

> On Thu, May 05, 2011 at 01:21:08PM -0500, Eric Sandeen wrote:
>> # rm -f a; touch a; filefrag a
>> /boot/a: 0 extents found
>> 
>> works properly, but
>> 
>> # rm -f a; touch a; filefrag -v a
>> Filesystem type is: ef53
>> Filesystem cylinder groups is approximately 61
>> File size of a is 0 (0 blocks, blocksize 1024)
>> ext logical physical expected length flags
>> a: 1 extent found
>> 
>> yields 1 extent when it should be 0.
>> 
>> Fix this up by special-casing no extents returned in verbose
>> mode; skip printing the header for the columns too, since there
>> are no columns to print.
>> 
>> Also, in nonverbose mode we can set fm_extent_count to 0
>> so that FIEMAP will just query the extent count without gathering
>> details; clarify this with a comment.
>> 
>> Addresses-redhat-bugzilla: 653234
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> 
> Thanks, 
> 
> applied to the maint branch (which will then get pulled to
> master/next) of e2fsprogs.
> 
>                    - Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/misc/filefrag.c b/misc/filefrag.c
index d604b6c..2795e15 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -180,6 +180,10 @@  static int filefrag_fiemap(int fd, int blk_shift, int *num_extents)
 
 	memset(fiemap, 0, sizeof(struct fiemap));
 
+	/*
+	 * If count (and therefore fm_extent_count) == 0, FIEMAP
+	 * returns count of extents found without filling in details.
+	 */
 	if (!verbose)
 		count = 0;
 
@@ -204,6 +208,14 @@  static int filefrag_fiemap(int fd, int blk_shift, int *num_extents)
 		}
 
 		if (verbose && !fiemap_header_printed) {
+			/*
+			 * No extents on first call?
+			 * Skip header and show 0 extents.
+			 */
+			if (fiemap->fm_mapped_extents == 0) {
+				*num_extents = 0;
+				goto out;
+			}
 			printf(" ext %*s %*s %*s length flags\n", logical_width,
 			       "logical", physical_width, "physical",
 			       physical_width, "expected");