filefrag shows wrong number of extents

Bug #1356496 reported by Nick Rose on 2014-08-13
This bug affects 1 person
Affects Status Importance Assigned to Milestone
e2fsprogs (Ubuntu)

Bug Description

Package: E2fsprogs version 1.42.8

In NTFS (and possibly other non-Linux filesystems), adding a '-v' switch to the filefrag command gives a different result from executing the command without the '-v' switch, for the same file.

For example:

$ sudo filefrag 1 extent found

$ sudo filefrag -v
Filesystem type is: 65735546
File size of is 38347615 (9363 blocks of 4096 bytes)
Discontinuity: Block 1727 is at 53086291 (was 53063600)
Discontinuity: Block 2547 is at 53168245 (was 53087111)
Discontinuity: Block 4398 is at 53184685 (was 53170096)
Discontinuity: Block 6193 is at 53276776 (was 53186480)
Discontinuity: Block 6297 is at 53289023 (was 53276880)
Discontinuity: Block 6422 is at 53344771 (was 53289148)
Discontinuity: Block 7875 is at 53369116 (was 53346224) 8 extents found

This has nothing to do with file system buffers, since this file has been on the disk for several months.

This bug report says that the problem is fixed in E2fsprogs version 1.41:
but I think it has been fixed only for ext* file systems, since the problem exists with E2fsprogs version 1.42.8, with NTFS, but not with ext4. I think the problem also exists with FAT file systems, but I can't currently check this.

Nick Rose (nkre5) wrote :

I forgot to mention:

Although E2fsprogs version 1.42.8 is not the latest version, the problem isn't mentioned in any of the subsequent E2fsprogs release notes, so it obviously hasn't been fixed yet.

Theodore Ts'o (tytso) wrote :

Confirmed on an NTFS file system. It applies for those file systems that do not support the FIEMAP ioctl, and so filefrag has to fall back to the legacy (and far more inefficient) FIBMAP ioctl.

Changed in e2fsprogs (Ubuntu):
status: New → Confirmed

The extent count calculation works correctly with the FIBMAP ioctl in
verbose (-v) mode, but without the verbose option, the calculation was
broken because we weren't properly updating the fm_ext data structures
in non-verbose mode.

Addresses-Launchpad-Bug: #1356496

Signed-off-by: Theodore Ts'o <email address hidden>
 misc/filefrag.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/misc/filefrag.c b/misc/filefrag.c
index d71bf43..c1a8684 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -329,16 +329,17 @@ static int filefrag_fibmap(int fd, int blk_shift, int *num_extents,
    print_extent_info(&fm_ext, *num_extents - 1,
        (last_block + 1) * st->st_blksize,
        blk_shift, st);
- fm_ext.fe_logical = logical;
- fm_ext.fe_physical = block * st->st_blksize;
    fm_ext.fe_length = 0;
   } else if (last_block && (block != last_block + 1)) {
    if (verbose)
     printf("Discontinuity: Block %ld is at %lu (was "
            "%lu)\n", i, block, last_block + 1);
+ fm_ext.fe_length = 0;
+ fm_ext.fe_logical = logical;
+ fm_ext.fe_physical = block * st->st_blksize;
   fm_ext.fe_length += st->st_blksize;
   last_block = block;

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers