Subject: My changes to subr_disc_mbr (Was Re: default generated disklabels get overwritten?)
To: Manuel Bouyer <>
From: Reinoud Zandijk <>
List: tech-kern
Date: 12/14/2005 23:41:31
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Wed, Dec 14, 2005 at 02:56:16PM +0100, Reinoud Zandijk wrote:
> On Wed, Dec 14, 2005 at 02:16:39PM +0100, Manuel Bouyer wrote:
> I think i've found the curlpit: in `kern/subr_disc_mbr.c' that NetBSD/i386 
> uses a `dummy' disclabel is created just with the parameters i've seen 
> showing up again and again. What is happening i think is that in 
> scsipi/cd.c the returned error is not processed OK when no disclabel is 
> found on the disc and thus sets this dummy to be the correct one.

I traced the problem back to the readdisklabel() in kern/subr_disk_mbr.c 
where the function returns NULL regardless if there is a disklabel on disc 
or not. It only returns an error string if there was an error reading 
sectors or when the read in disklabel was corrupt.

This makes it impossible for its callers (disc device drivers) to determine 
if there was indeed a disklabel on disc or not or that it needs to create a 
default label for the disc. The basic change i made was:

-__KERNEL_RCSID(0, "$NetBSD: subr_disk_mbr.c,v 1.11 2005/12/14 21:40:32 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk_mbr.c,v 1.7 2005/12/11 12:24:30 christos Exp $");
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -297,6 +297,8 @@
+       if (rval == SCAN_CONTINUE)
+               return "No disclabel found";
        if (rval == SCAN_ERROR)
                return a.msg;
        return NULL;

It was reversed later the same day without discussion. I propably should 
have mailed first to this list but IMHO its broken in the origional form.

The result is that a disk driver like sys/dev/scsipi/cd.c can not create 
its own default label while still supporting `normal' disklabels to be on 
the disc. It can't determine if there is a label on the disk or not.


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.6 (NetBSD)