Date: Thu, 21 Jul 2005 14:45:52 +0100 From: Nick Barnes <Nick.Barnes@pobox.com> To: freebsd-fs@freebsd.org Subject: CGSIZE inaccuracy? Message-ID: <73797.1121953552@thrush.ravenbrook.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?73797.1121953552>