Subject: port-sparc/6325: [port-sparc] readdisklabel() should check a Sun disk label first
To: None <gnats-bugs@gnats.netbsd.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: netbsd-bugs
Date: 10/18/1998 15:20:57
>Number:         6325
>Category:       port-sparc
>Synopsis:       readdisklabel() should check a Sun disk label first
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Oct 17 23:35:01 1998
>Last-Modified:
>Originator:     Izumi Tsutsui
>Organization:
Izumi Tsutsui	Himeji City Japan
>Release:        1.3H current supped on October 17 1998
>Environment:
System: NetBSD legnum 1.3H NetBSD 1.3H (LEGNUM) #16: Sat Oct 17 17:47:33 JST 1998 tsutsui@legnum:/usr/src/sys/arch/sparc/compile/LEGNUM sparc

>Description:
Although writedisklabel() writes only a Sun disk label,
readdisklabel() is checking a NetBSD disk label first.
So if there is a valid NetBSD disk label on the disk,
kernel does not recognize that the Sun disk label is
modified.

>How-To-Repeat:
Connect a disk which has a valid NetBSD disklabel for sparc,
then modify and read the disklabel.

BTW, sparc is the only port which defines LABELOFFSET as 128,
so most disks do not have the valid NetBSD disklabels for sparc..

>Fix:
Check a Sun disk label first in readdisklabel() like sun3 does.

--- disksubr.c.orig	Sat Jun 20 20:29:36 1998
+++ disksubr.c	Sun Oct 18 14:47:59 1998
@@ -183,6 +183,11 @@
 	if (error)
 		return ("disk label read error");
 
+	/* Check for a Sun disk label (for PROM compatibility). */
+	slp = (struct sun_disklabel *) clp->cd_block;
+	if (slp->sl_magic == SUN_DKMAGIC)
+		return (disklabel_sun_to_bsd(clp->cd_block, lp));
+
 	/* Check for a NetBSD disk label. */
 	dlp = (struct disklabel *) (clp->cd_block + LABELOFFSET);
 	if (dlp->d_magic == DISKMAGIC) {
@@ -191,12 +196,6 @@
 		*lp = *dlp;
 		return (NULL);
 	}
-
-	/* Check for a Sun disk label (for PROM compatibility). */
-	slp = (struct sun_disklabel *) clp->cd_block;
-	if (slp->sl_magic == SUN_DKMAGIC)
-		return (disklabel_sun_to_bsd(clp->cd_block, lp));
-
 
 	bzero(clp->cd_block, sizeof(clp->cd_block));
 	return ("no disk label");
>Audit-Trail:
>Unformatted: