Subject: bin/3503: config support for sorting wildcarded units after specific ones
To: None <gnats-bugs@gnats.netbsd.org>
From: Brian Baird <brb@brig.com>
List: netbsd-bugs
Date: 04/16/1997 03:02:24
>Number:         3503
>Category:       bin
>Synopsis:       config support for sorting wildcarded units after specific ones
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 16 03:05:00 1997
>Last-Modified:
>Originator:     Brian Baird
>Organization:
Brian Baird				Brig Systems, Pleasanton CA
brb@brig.com				+1 510 484 1342
>Release:        1.2D 970415
>Environment:
System: NetBSD tardis.brig.com 1.2D NetBSD 1.2D (BRIG) #1: Fri Apr 11 05:05:34 PDT 1997 brb@tardis.brig.com:/u/netbsd/ksrc-970326/sys/arch/i386/compile/BRIG i386


>Description:
	If, in a kernel config file, one enters
		sd* at scsibus? target ? lun ?
	and then later on the the config file, enters
		sd0 at scsibus? target 3 lun ?
	the sd0 line will effectively be ignored because the sd* entry
	is written into the cfdata array in ioconf.c earlier.  It
	slurps up any available sd units it sees.

	This was discussed in tech-kern some time ago.  The consensus
	seemed to be to make the fix at config time rather than at
	autoconf time.
>How-To-Repeat:
	compile and boot a NetBSD/sparc -current GENERIC_SCSI3 kernel
	(which is an include of GENERIC and then overrides for sd0-3).
	Note that targets 0, 1, 2, and 3 become sd4, 5, 6, 7, not sd3,
	1, 2, and 0.
>Fix:
	move the starred entries of each base to after the specific
	unit entries.

--- src/usr.sbin/config/pack.c.dist	Mon Oct 14 10:00:06 1996
+++ src/usr.sbin/config/pack.c	Wed Apr 16 02:44:24 1997
@@ -167,6 +167,33 @@
 	register struct devi *i, *l, *p;
 	register struct devbase *d;
 	register int j, m, n;
+	struct devi **ipp;
+
+	/*
+	 * sort all the wildcarded units to after the specific units so
+	 * an xx0 cfdata entry will always get written before an xx* entry
+	 */
+	for (d = allbases; d != NULL; d = d->d_next) {
+		ipp = d->d_ipp;
+		l = NULL;
+		for (i = d->d_ihead; i != NULL;) {
+			if (i->i_bsame == NULL || &i->i_bsame == ipp)
+				break;		/* already at end */
+			if (i->i_unit == STAR) {
+				if (l == NULL) {
+					d->d_ihead = i->i_bsame;
+				} else {
+					l->i_bsame = i->i_bsame;
+				}
+				*d->d_ipp = i;
+				i->i_bsame = NULL;
+				d->d_ipp = &i->i_bsame;
+				continue;
+			}
+			l = i;
+			i = i->i_bsame;
+		}
+	}
 
 	packed = emalloc((ndevi + 1) * sizeof *packed);
 	n = 0;

>Audit-Trail:
>Unformatted: