CFR patch to improve fsdb sparse file handling

Don Lewis truckman at FreeBSD.org
Wed Feb 1 01:14:14 UTC 2012


A while back I noticed that fsdb bailed out early if it was asked to
print the block list for a file with a hole in its direct block list. At
the time I just commented out the early return.  Recently I had a chance
to revisit this code and came up with what I think is a better patch.
I thought it would be more informative to print out the NULL block
pointers to make it clear that the file is sparse even though the
existing code that handles the indirect blocks skips over the holes. The
code that printed the fragment count looked too much like an entry in an
obfuscated C contest, so I simplified it a bit.  I tried to match the
existing style instead of changing it to match style(9).

Index: sbin/fsdb/fsdbutil.c
===================================================================
--- sbin/fsdb/fsdbutil.c	(revision 230604)
+++ sbin/fsdb/fsdbutil.c	(working copy)
@@ -293,22 +293,21 @@
     printf("Blocks for inode %d:\n", inum);
     printf("Direct blocks:\n");
     ndb = howmany(DIP(dp, di_size), sblock.fs_bsize);
-    for (i = 0; i < NDADDR; i++) {
-	if (DIP(dp, di_db[i]) == 0) {
-	    putchar('\n');
-	    return;
-	}
+    for (i = 0; i < NDADDR && i < ndb; i++) {
 	if (i > 0)
 	    printf(", ");
 	blkno = DIP(dp, di_db[i]);
 	printf("%jd", (intmax_t)blkno);
-	if (--ndb == 0 && (offset = blkoff(&sblock, DIP(dp, di_size))) != 0) {
+    }
+    if (ndb <= NDADDR) {
+	offset = blkoff(&sblock, DIP(dp, di_size));
+	if (offset != 0) {
 	    nfrags = numfrags(&sblock, fragroundup(&sblock, offset));
 	    printf(" (%d frag%s)", nfrags, nfrags > 1? "s": "");
 	}
     }
     putchar('\n');
-    if (ndb == 0)
+    if (ndb <= NDADDR)
 	return;
 
     bufp = malloc((unsigned int)sblock.fs_bsize);



More information about the freebsd-fs mailing list