From a00be17e4768c5ce55f74be518f35f5d5d1b158b Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 30 Sep 2011 18:43:39 -0400 Subject: [PATCH] filefrag: Display the number of contiguous, not physical, extents From a bug report filed by Ibragimov Rinat: When filefrag uses FIEMAP ioctl its logic differs for ordinary and verbose (-v) modes. ext4 returns extent on every 32768 block so on large files it is possible that `filefrag large-file' tells about 4 extents while `filefrag -v large-file' finds only one. Also when I tried to use generic_block_fiemap function to add FIEMAP for reiserfs, every block was reported as a new extent resulting in thousands "extents" for continuous files. I think filefrag should merge adjacent extents even when -v is not specified. Addresses-Debian-Bug: #631498 Signed-off-by: "Theodore Ts'o" --- misc/filefrag.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/misc/filefrag.c b/misc/filefrag.c index 8441757..0131bf2 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -223,11 +223,6 @@ static int filefrag_fiemap(int fd, int blk_shift, int *num_extents) fiemap_header_printed = 1; } - if (!verbose) { - *num_extents = fiemap->fm_mapped_extents; - goto out; - } - /* If 0 extents are returned, then more ioctls are not needed */ if (fiemap->fm_mapped_extents == 0) break; @@ -244,7 +239,9 @@ static int filefrag_fiemap(int fd, int blk_shift, int *num_extents) tot_extents++; else last_blk = 0; - print_extent_info(&fm_ext[i], n, last_blk, blk_shift); + if (verbose) + print_extent_info(&fm_ext[i], n, last_blk, + blk_shift); last_blk = phy_blk + ext_len - 1; if (fm_ext[i].fe_flags & FIEMAP_EXTENT_LAST) -- 1.8.3.1