Subject: Re: Supporting sector size != DEV_BSIZE
To: Trevin Beattie <trevin@xmission.com>
From: Bill Studenmund <wrstuden@netbsd.org>
List: tech-kern
Date: 06/09/2002 19:15:01
On Fri, 7 Jun 2002, Trevin Beattie wrote:

> I've been poring over the mkfs.c code to make sure there are no references
> to DEV_BSIZE (as that value is not stored on disk), and I came across the
> following at line 899:
>
> 	node.di_blocks = btodb(fragroundup(&sblock, node.di_size));
>
> A quick grep through the ffs code confirmed that di_blocks is assumed to be
> in units of DEV_BSIZE.  This may cause problems if, as Bill has suggested,
> a drive is transferred to another system where the kernel's value of
> DEV_BSIZE is different.  Am I mistaken, or does anyone have a suggestion on
> how to fix it without breaking existing implementations?  Why doesn't
> di_blocks simply count the number of fragments?

Don't forget that this code wasn't made to work with DEV_BSIZE !=
the disk block size.

So in cases like this, the best thing to do is make sure that you use
a btodb variant that uses the disk's sector size, not DEV_BSIZE.

Note also that since di_blocks is in sectors, any update to it (say in the
kernel code) will need to use the same macro.

As to why di_blocks uses sectors, not fragments, I'm not sure.

Take care,

Bill