From owner-freebsd-fs@FreeBSD.ORG Wed Feb 1 01:14:14 2012 Return-Path: Delivered-To: freebsd-fs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 72E04106564A for ; Wed, 1 Feb 2012 01:14:14 +0000 (UTC) (envelope-from truckman@FreeBSD.org) Received: from gw.catspoiler.org (gw.catspoiler.org [75.1.14.242]) by mx1.freebsd.org (Postfix) with ESMTP id 584528FC18 for ; Wed, 1 Feb 2012 01:14:14 +0000 (UTC) Received: from FreeBSD.org (mousie.catspoiler.org [192.168.101.2]) by gw.catspoiler.org (8.13.3/8.13.3) with ESMTP id q1110pfM092973 for ; Tue, 31 Jan 2012 17:00:55 -0800 (PST) (envelope-from truckman@FreeBSD.org) Message-Id: <201202010100.q1110pfM092973@gw.catspoiler.org> Date: Tue, 31 Jan 2012 17:00:51 -0800 (PST) From: Don Lewis To: freebsd-fs@FreeBSD.org MIME-Version: 1.0 Content-Type: TEXT/plain; charset=us-ascii Cc: Subject: CFR patch to improve fsdb sparse file handling X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Feb 2012 01:14:14 -0000 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);