Subject: port-next68k/16929: default disklabel is bad
To: None <gnats-bugs@gnats.netbsd.org>
From: None <chris@Pin.LU>
List: netbsd-bugs
Date: 05/20/2002 18:20:55
>Number:         16929
>Category:       port-next68k
>Synopsis:       default disklabel is bad
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    port-next68k-maintainer
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 20 10:01:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Christian Limpach
>Release:        current (as of May 20 2002)
>Organization:
	
>Environment:
	
System: NetBSD clapper 1.5ZC NetBSD 1.5ZC (CLAPPER) #46: Mon May 13 20:51:50 CEST 2002     root@marble:/devel/netbsd/src-current/sys/arch/next68k/compile/CLAPPER next68k
arch/next68k/next68k/disksubr.c rev. 1.7

>Description:
	The default in-core disklabel for unlabeled disks is bad.
	# disklabel sd0
	sd0: no disk label
	# /dev/rsd0c:
	...
	total sectors: 205561
	...
	1 partitions:
	#        size    offset     fstype  [fsize bsize cpg/sgs]
	 a: 536870911         0     unused      0     0         # (Cyl.    0 - 3195660*)
	disklabel: boot block size 0
	disklabel: super block size 0
	disklabel: partition a: partition extends past end of unit
	disklabel: warning, unused partition c: size 205561 offset 0

>How-To-Repeat:
	try to disklabel a disk which doesn't have a label

>Fix:
	Make the disklabel have at least RAW_PART partitions and fix
	the offset/size initialization of partitions.
	The following ports probably the same problem:
	luna68k news68k newsmips pc532 pmax

Index: disksubr.c
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/next68k/next68k/disksubr.c,v
retrieving revision 1.7
diff -u -r1.7 disksubr.c
--- disksubr.c	2002/03/05 09:40:41	1.7
+++ disksubr.c	2002/05/20 16:38:23
@@ -67,13 +67,21 @@
 	struct buf *bp;
 	struct disklabel *dlp;
 	char *msg = NULL;
+	int i;
 
+	/* minimal requirements for archtypal disk label */
+	if (lp->d_secsize == 0)
+		lp->d_secsize = DEV_BSIZE;
 	if (lp->d_secperunit == 0)
 		lp->d_secperunit = 0x1fffffff;
-	lp->d_npartitions = 1;
-	if (lp->d_partitions[0].p_size == 0)
-		lp->d_partitions[0].p_size = 0x1fffffff;
-	lp->d_partitions[0].p_offset = 0;
+	lp->d_npartitions = RAW_PART + 1;
+	for (i = 0; i < RAW_PART; i++) {
+		lp->d_partitions[i].p_size = 0;
+		lp->d_partitions[i].p_offset = 0;
+	}
+	if (lp->d_partitions[i].p_size == 0)
+		lp->d_partitions[i].p_size = 0x1fffffff;
+	lp->d_partitions[i].p_offset = 0;
 
 	bp = geteblk((int)lp->d_secsize);
 	bp->b_dev = dev;

after patch:
# disklabel sd0
sd0: no disk label
# /dev/rsd0c:
...
total sectors: 205561
...
3 partitions:
#        size    offset     fstype  [fsize bsize cpg/sgs]
 c:    205561         0     unused      0     0         # (Cyl.    0 - 1223*)
disklabel: boot block size 0
disklabel: super block size 0

>Release-Note:
>Audit-Trail:
>Unformatted: