Skip to contentSkip to conversation

filefrag: fix extent count calculation when using FIBMAP

PATCH New Theodore Ts'o 1 participant 1 message Aug 13, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 filefrag: fix extent count calculation when using FIBMAP

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

---
 misc/filefrag.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
misc/filefrag.c +3 -2
index d71bf43..c1a8684 100644
@@ -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;
 			(*num_extents)++;
 		} 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;
 			(*num_extents)++;
 		}
+		fm_ext.fe_logical = logical;
+		fm_ext.fe_physical = block * st->st_blksize;
 		fm_ext.fe_length += st->st_blksize;
 		last_block = block;
 	}
Signature · 1 line
2.0.0