diff options
author | Nikolay Borisov <nborisov@suse.com> | 2017-08-24 16:43:44 -0500 |
---|---|---|
committer | Eric Sandeen <sandeen@redhat.com> | 2017-08-24 16:43:44 -0500 |
commit | e7eaacefff8bc4968143400ba2450abe6ce8d8d5 (patch) | |
tree | c16753feef35e15482755cd6def9a7f75492ef1e | |
parent | abd0c76667e705604b2a82f4a17cbeba4478ca98 (diff) | |
download | xfsprogs-dev-e7eaacefff8bc4968143400ba2450abe6ce8d8d5.tar.gz |
fiemap: Fix semantics of max_extents (-n arguments)
Currently the semantics of the -n argument are a bit idiosyncratic. We want the
argument to be the limit of extents that are going to be output by the tool. This
is clearly broken now as evident from the following example on a fragmented file:
xfs_io -c "fiemap -v -n 5" test-dir/fragmented-file
test-dir/fragmented-file:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..15]: hole 16
1: [16..23]: 897847296..897847303 8 0x0
2: [24..31]: hole 8
3: [32..39]: 897851392..897851399 8 0x0
So we want at most 5 extents printed, yet we get 4. So we always print n - 1
extents.
With this modification the output looks like:
xfs_io -c "fiemap -v -n 5" test-dir/fragmented-file
test-dir/fragmented-file:
EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS
0: [0..15]: hole 16
1: [16..23]: 897847296..897847303 8 0x0
2: [24..31]: hole 8
3: [32..39]: 897851392..897851399 8 0x0
4: [40..47]: hole 8
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
[sandeen: fix initialization of max_extents]
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
-rw-r--r-- | io/fiemap.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/io/fiemap.c b/io/fiemap.c index 44a64870d7..e6fd66da75 100644 --- a/io/fiemap.c +++ b/io/fiemap.c @@ -26,7 +26,7 @@ #define EXTENT_BATCH 32 static cmdinfo_t fiemap_cmd; -static int max_extents = 0; +static int max_extents = -1; static void fiemap_help(void) @@ -122,7 +122,7 @@ print_verbose( cur_extent++; } - if ((cur_extent + 1) == max_extents) + if (cur_extent == max_extents) return 1; snprintf(lbuf, sizeof(lbuf), "[%llu..%llu]:", lstart, @@ -157,7 +157,7 @@ print_plain( cur_extent++; } - if ((cur_extent + 1) == max_extents) + if (cur_extent == max_extents) return 1; printf("\t%d: [%llu..%llu]: %llu..%llu", cur_extent, @@ -264,7 +264,7 @@ fiemap_f( printf("%s:\n", file->name); - while (!last && ((cur_extent + 1) != max_extents)) { + while (!last && (cur_extent != max_extents)) { memset(fiemap, 0, map_size); fiemap->fm_flags = fiemap_flags; @@ -314,12 +314,12 @@ fiemap_f( break; } - if ((cur_extent + 1) == max_extents) + if (cur_extent == max_extents) break; } } - if ((cur_extent + 1) == max_extents) + if (cur_extent == max_extents) goto out; memset(&st, 0, sizeof(st)); |