Subject: Increasing maximum partition to 16
To: None <tech-kern@netbsd.org>
From: Matthias Scheler <tron@zhadum.de>
List: tech-kern
Date: 12/28/2000 17:29:34
	Hello,

I've attached changes for NetBSD-current which give the i386 port a maximum
of 16 partitions per disk:

tron@lyssa:~#df
Filesystem            1K-blocks     Used     Avail Capacity  Mounted on
[...]
/dev/vnd0l                31727        1     30139       0%    /mnt/l

The changes are:

+ completely backward compatible (new kernel works with old device nodes)
+ easily reusable for other ports like e.g. alpha or sparc

The trick is to use some extra upper bits of the minor device number for
the partition.

	Kind regards

-- 
Matthias Scheler                                         http://core.de/~tron/

Index: sys/arch/i386/include/disklabel.h
===================================================================
RCS file: /cvsroot/syssrc/sys/arch/i386/include/disklabel.h,v
retrieving revision 1.8
diff -u -r1.8 disklabel.h
--- sys/arch/i386/include/disklabel.h	1999/01/27 20:54:57	1.8
+++ sys/arch/i386/include/disklabel.h	2000/12/28 17:19:00
@@ -33,10 +33,11 @@
 #ifndef _MACHINE_DISKLABEL_H_
 #define _MACHINE_DISKLABEL_H_
 
-#define	LABELSECTOR	1		/* sector containing label */
-#define	LABELOFFSET	0		/* offset of label in sector */
-#define	MAXPARTITIONS	8		/* number of partitions */
-#define	RAW_PART	3		/* raw partition: XX?d (XXX) */
+#define	LABELSECTOR		1	/* sector containing label */
+#define	LABELOFFSET		0	/* offset of label in sector */
+#define	MAXPARTITIONS		16	/* number of partitions */
+#define	OLDMAXPARTITIONS 	8	/* number of partitions before 1.6 */
+#define	RAW_PART		3	/* raw partition: XX?d (XXX) */
 
 /* Pull in MBR partition definitions. */
 #include <sys/disklabel_mbr.h>
Index: sys/sys/disklabel.h
===================================================================
RCS file: /cvsroot/syssrc/sys/sys/disklabel.h,v
retrieving revision 1.63
diff -u -r1.63 disklabel.h
--- sys/sys/disklabel.h	2000/11/26 17:44:03	1.63
+++ sys/sys/disklabel.h	2000/12/28 17:19:11
@@ -59,10 +59,26 @@
 /*
  * Translate between device numbers and major/disk unit/disk partition.
  */
+#define MAXDISKS	((1 << 20) / MAXPARTITIONS)
+#ifndef OLDMAXPARTITIONS
 #define	DISKUNIT(dev)	(minor(dev) / MAXPARTITIONS)
 #define	DISKPART(dev)	(minor(dev) % MAXPARTITIONS)
 #define	DISKMINOR(unit, part) \
     (((unit) * MAXPARTITIONS) + (part))
+#else /* OLDMAXPARTITIONS */
+/*
+ * On ports which used to have a small value for MAXPARTITIONS (usually 8)
+ * we use some of the upper bits of the minor number (usually 1) for the
+ * partition number. This maintains backward compatibility with device
+ * nodes created before MAXPARTITIONS was increased.
+ */
+#define DISKUNIT(dev)	((minor(dev) / OLDMAXPARTITIONS) % MAXDISKS)
+#define DISKPART(dev)	((minor(dev) % OLDMAXPARTITIONS) + \
+    ((minor(dev) / (MAXDISKS * OLDMAXPARTITIONS)) * OLDMAXPARTITIONS))
+#define	DISKMINOR(unit, part) \
+    (((unit) * OLDMAXPARTITIONS) + ((part) % OLDMAXPARTITIONS) + \
+     ((part) / OLDMAXPARTITIONS) * (MAXDISKS * OLDMAXPARTITIONS))
+#endif /* OLDMAXPARTITIONS */
 #define	MAKEDISKDEV(maj, unit, part) \
     (makedev((maj), DISKMINOR((unit), (part))))
 
Index: etc/etc.i386/MAKEDEV
===================================================================
RCS file: /cvsroot/basesrc/etc/etc.i386/MAKEDEV,v
retrieving revision 1.131
diff -u -r1.131 MAKEDEV
--- etc/etc.i386/MAKEDEV	2000/12/19 22:39:34	1.131
+++ etc/etc.i386/MAKEDEV	2000/12/28 17:19:11
@@ -119,6 +119,8 @@
 dialout=524288		# high bit of the minor number
 callunit=262144
 
+highpartoffset=524280	# offset for partition 9 to 16
+
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 umask 77
 
@@ -416,6 +418,14 @@
 	mknod ${name}${unit}f	b $blk $(($unit * 8 + 5))
 	mknod ${name}${unit}g	b $blk $(($unit * 8 + 6))
 	mknod ${name}${unit}h	b $blk $(($unit * 8 + 7))
+	mknod ${name}${unit}i	b $blk $(($unit * 8 + $highpartoffset + 8))
+	mknod ${name}${unit}j	b $blk $(($unit * 8 + $highpartoffset + 9))
+	mknod ${name}${unit}k	b $blk $(($unit * 8 + $highpartoffset + 10))
+	mknod ${name}${unit}l	b $blk $(($unit * 8 + $highpartoffset + 11))
+	mknod ${name}${unit}m	b $blk $(($unit * 8 + $highpartoffset + 12))
+	mknod ${name}${unit}n	b $blk $(($unit * 8 + $highpartoffset + 13))
+	mknod ${name}${unit}o	b $blk $(($unit * 8 + $highpartoffset + 14))
+	mknod ${name}${unit}p	b $blk $(($unit * 8 + $highpartoffset + 15))
 	mknod r${name}${unit}a	c $chr $(($unit * 8 + 0))
 	mknod r${name}${unit}b	c $chr $(($unit * 8 + 1))
 	mknod r${name}${unit}c	c $chr $(($unit * 8 + 2))
@@ -424,6 +434,14 @@
 	mknod r${name}${unit}f	c $chr $(($unit * 8 + 5))
 	mknod r${name}${unit}g	c $chr $(($unit * 8 + 6))
 	mknod r${name}${unit}h	c $chr $(($unit * 8 + 7))
+	mknod r${name}${unit}i	c $chr $(($unit * 8 + $highpartoffset + 8))
+	mknod r${name}${unit}j	c $chr $(($unit * 8 + $highpartoffset + 9))
+	mknod r${name}${unit}k	c $chr $(($unit * 8 + $highpartoffset + 10))
+	mknod r${name}${unit}l	c $chr $(($unit * 8 + $highpartoffset + 11))
+	mknod r${name}${unit}m	c $chr $(($unit * 8 + $highpartoffset + 12))
+	mknod r${name}${unit}n	c $chr $(($unit * 8 + $highpartoffset + 13))
+	mknod r${name}${unit}o	c $chr $(($unit * 8 + $highpartoffset + 14))
+	mknod r${name}${unit}p	c $chr $(($unit * 8 + $highpartoffset + 15))
 	chgrp operator $name$unit? r$name$unit?
 	chmod 640 $name$unit? r$name$unit?
 	;;