Date: Tue, 31 Jan 2012 17:00:51 -0800 (PST) From: Don Lewis <truckman@FreeBSD.org> To: freebsd-fs@FreeBSD.org Subject: CFR patch to improve fsdb sparse file handling Message-ID: <201202010100.q1110pfM092973@gw.catspoiler.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202010100.q1110pfM092973>