Subject: disk block sizes != DEV_BSIZE?
To: None <current-users@NetBSD.ORG>
From: Chris G Demetriou <>
List: current-users
Date: 06/17/1996 21:14:34
Are any of the rest of you having problems with using disks with
sectors sizes != DEV_BSIZE?  (Actually, what i'd like to do is use a
disk with sector size == DEV_BSIZE, but with a disklabel sector size
of something larger... anyway...)

As far as I can tell, the current situation looks like:

	(1) block partition access and the file systems seem to want
	    to access devices on sector-size boundaries (as determined
	    by the sector size in the disklabel, else DEV_BSIZE),
	    and set a buffer's b_blkno field in units of the sector

	(2) raw transfers use btodb(), i.e. DEV_BSIZE units, always,
	    and specify b_blkno in units of DEV_BSIZE.

That means that *strategy() and functions like
bounds_check_with_label() get b_blkno in different units -- way bad.

There's also the fact that:

	(3) some drivers, e.g. the SCSI disk driver, appear to again
	    divide the block number by (disklabel sector size / DEV_BSIZE).

At the very least, there appears to be an inconsistency here which
should be rectified.  Has anyone else who is familiar with the code
noticed the same thing, or am I way off in left field?  (If you say
the latter, "convince me."  8-)

Any thoughts on The Right Solution?  It seems to me that the easiest
and most correct solution is:

	(1) have b_blkno talk about disk block numbers in terms of
	    DEV_BSIZE units,
	(2) have the drivers convert that into the device block size,
	    potentially rejecting requests that are malformed (e.g.
	    512-byte access to 1k-block device), and
	(3) use the disklabel sector size only when calculating
	    information with the disklabel, and convert to/from
	    DEV_BSIZE units appropriate.

Basically, in that case, the only constraints are that:
	(1) the disk sector size must be a multiple of DEV_BSIZE,
	(2) the disklabel sector size must be a multiple of
	    the actual disk sector size.
	(3) accesses to the disk (via the raw device or via
	    internal mechanisms) must be done such that
	    the given b_blkno and transfer size (in blocks)
	    is divisible by (disk sector size / DEV_BSIZE).

That would allow me, for instance, to create a disk image that could
be used on either a 512-byte sector SCSI disk or a 2k-byte sector SCSI
CD-ROM, without problem.