Subject: ultrix disk label patches
To: None <port-pmax@sun-lamp.cs.berkeley.edu>
From: Andrew Gallatin <gallatin@isds.Duke.EDU>
List: port-pmax
Date: 08/21/1994 16:33:24
Hi,

I've added in some code in disksubr.c & rz.c to read in Ultrix
partition tables.  I'm not sure if I've done it 'well' but it seems to
work.   What bothers me is there doesn't seem to be a good way to
include sys/arch/pmax/stand/dec_boot.h & it seems silly to duplicate
it...

Anyway, the following patches are against the tree at sun-lamp as of
Sun Aug 21 16:11:46 1994 EDT.  Since Jonathon Stone's patches don't
seem to have been integrated yet, the patch to rz.c includes some
changes that he's made.  

I've tested them on 3 machines (3100,5000/25 & 5000/200), all of whose
partition information was written using chpt from Ultrix 4.3A.

Oh, and I should mention that my tree includes all of Jonathon's
patches, in case there are any hidden dependancies.

Drew





*** sys/arch/pmax/pmax/disksubr.c.DIST	Sun Aug 21 16:11:46 1994
--- sys/arch/pmax/pmax/disksubr.c	Sun Aug 21 15:25:13 1994
***************
*** 42,47 ****
--- 42,52 ----
  
  #define	b_cylin	b_resid
  
+ #ifdef COMPAT_ULTRIX
+ #include "../../stand/dec_boot.h"
+ #endif
+ 
+ 
  /*
   * Attempt to read a disk label from a device
   * using the indicated stategy routine.
***************
*** 59,64 ****
--- 64,72 ----
  {
  	register struct buf *bp;
  	struct disklabel *dlp;
+ #ifdef COMPAT_ULTRIX
+ 	Dec_DiskLabel *Dec_dlp;
+ #endif
  	char *msg = NULL;
  
  	if (lp->d_secperunit == 0)
***************
*** 92,97 ****
--- 100,144 ----
  			break;
  		}
  	}
+ #ifdef COMPAT_ULTRIX	  /* look for ultrix disklabel 
+ 			     gallatin@isds.duke.edu , 8/21/94 */
+ 	if(msg){
+ 	     msg = NULL;
+ 	     bp->b_dev = dev;
+ 	     bp->b_blkno = DEC_LABEL_SECTOR;
+ 	     bp->b_bcount = lp->d_secsize;
+ 	     bp->b_flags = B_BUSY | B_READ;
+ 	     bp->b_cylin = DEC_LABEL_SECTOR / lp->d_secpercyl;
+ 	     (*strat)(bp);
+ 	     if (biowait(bp)) {
+                 msg = "I/O error";
+ 	     }  else for (Dec_dlp = (Dec_DiskLabel *)bp->b_un.b_addr;
+ 			  Dec_dlp <= (Dec_DiskLabel *)(bp->b_un.b_addr+DEV_BSIZE-sizeof(*Dec_dlp));
+ 			  Dec_dlp = (Dec_DiskLabel *)((char *)Dec_dlp + sizeof(long))) {
+ 	       if (Dec_dlp->magic != DEC_LABEL_MAGIC) {
+ 		 printf("label: %x\n",Dec_dlp->magic);
+ 		 if (msg == NULL)
+ 		   msg = "no disk label";
+ 	       }
+ 	       else {
+ 		 int i;
+ 		 lp->d_magic=DEC_LABEL_MAGIC;
+ 		 for(i=0;i<((MAXPARTITIONS<DEC_NUM_DISK_PARTS) ?
+ 			    MAXPARTITIONS : DEC_NUM_DISK_PARTS); i++) {
+ 		   lp->d_partitions[i].p_size = Dec_dlp->map[i].numBlocks;
+ 		   lp->d_partitions[i].p_offset = Dec_dlp->map[i].startBlock;
+ 		   lp->d_partitions[i].p_fsize = 1024;
+ 		   if(i==1)
+ 		     lp->d_partitions[i].p_fstype=FS_SWAP;
+ 		   else
+ 		     lp->d_partitions[i].p_fstype=FS_BSDFFS;
+ 		 }
+ 		 msg = "using ULTRIX partition information";
+ 		 break;
+ 	       }
+ 	     }
+ 	}
+ #endif /* COMPAT_ULTRIX */
  	bp->b_flags = B_INVAL | B_AGE;
  	brelse(bp);
  	return (msg);

