Subject: Re: Supporting sector size != DEV_BSIZE
To: Trevin Beattie <trevin@xmission.com>
From: Bill Studenmund <wrstuden@netbsd.org>
List: tech-kern
Date: 05/31/2002 15:04:07
On Fri, 31 May 2002, Trevin Beattie wrote:

> I should have paid more attention to what you already suggested, Chuck! :^)
>
> I was looking through the bounds_check_with_label function
> (arch/i386/i386/disksubr.c, which, BTW, is not called for partition 'd'),

Partition 'd' is the whole disk, which isn't checked. That's part of the
design.

> and almost right away noticed a bad inconsistency.  The function starts by
> converting bytes to sectors:
>
> 481:	sz = howmany(bp->b_bcount, lp->d_secsize);
>
> It then adds the sector count to the _block number_ and checks the result
> against the partition size:
>
> 483:	if (bp->b_blkno + sz > p->p_size) {
> 484:		sz = p->p_size - bp->b_blkno;
>
> If the request runs past the end of the partition, it truncates the size
> and converts the number of *DEV_BSIZE blocks* to bytes:
>
> 496:		bp->b_bcount = sz << DEV_BSHIFT;
>
> Obviously, one or more of the above lines is incorrect and must be changed,
> because line 496 is inconsistent with line 481.  But I have no idea what
> the correct change should be, because I can't find any formal definition
> for the units used by b_blkno.  <sys/buf.h> defines this parameter as the
> "underlying physical block number"; but is that a physical sector or a
> DEV_BSIZE block?
>
> My guess, judging from dev/vnd.c:376, is that b_blkno is in DEV_BSIZE
> units.  But the value of p_size (partition size) stored on the disk label
> of my virtual disk is in units of sectors.  This would seem to indicate
> that b_blkno needs shifting everywhere it's used in
> bounds_check_with_label.  Unless the partition data should actually be in
> terms of DEV_BSIZE instead of sectors, in which case disklabel needs to be
> changed.

b_blkno is in units of DEV_BSIZE.

> Can anybody refer me to the design specs for the file system?

You mean the buffer cache? :-)

Not sure.

Take care,

Bill