Subject: Of SCSI disks and things amiss
To: None <tech-kern@NetBSD.ORG>
From: Greg Hudson <ghudson@mit.edu>
List: tech-kern
Date: 02/29/1996 00:21:23
[This message contains a proposal to commit something in the kernel if
no one objects.  See near the end.]

So, right now, when I plug in a new unformatted SCSI disk on my system
(an i386, which is irrelevant except insofar as the raw partition is d
and not c) and run disklabel on it, I get a label with the following
interesting excerpts:

sectors/cylinder: 1188
cylinders: 3511

4 partitions:
#        size   offset    fstype   [fsize bsize   cpg]
  d:  4194058        0    unused        0     0         # (Cyl.    0 - 3530*)

You will note that 1188 * 3511 is 4171068, just a tad below the
4194058 sectors used for the size of the raw partition.  If you
attempt to write this disklabel, you get the complaint:

	disklabel: partition d: partition extends past end of unit

because disklabel computes a d_secperunit of 4171068.  This situation
is clearly not correct.

The problem appears to stem from scsi/sd.c, which has:

	lp->d_secperunit = sd->params.disksize;
	[...]
	lp->d_partitions[RAW_PART].p_size =
	    lp->d_secperunit * (lp->d_secsize / DEV_BSIZE);

Evidently, sd->params.disksize includes the reserved sectors on the
disk.

Every other piece of code in the kernel appears to calculate
d_secperunit using d_secpercyl * d_ncylinders.  If no one objects in
the next few days, I am going to change the first line I quoted from
scsi/sd.c to:

	lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;