Subject: Re: Of SCSI disks and things amiss
To: Greg Hudson <ghudson@mit.edu>
From: Bill Studenmund <wrstuden@loki.stanford.edu>
List: tech-kern
Date: 02/29/1996 10:21:40
> 
> [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.

This is the point where I disagree. As I understand how modern SCSI devices
work, the reserved sectors are totally hidden from us mortal drive
users/Operating systems. What you're seeing is the fact that the drive
is good at playing tricks to cram extra storage on the disk. Basically,
the number of sectors per track varies across a disk.

As this proposed change is in a system-wide part of the kernel, I do
not like it. I want NetBSD to be able to deal with my whole disk, not
just the part which lies on nice cylinder boundries.

That said, I do agree that your inability to write a disklabel is wrong.
A fix I'd rather see, though, is for disklabel to stop worrying about
whether the RAW_PART is a nice # of cylinders. Its size should be compared
with the drives true size.

> 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;

Since all the other calculations rely on data from struct disklabel,
why not just have the other parts of the kernel just look at the
given number of sectors? Why always recalculate?

I'm sorry if I come across strongly, but I do feel strongly about this
matter (basically assuming secpercyl is a constant integer across the
disk). When BSD was made (certainly 4.2 & 4.3), this model was quite
accurate. Not so anymore. To me, it's just really frustrating whenever
BSD gets fussy about cylinder sizes, etc. It's on of the (admittedly
minor) things which just makes me want to get the TV Brick (foam :-)
and bludgeon the computer. :-)

So I would suggest fixing disklabel to make sure the new RAW_PART size
is the size of the disk, not a nice # of cylinders. That way, you get
to write disklabels (which you really should be able to do! ), and I
get my whole hard disk.

Take care,

Bill