From owner-freebsd-fs@FreeBSD.ORG Thu Jul 21 13:46:04 2005 Return-Path: X-Original-To: freebsd-fs@freebsd.org Delivered-To: freebsd-fs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 617B016A420 for ; Thu, 21 Jul 2005 13:46:04 +0000 (GMT) (envelope-from nb@ravenbrook.com) Received: from raven.ravenbrook.com (raven.ravenbrook.com [193.82.131.18]) by mx1.FreeBSD.org (Postfix) with ESMTP id 10AD843D81 for ; Thu, 21 Jul 2005 13:45:55 +0000 (GMT) (envelope-from nb@ravenbrook.com) Received: from thrush.ravenbrook.com (thrush.ravenbrook.com [193.112.141.145]) by raven.ravenbrook.com (8.12.6p3/8.12.6) with ESMTP id j6LDjqXi030013 for ; Thu, 21 Jul 2005 14:45:53 +0100 (BST) (envelope-from nb@ravenbrook.com) Received: from thrush.ravenbrook.com (localhost [127.0.0.1]) by thrush.ravenbrook.com (8.12.9p2/8.12.9) with ESMTP id j6LDjqFM073798 for ; Thu, 21 Jul 2005 14:45:52 +0100 (BST) (envelope-from nb@thrush.ravenbrook.com) From: Nick Barnes To: freebsd-fs@freebsd.org Date: Thu, 21 Jul 2005 14:45:52 +0100 Message-ID: <73797.1121953552@thrush.ravenbrook.com> Sender: nb@ravenbrook.com Subject: CGSIZE inaccuracy? 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: Thu, 21 Jul 2005 13:46:04 -0000 I'm running 4.9-RELEASE, and writing some tools to navigate around my UFS filesystems to figure out what I have lost when I get bad blocks. There's not much detailed online documentation of UFS beyond fs(5) and fs.h, so I'm feeling my way through the sources. Looking at fs.h, I see this: /* * The size of a cylinder group is calculated by CGSIZE. The maximum size * is limited by the fact that cylinder groups are at most one block. * Its size is derived from the size of the maps maintained in the * cylinder group and the (struct cg) size. */ #define CGSIZE(fs) \ /* base cg */ (sizeof(struct cg) + sizeof(int32_t) + \ /* blktot size */ (fs)->fs_cpg * sizeof(int32_t) + \ /* blks size */ (fs)->fs_cpg * (fs)->fs_nrpos * sizeof(int16_t) + \ /* inode map */ howmany((fs)->fs_ipg, NBBY) + \ /* block map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY) +\ /* if present */ ((fs)->fs_contigsumsize <= 0 ? 0 : \ /* cluster sum */ (fs)->fs_contigsumsize * sizeof(int32_t) + \ /* cluster map */ howmany((fs)->fs_cpg * (fs)->fs_spc / NSPB(fs), NBBY))) In a typical filesystem (fs_fsize = 2048, fs_bsize = 16384, fs_ipg = 22528, fs_cpg = 89, fs_spc = 4096, fs_nrpos = 1, fs_contigsumsize = 7), the parts of this sum add up like this: 172 struct cg; 4 int32_t 356 blktot: free blocks per cylinder; 178 blks: free blocks per rpos per cylinder; 2816 inode map, one bit per inode; 11392 block map, one bit per fragment; 28 cluster summary, one int32_t per contigsumsize+1; 1424 cluster map, one bit per block; ------ 16370 CGSIZE However, using the cg_* macros from fs.h (e.g. cg_clustersum), I get offsets like this: base limit size 0- 168 168 struct cg less cg_space 168- 524 356 cg_blktot (free blocks per cylinder) 524- 702 178 cg_blks (free blocks per rpos per cylinder) 702- 3518 2816 cg_inosused (inode bitmap) 3518-14910 11392 cg_blksfree (fragment bitmap) 14911-14912 2 padding 14912-14940 28 cg_clustersum (block cluster summaries) 14940-16364 1424 cg_clusteroff (block bitmap) 16364 nextfreeoff There are three discrepancies here: +4: sizeof(struct cg) is used instead of offsetof(cg_space); +4: sizeof(int32_t) is added, mysteriously; -2: the padding for cg_clustersum is disregarded. I don't *think* that this matters, because CGSIZE is only apparently used (by newfs and fsck) as a conservative approximation of the size of the cylinder group header. But it seems odd, given that a correct calculation is fairly easy. Nick Barnes Ravenbrook Limited