Subject: Disklabels arrive for 2.11BSD (#260 part 11 of 18)
Index:	sys,bin,usr.lib,(many more)/<many> 2.11BSD

Description:
	The moving the partitions tables out of the disk drivers and to
	a disklabel residing on the media has been on the wish list for
	many many years.

	Disklabels have finally arrived for 2.11BSD!

Repeat-By:
	Observation.  Also a reading of the setup and installation
	documentation for previous 2BSD releases (2.9, 2.10, 2.11)
	all have a paragraph similar to this present:

"It is possible to change the partitions by changing the code for the
table in the disk driver.  Since it's desirable to do this, these tables
really should be read off each pack...."

Fix:
	This is part 11 of 18.  Gather all parts before doing anything
	except reading the instructions which are in #250 (part 1).

	Updated by this part are:

/usr/src/sys/pdp/machdep2.c
/usr/src/sys/pdp/conf.c

	machdep2.c had added the logic to allocate an initial pool
	of disklabels external to the kernel.  Six (6) labels are 
	allocated, this is sufficient for 6 disk drives.  If more drives
	are used (unlikely - most systems are lucky to have more than 1)
	then labels are allocated out of main memory - some fragmentation
	will result and if this is a problem you will need to increase
	the default number of labels in the pool by modifying machdep2.c.

	conf.c was changed to include 'close' and 'ioctl' entry points for
	the MSCP (ra) and RL (rl) drivers.

	NOTE:  drivers which support disklabels must now have a 'close'
	       and 'ioctl' entry points.  The driver keeps track of which 
	       partitions are active on a drive now by setting a bit when
	       a partition is opened and clearing that bit when the last
	       close is done.  PREVIOUSLY disk drivers were the exception
	       amoung drivers by not having a 'close' routine.

	       The ioctl entry point is used by 'disklabel' to set and
	       retrieve disklabel information.

	Cut where indicated and save to a file (/tmp/260).  Then:

		patch -p0 < /tmp/260
		rm /tmp/260

-------------------------cut here-----------------------
*** /usr/src/sys/pdp/machdep2.c.old	Mon Feb 20 20:00:15 1995
--- /usr/src/sys/pdp/machdep2.c	Wed May  3 20:33:09 1995
***************
*** 3,9 ****
   * All rights reserved.  The Berkeley software License Agreement
   * specifies the terms and conditions for redistribution.
   *
!  *	@(#)machdep2.c	2.3 (2.11BSD GTE) 2/15/95
   */
  
  #include "param.h"
--- 3,9 ----
   * All rights reserved.  The Berkeley software License Agreement
   * specifies the terms and conditions for redistribution.
   *
!  *	@(#)machdep2.c	2.4 (2.11BSD GTE) 1995/05/01
   */
  
  #include "param.h"
***************
*** 30,35 ****
--- 30,36 ----
  #include "ra.h"
  #include "tms.h"
  #include "ingres.h"
+ #include "disklabel.h"
  
  #if	NINGRES > 0
  #include <sys/ingreslock.h>
***************
*** 194,199 ****
--- 195,205 ----
  #undef  C
  #endif
  
+ /*
+  * Allocate the initial disklabels.
+ */
+ 	(void) initdisklabels();
+ 
  #if NRAM > 0
  	ramsize = raminit();
  #endif
***************
*** 440,442 ****
--- 446,476 ----
  	return(((ubadr_t)(addr - _iostart) << 6) + _ioumr);
  	}
  #endif NRAC
+ 
+ #define	NLABELS	6
+ 
+ 	memaddr	_dlabelbase;
+ 	int	_dlabelnum = NLABELS;
+ 
+ void
+ initdisklabels()
+ 	{
+ #define	C	(NLABELS * (btoc(sizeof (struct disklabel))))
+ 
+ 	_dlabelbase = malloc(coremap, C);
+ 	}
+ 
+ memaddr
+ disklabelalloc()
+ 	{
+ 	register memaddr base;
+ 
+ 	if	(--_dlabelnum)
+ 		{
+ 		base = _dlabelbase;
+ 		_dlabelbase += btoc(sizeof (struct disklabel));
+ 		return(base);
+ 		}
+ 	base = malloc(coremap, btoc (sizeof (struct disklabel)));
+ 	return(base);
+ 	}
*** /usr/src/sys/pdp/conf.c.old	Wed Feb 15 20:25:25 1995
--- /usr/src/sys/pdp/conf.c	Mon Jun 19 20:36:34 1995
***************
*** 3,9 ****
   * All rights reserved.  The Berkeley software License Agreement
   * specifies the terms and conditions for redistribution.
   *
!  *	@(#)conf.c	2.4 (2.11BSD GTE) 2/15/95
   */
  
  #include "param.h"
--- 3,9 ----
   * All rights reserved.  The Berkeley software License Agreement
   * specifies the terms and conditions for redistribution.
   *
!  *	@(#)conf.c	2.7 (2.11BSD GTE) 1995/06/19
   */
  
  #include "param.h"
***************
*** 94,106 ****
  
  #include "rl.h"
  #if NRL > 0
! int	rlopen(), rlstrategy(), rlroot();
  daddr_t	rlsize();
- #define	rlclose		nulldev
  #else
  #define	rlroot		nulldev
  #define	rlopen		nodev
  #define	rlclose		nodev
  #define	rlstrategy	nodev
  #define	rlsize		NULL
  #endif
--- 94,106 ----
  
  #include "rl.h"
  #if NRL > 0
! int	rlopen(), rlstrategy(), rlroot(), rlclose(), rlioctl();
  daddr_t	rlsize();
  #else
  #define	rlroot		nulldev
  #define	rlopen		nodev
  #define	rlclose		nodev
+ #define	rlioctl		nodev
  #define	rlstrategy	nodev
  #define	rlsize		NULL
  #endif
***************
*** 140,151 ****
  
  #include "ra.h"
  #if NRAC > 0
! int	rastrategy(), raroot(), raopen();
  daddr_t	rasize();
- #define	raclose		nulldev
  #else
  #define	raopen		nodev
  #define	raclose		nodev
  #define	raroot		nulldev
  #define	rastrategy	nodev
  #define	rasize		nodev
--- 140,151 ----
  
  #include "ra.h"
  #if NRAC > 0
! int	rastrategy(), raroot(), raopen(), raclose(), raioctl();
  daddr_t	rasize();
  #else
  #define	raopen		nodev
  #define	raclose		nodev
+ #define	raioctl		nodev
  #define	raroot		nulldev
  #define	rastrategy	nodev
  #define	rasize		nodev
***************
*** 411,417 ****
  	hkstrategy,
  /* ra = 14 */
  	raopen,		raclose,	rawrw,		rawrw,
! 	nodev,		nulldev,	0,		seltrue,
  	rastrategy,
  /* rk = 15 */
  	rkopen,		rkclose,	rawrw,		rawrw,
--- 411,417 ----
  	hkstrategy,
  /* ra = 14 */
  	raopen,		raclose,	rawrw,		rawrw,
! 	raioctl,	nulldev,	0,		seltrue,
  	rastrategy,
  /* rk = 15 */
  	rkopen,		rkclose,	rawrw,		rawrw,
***************
*** 419,425 ****
  	rkstrategy,
  /* rl = 16 */
  	rlopen,		rlclose,	rawrw,		rawrw,
! 	nodev,		nulldev,	0,		seltrue,
  	rlstrategy,
  /* rx = 17 */
  	rxopen,		rxclose,	rawrw,		rawrw,
--- 419,425 ----
  	rkstrategy,
  /* rl = 16 */
  	rlopen,		rlclose,	rawrw,		rawrw,
! 	rlioctl,	nulldev,	0,		seltrue,
  	rlstrategy,
  /* rx = 17 */
  	rxopen,		rxclose,	rawrw,		rawrw,