*** sys/arch/pmax/dev/rz.c.DIST	Sun Aug 21 16:11:53 1994
--- sys/arch/pmax/dev/rz.c	Sun Aug 21 16:20:19 1994
***************
*** 89,94 ****
--- 89,104 ----
   * (including the boot area).
   */
  static struct size rzdefaultpart[MAXPARTITIONS] = {
+ #ifdef GENERIC	/* greedy machines have 64 meg of swap */
+                 0,   32768,     /* A */
+             32768,  131072,     /* B */
+ 	        0,       0,	/* C */
+ 	    17408,       0,	/* D */
+ 	   115712,       0,	/* E */
+ 	   218112,       0,	/* F */
+ 	   163840,       0,	/* G */
+ 	   115712,       0,	/* H */
+ #else
  	        0,   16384,	/* A */
  	    16384,   65536,	/* B */
  	        0,       0,	/* C */
***************
*** 97,102 ****
--- 107,113 ----
  	   218112,       0,	/* F */
  	    81920,       0,	/* G */
  	   115712,       0,	/* H */
+ #endif
  };
  
  #define	RAWPART		2	/* 'c' partition */	/* XXX */
***************
*** 663,668 ****
--- 674,683 ----
  	}
  }
  
+ #ifdef COMPAT_ULTRIX
+ #include "../../stand/dec_boot.h"
+ #endif
+ 
  /*
   * Read or constuct a disklabel
   */
***************
*** 695,702 ****
  	msg = readdisklabel(dev, rzstrategy, lp, &cd);
  	if (msg == NULL)
  		return;
! #if 0
  	printf("rz%d: WARNING: %s\n", unit, msg);
  	sc->sc_label.d_magic = DISKMAGIC;
  	sc->sc_label.d_magic2 = DISKMAGIC;
  	sc->sc_label.d_type = DTYPE_SCSI;
--- 710,737 ----
  	msg = readdisklabel(dev, rzstrategy, lp, &cd);
  	if (msg == NULL)
  		return;
! 
  	printf("rz%d: WARNING: %s\n", unit, msg);
+ #if 1
+ 	if(sc->sc_label.d_magic != DEC_LABEL_MAGIC){
+ 	  bzero(lp, sizeof (*lp));
+ 	  for (i = 0; i < MAXPARTITIONS; i++) {
+ 		sc->sc_label.d_partitions[i].p_size =
+ 			(rzdefaultpart[i].nblocks) ?
+ 			rzdefaultpart[i].nblocks: sc->sc_blks;
+ 		sc->sc_label.d_partitions[i].p_offset =
+ 			rzdefaultpart[i].strtblk;
+ 		printf(" default rz%d%c: start %d len %d\n",
+ 			unit, "abcdefgh"[i],
+ 			rzdefaultpart[i].strtblk,  rzdefaultpart[i].nblocks);
+ 	      }
+ 	}
+ 	else
+ 	  for (i = 0; i < MAXPARTITIONS; i++)
+ 	    printf(" rz%d%c: start %d len %d\n",
+ 		   unit, "abcdefgh"[i],
+ 		   sc->sc_label.d_partitions[i].p_offset,
+ 		   sc->sc_label.d_partitions[i].p_size);
  	sc->sc_label.d_magic = DISKMAGIC;
  	sc->sc_label.d_magic2 = DISKMAGIC;
  	sc->sc_label.d_type = DTYPE_SCSI;
***************
*** 707,718 ****
  	sc->sc_label.d_npartitions = MAXPARTITIONS;
  	sc->sc_label.d_bbsize = BBSIZE;
  	sc->sc_label.d_sbsize = SBSIZE;
- 	for (i = 0; i < MAXPARTITIONS; i++) {
- 		sc->sc_label.d_partitions[i].p_size =
- 			rzdefaultpart[i].nblocks;
- 		sc->sc_label.d_partitions[i].p_offset =
- 			rzdefaultpart[i].strtblk;
- 	}
  	sc->sc_label.d_partitions[RAWPART].p_size = sc->sc_blks;
  #endif
  }
--- 742,747 ----
***************
*** 740,746 ****
--- 769,782 ----
  
  	lp = &sc->sc_label;
  	if (part >= lp->d_npartitions || lp->d_partitions[part].p_size == 0)
+ 	{
+ 		printf("rzopen: ENXIO on rz%d%c unit %d part %d\n",
+ 			unit, "abcdefg"[part],  unit, part);
+ 		printf("# partions %d, size of %d = %d\n",
+ 			lp->d_npartitions, lp->d_partitions[part].p_size);
  		return (ENXIO);
+ 	}
+ 
  	/*
  	 * Warn if a partition is opened that overlaps another
  	 * already open, unless either is the `raw' partition

------------------------------------------------------------------------------