Subject: install/10811: Sysinst/mac68k sometimes corrupts disk during installation
To: None <gnats-bugs@gnats.netbsd.org>
From: None <rnestor@augustmail.com>
List: netbsd-bugs
Date: 08/10/2000 16:43:26
>Number:         10811
>Category:       install
>Synopsis:       Sysinst/mac68k sometimes corrupts disk during installation
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    install-manager
>State:          open
>Class:          support
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 10 16:44:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Bob Nestor
>Release:        NetBSD-1.5A (-current)
>Organization:
>Environment:
NetBSD pluto 1.5A NetBSD 1.5A (GENERIC) #0: Mon Jul  3 01:19:59 CDT 2000     root@pluto:/usr/src/sys/arch/mac68k/compile/GENERIC mac68k

>Description:
Sysinst/mac68k incorrectly partitions some disks resulting in disk corruption.


>How-To-Repeat:
The patches provided here improve the disk partitioning alogrithm and
add checks and diagnostic messages to help prevent corruption.

>Fix:
*** md.h	Tue Jul  4 16:16:18 2000
--- md.h.orig	Tue Jul  4 18:11:24 2000
***************
*** 84,94 ****
   */
  #define NEW_MAP_SIZE 15
  
! EXTERN MAP map
! #ifdef MAIN
! = {0, 0, 0, 0, 0, 0, 0, 0, {0} }
! #endif
! ;
  int	edit_diskmap __P((void));		
  void	disp_selected_part (int sel);
  int	part_type(int entry, char *fstyp, char *use, char *name);
--- 84,91 ----
   */
  #define NEW_MAP_SIZE 15
  
! EXTERN MAP map;
! 
  int	edit_diskmap __P((void));		
  void	disp_selected_part (int sel);
  int	part_type(int entry, char *fstyp, char *use, char *name);
***************
*** 133,159 ****
  } EBZB;
  
  /*
!  * Define a mimimal Disk Partition Map in case the disk hasn't been
!  *  previously initialized and we need to write one.  This structure
!  *  is only partially initialized here; the initialization is completed
!  *  when the disk is actually queried for a Partition Map.
   */
! EXTERN struct part_map_entry default_map[]
  #ifdef MAIN
  = {
!   {PART_ENTRY_MAGIC, 0, 7,  1,  NEW_MAP_SIZE, "Macintosh",
! 	"Apple_partition_map", 0,63, 0x73},
!   {PART_ENTRY_MAGIC, 0, 7, 0, 32, "Macintosh", "Apple_Driver", 0, 32, 0x7f},
!   {PART_ENTRY_MAGIC, 0, 7, 0, 32, "Macintosh", "Apple_Driver43", 0, 32, 0x7f},
!   {PART_ENTRY_MAGIC, 0, 7, 0, 4096, "untitled", "Apple_HFS", 0, 4096, 0x37},
!   {PART_ENTRY_MAGIC, 0, 7, 0, 32767, "NetBSD Root", "Apple_Unix_SVR2", 0, 0, 0x37},
!   {PART_ENTRY_MAGIC, 0, 7, 0, 65534, "NetBSD SWAP", "Apple_Unix_SVR2", 0, 0, 0x37},
!   {PART_ENTRY_MAGIC, 0, 7, 0, 0, "NetBSD Usr", "Apple_Unix_SVR2", 0, 0, 0x37}
  }
  #endif
  ;
  
! EXTERN struct drvr_map block0;
  
  /* Megs required for a full X installation. */
  #define XNEEDMB 50
--- 130,168 ----
  } EBZB;
  
  /*
!  * Also define Block 0 on the device.  We only use this when we have to
!  *  initialize the entire disk and then we really only care about the
!  *  Signature word, but someday someone might want to fill in other
!  *  parts.
   */
! typedef struct {
!     unsigned short	sbSig;		/* unique value for SCSI block 0 */
!     unsigned short 	sbBlkSize;	/* block size of device */
!     unsigned long 	sbBlkCount;	/* number of blocks on device */
!     unsigned short 	sbDevType;	/* device type */
!     unsigned short 	sbDevId;	/* device id */
!     unsigned long 	sbData;		/* not used */
!     unsigned short 	sbDrvrCount;	/* driver descriptor count */
!     unsigned long 	ddBlock;	/* 1st driver's starting block */
!     unsigned short 	ddSize;		/* size of 1st driver (512-byte blks) */
!     unsigned short 	ddType;		/* system type (1 for Mac+) */
!     unsigned short 	ddPad[243];	/* ARRAY[0..242] OF INTEGER; not used */
! } Block0;
! 
! EXTERN struct part_map_entry new_map[]
  #ifdef MAIN
  = {
!   {PART_ENTRY_MAGIC, 0xa5a5, 5,   1,   NEW_MAP_SIZE & 0x7e, "Macintosh",
! 	"Apple_partition_map", 0,63, 0x37},
!   {PART_ENTRY_MAGIC, 0, 5, 64, 32, "Macintosh", "Apple_Driver", 0, 32, 0x37},
!   {PART_ENTRY_MAGIC, 0, 5, 96, 32, "Macintosh", "Apple_Driver43", 0, 32, 0x37},
!   {PART_ENTRY_MAGIC, 0, 5, 128, 4096, "untitled", "Apple_HFS", 0, 4096, 0x37},
!   {PART_ENTRY_MAGIC, 0, 5,4224, 0, "untitled", "Apple_Free", 0, 0, 0x37}
  }
  #endif
  ;
  
! EXTERN Block0 new_block0;
  
  /* Megs required for a full X installation. */
  #define XNEEDMB 50
***************
*** 189,195 ****
  #ifdef MAIN
  = {
      {"kern",	1, NULL, "Kernel       : "},
!     {"kern_sbc",0, NULL, "Kernel (SBC) : "},
      {"base",	1, NULL, "Base         : "},
      {"etc",	1, NULL, "System (/etc): "},
      {"comp",	1, NULL, "Compiler     : "},
--- 198,204 ----
  #ifdef MAIN
  = {
      {"kern",	1, NULL, "Kernel       : "},
!     {"kern_sbc",1, NULL, "Kernel (SBC) : "},
      {"base",	1, NULL, "Base         : "},
      {"etc",	1, NULL, "System (/etc): "},
      {"comp",	1, NULL, "Compiler     : "},
***************
*** 217,223 ****
  /*
   *  prototypes for MD code.
   */
! void md_dump_block0(struct drvr_map *);
! void md_dump_map(int, struct part_map_entry *);
! int md_split(int, long int, int, char *, char *);
! int md_setup_disk(long int,long int, long int);
--- 226,229 ----
  /*
   *  prototypes for MD code.
   */
! 
*** md.c	Tue Jul  4 17:56:44 2000
--- md.c.orig	Tue Jul  4 18:11:12 2000
***************
*** 48,53 ****
--- 48,55 ----
  #include "msg_defs.h"
  #include "menu_defs.h"
  
+ MAP map = {0, 0, 0, 0, 0, 0, 0, 0, {0}};
+ 
  /* prototypes */
  
  /*
***************
*** 88,93 ****
--- 90,101 ----
  char macos_order[] = {'a', 'd', 'e', 'f', 'g', 'h'};
  
  /*
+  * Define a default Disk Partition Map that can be used for an uninitialized
+  *  disk.
+  */
+ Block0 new_block0 = {0x4552, 512, 0};
+  
+ /*
   * Compare lexigraphically two strings up to a max length
   */
  int
***************
*** 480,486 ****
  edit_diskmap(void)
  {
      int i;
-     long int size;
      char fstyp[16], use[16], name[64];
  
  	/* Ask full/part */
--- 488,493 ----
***************
*** 510,617 ****
  		    strcpy (map.blk[i].pmPartType, "Apple_Free");
  	    sortmerge();
  	}
!         /*
!          * If disk has a Root partition, go directly to edit
!          */
!         if (map.root_cnt) {
!            process_menu (MENU_editparttable);
!         } else { 
!            /*
!             * New installation; scan for Apple_Free slots and total space
!             */
! 	   for (i=0,size=0;i<map.size;i++)
!               if (map.blk[i].pmSig == PART_ENTRY_MAGIC &&
!                   (strnicmp(map.blk[i].pmPartType, "Apple_Free",10) == 0)) {
!                  size += map.blk[i].pmPartBlkCnt;
!               }
!            msg_display (MSG_layout, 1.0*(size/2048),
!                                     1.0*(80+4*rammb),
!                                     1.0*((80+4*rammb)+rammb+XNEEDMB)); 
!            process_menu (MENU_layout);
!            if (layoutkind == 1) {
!               if (!md_setup_disk(16*2*1024L, rammb*2*1024L, -1L)) {
!                  msg_display(MSG_disktoosmall);
!                  process_menu (MENU_ok);
!               }
! #if 1
!    	      process_menu (MENU_editparttable);   /* For debugging */
! #endif
!            }
!            else if (layoutkind == 2) {
!               if (!md_setup_disk(16*2*1024L, (rammb+XNEEDMB)*2*1024L, -1L)) {
!                  msg_display(MSG_disktoosmall);
!                  process_menu (MENU_ok);
!               }
! #if 1
!    	      process_menu (MENU_editparttable);   /* For debugging */
! #endif
!            }
!            else
!    	      process_menu (MENU_editparttable);
!         }
  	return (1);
  }
  
  int
- md_setup_disk (root, swap, usr)
-      long int root;
-      long int swap;
-      long int usr;
- {
-      int i;
-      EBZB *bp;
- 
-      /*
-       * Scan for first free slot on disk
-       */
-      for (i=0;i<map.size;i++)
-          if (map.blk[i].pmSig == PART_ENTRY_MAGIC &&
-              strnicmp(map.blk[i].pmPartType, "Apple_Free",10) == 0) {
-             if (md_split(i, root, BZB_TYPEFS, "Apple_Unix_SVR2", "/"))
-                return 0;
-             break;
-          }
-       /*
-        * Got Root setup OK, look for space for SWAP
-        */
-      for (i=0;i<map.size;i++)
-          if (map.blk[i].pmSig == PART_ENTRY_MAGIC &&
-              strnicmp(map.blk[i].pmPartType, "Apple_Free",10) == 0) {
-             if (md_split(i, swap, BZB_TYPESWAP, "Apple_Unix_SVR2", ""))
-                return 0;
-             break;
-          }
-       /*
-        * Got SWAP setup OK, Look for space for Usr
-        */
-      for (i=0;i<map.size;i++)
-          if (map.blk[i].pmSig == PART_ENTRY_MAGIC &&
-              strnicmp(map.blk[i].pmPartType, "Apple_Free",10) == 0) {
-             if (usr == -1) {
-                bp = (EBZB *)&map.blk[i].pmBootArgs;
-                bp->magic = BZB_MAGIC;
-                bp->type = BZB_TYPEFS;
-                bp->flags.usr = 1;
-                strcpy(map.blk[i].pmPartName, "NetBSD Usr");
-                strcpy(map.blk[i].pmPartType, "Apple_Unix_SVR2");
-                strcpy(bp->mount_point, "/usr");
-                break;
-            } else {
-                if (md_split(i, usr, BZB_TYPEFS, "Apple_Unix_SVR2", "/usr"))
-                   return 0;
-            }
-          }
-       return 1;
- }
- 
- int
  md_get_info()
  {
  	struct disklabel disklabel;
! 	int fd, i, rc, part;
  	char devname[100];
!         struct part_map_entry block;
!         EBZB *bp;
  
  	snprintf (devname, sizeof(devname), "/dev/r%sc", diskdev);
  
--- 517,533 ----
  		    strcpy (map.blk[i].pmPartType, "Apple_Free");
  	    sortmerge();
  	}
! 	process_menu (MENU_editparttable);
  	return (1);
  }
  
  int
  md_get_info()
  {
  	struct disklabel disklabel;
! 	int fd, i;
  	char devname[100];
! 	struct part_map_entry block;
  
  	snprintf (devname, sizeof(devname), "/dev/r%sc", diskdev);
  
***************
*** 645,684 ****
  	 * Just in case, initialize the structures we'll need if we
  	 *  need to completely initialize the disk.
  	 */
! 	dlsize = disklabel.d_secperunit - NEW_MAP_SIZE - 1;
!         default_map[0].pmDataCnt = default_map[0].pmPartBlkCnt;
! 	for (i=1,part=0;i<NEW_MAP_SIZE;i++) {
!            if (default_map[i].pmSig == PART_ENTRY_MAGIC) {
!    	       default_map[i].pmPyPartStart = default_map[i-1].pmPyPartStart +
! 			default_map[i-1].pmPartBlkCnt;
!                if (default_map[i].pmPartBlkCnt == 0)
!                   default_map[i].pmPartBlkCnt = dlsize;
! 	       dlsize -= default_map[i].pmPartBlkCnt;
! 	       default_map[i].pmDataCnt = default_map[i].pmPartBlkCnt;
!                if (strncmp(default_map[i].pmPartType, "Apple_Driver", 12) == 0
!                   && diskdev[0] == 'w')
!                   strcpy(default_map[i].pmPartType, "Apple_Driver_ATA");
!                if (strncmp(default_map[i].pmPartType, "Apple_Unix_SVR2", 15) == 0) {
!                   bp = (EBZB *)&default_map[i].pmBootArgs;
!                   bp->magic = BZB_MAGIC;
!                   if (strstr(default_map[i].pmPartName, "Root")) {
!                      bp->flags.part = 'a';
!                      bp->flags.root = 1;
!                      bp->type = BZB_TYPEFS;
!                   } else if (strstr(default_map[i].pmPartName, "SWAP")) {
!                      bp->flags.part = 'b';
!                      bp->type = BZB_TYPESWAP;
!                   } else {
!                      bp->flags.part = bsd_order[part];
!                      if (part++ == 0)
!                         strcpy (bp->mount_point, "/usr");
!                      bp->flags.usr = 1;
!                      bp->type = BZB_TYPEFS;
!                   }
!                }
!            }
  	}
! 	dlsize = disklabel.d_secperunit;
  #if 0
  	msg_display(MSG_dldebug, bsize, dlcyl, dlhead, dlsec, dlsize);
  	process_menu(MENU_ok);
--- 561,581 ----
  	 * Just in case, initialize the structures we'll need if we
  	 *  need to completely initialize the disk.
  	 */
! 	dlsize = dlsec*dlhead*dlcyl;
! 	new_block0.sbBlkCount = dlsize;
! 	for (i=0;i<NEW_MAP_SIZE;i++) {
! 	   if (i > 0)
! 		new_map[i].pmPyPartStart = new_map[i-1].pmPyPartStart +
! 			new_map[i-1].pmPartBlkCnt;
! 	   new_map[i].pmDataCnt = new_map[i].pmPartBlkCnt;
! 	   if (new_map[i].pmPartBlkCnt) {
! 		new_map[i].pmPartBlkCnt = dlsize;
! 		new_map[i].pmDataCnt = dlsize;
! 		break;
! 	   }
! 	   dlsize -= new_map[i].pmPartBlkCnt;
  	}
! 	dlsize = dlsec*dlhead*dlcyl;
  #if 0
  	msg_display(MSG_dldebug, bsize, dlcyl, dlhead, dlsec, dlsize);
  	process_menu(MENU_ok);
***************
*** 687,702 ****
  	 * Verify the disk has been initialized for MacOS use by checking
  	 *  to see if the disk have a Boot Block
  	 */
!         rc = 0;
! 	if (lseek(fd, (off_t)0 * bsize, SEEK_SET) != -1L)
! 	    rc = read(fd,  &block0, sizeof(struct drvr_map));
!         if (rc != sizeof(block0) || (block0.sbSig != DRIVER_MAP_MAGIC)) {
!              block0.sbSig = DRIVER_MAP_MAGIC;
! 	     block0.sbBlkCount = disklabel.d_secperunit;   /* Plug in reported disk size */
!              block0.sbBlockSize = 512;
!              block0.sbDevType = 1;
!              block0.sbDevID = 1;
!              block0.sbDrvrCount = 0;
               process_menu(MENU_nodiskmap);
          }
  	else {
--- 584,592 ----
  	 * Verify the disk has been initialized for MacOS use by checking
  	 *  to see if the disk have a Boot Block
  	 */
! 	if (lseek(fd, (off_t)0 * bsize, SEEK_SET) < 0 ||
! 	    read(fd,  &block, sizeof(struct part_map_entry)) < sizeof(block) ||
! 	    block.pmSig != 0x4552) {
               process_menu(MENU_nodiskmap);
          }
  	else {
***************
*** 716,724 ****
  		    break;
  	        }
              }
-             /*
-              * Now read the entire on-disk Partition Map into memory
-              */
  	    lseek(fd, (off_t)1 * bsize, SEEK_SET);
  	    read(fd, map.blk, map.size * bsize);
  	}
--- 606,611 ----
***************
*** 740,746 ****
  int
  md_pre_disklabel()
  {
!     int fd, writeable;
      char devname[100];
  
      /*
--- 627,633 ----
  int
  md_pre_disklabel()
  {
!     int fd;
      char devname[100];
  
      /*
***************
*** 750,760 ****
       * Always remember that this code was written in a town called
       *  Murphy, so anything that can go wrong will.
       */
! #if 0
!     msg_clear();
!     msg_display(MSG_dodiskmap);
!     process_menu(MENU_ok);
! #endif
  
      snprintf (devname, sizeof(devname), "/dev/r%sc", diskdev);
  
--- 637,643 ----
       * Always remember that this code was written in a town called
       *  Murphy, so anything that can go wrong will.
       */
!     printf ("%s", msg_string (MSG_dodiskmap));
  
      snprintf (devname, sizeof(devname), "/dev/r%sc", diskdev);
  
***************
*** 767,885 ****
  	exit (1);
      }
      /*
!      * OK boys and girls, here we go.  First check the sbSig field of
!      *  block0 in the incore Partition Map.  It should be DRIVER_MAP_MAGIC.
!      * We probably shouldn't write it unless it's changed, but doing so
!      *  seems to cause the kernel to update the in-core disklabel!
       */
!     if (block0.sbSig == DRIVER_MAP_MAGIC) {
!         if (lseek (fd, (off_t)1 * bsize, SEEK_SET) < 0) {
!     	    endwin();
!     	    fprintf (stderr, "Can't position disk to rewrite Disk Map\n");
! 	    close (fd);
! 	    exit (1);
!         }
!         if (write (fd, map.blk, map.size * bsize) != (map.size * bsize)) {
! 	    endwin();
! 	    fprintf(stderr, "I/O error writing Disk Map\n");
! 	    close (fd);
! 	    exit (1);
!         }
  	if (lseek (fd, (off_t)0 * bsize, SEEK_SET) < 0) {
  	    endwin();
  	    fprintf (stderr, "Can't position to write Block0\n");
  	    close (fd);
  	    exit (1);
  	}
! 	if (write (fd, &block0, bsize) != bsize) {
  	    endwin();
  	    fprintf (stderr, "I/O error writing Block0\n");
  	    close (fd);
  	    exit (1);
  	}
      }
-     fsync(fd);
-     /*
-      * Now we need to set the in-core label.  The mac68k port doesn't do
-      *  disk labels and right now there's no way to get the on-disk
-      *  label in-core without rebooting, but we'll try anyway. Actually
-      *  if the disk was previously unlabeled this will work.
-      */
-     writeable = 1;
-     ioctl(fd, DIOCWLABEL, (char *)&writeable);   /* Make label writeable */
-     if (ioctl(fd, DIOCWDINFO, &bsdlabel) != 0)
-         ioctl(fd, DIOCSDINFO, &bsdlabel);
-     writeable = 0;
-     ioctl(fd, DIOCWLABEL, (char *)&writeable);   /* Make it R/O now */
-     fsync(fd);
      /*
       * Well, if we get here the dirty deed has been done.
       */
      close (fd);
-     /*
-      * Force the system to flush the disk buffers to disk
-      */
-     sync();
      return 0;
  }
  
  int
  md_post_disklabel(void)
  {
!     struct disklabel updated_label;
!     int fd, i, no_match;
!     char devname[100], buf[80];
! 
!     snprintf(devname, sizeof(devname), "/dev/r%sc", diskdev);
!     /*
!      * Open the disk as a raw device
!      */
!     if ((fd = open(devname, O_RDONLY, 0)) < 0)
!        return 0;
!     /*
!      * Get the "new" label to see if we were successful.  If we we're
!      *  we'll return an error to keep from destroying the user's disk.
!      */
!     ioctl(fd, DIOCGDINFO, &updated_label);
!     close(fd);
!     /*
!      * Make sure the in-core label matches the on-disk one
!      */
!     no_match = 0;
!     for (i=0;i<MAXPARTITIONS;i++) {
!         if (i > updated_label.d_npartitions)
!            break;
!         if (bsdlabel[i].pi_size != updated_label.d_partitions[i].p_size)
!            no_match = 1;
!         if (bsdlabel[i].pi_size) {
!            if (bsdlabel[i].pi_offset != updated_label.d_partitions[i].p_offset)
!                no_match = 1;
!            if (bsdlabel[i].pi_fstype != updated_label.d_partitions[i].p_fstype)
!                no_match = 1;
!         }
!         if (no_match)
!            break;
!     }
!     /*
!      * If the labels don't match, tell the user why
!      */
!     if (no_match) {
!        msg_clear();
!        msg_display(MSG_label_error);
!        msg_table_add(MSG_dump_line,
!            "    in-core offset      size type  disk offset      size type");
!        for (i=0;i<MAXPARTITIONS;i++) {
!            sprintf(buf, "%4d:%13.8x%10.8x%4.2x%14.8x%10.8x%4.2x", i,
!               bsdlabel[i].pi_offset, bsdlabel[i].pi_size,
!               bsdlabel[i].pi_fstype,
!               updated_label.d_partitions[i].p_offset,
!               updated_label.d_partitions[i].p_size,
!               updated_label.d_partitions[i].p_fstype);
!            msg_table_add(MSG_dump_line, buf);
!        }
!        process_menu(MENU_ok2);
!     }
!     return no_match;
  }
  
  int
--- 650,697 ----
  	exit (1);
      }
      /*
!      * OK boys and girls, here we go.  First check the pmSigPad field of
!      *  the first block in the incore Partition Map.  It should be zero,
!      *  but if it's 0xa5a5 that means we need to write out Block0 too.
       */
!     if (map.blk[0].pmSigPad == 0xa5a5) {
  	if (lseek (fd, (off_t)0 * bsize, SEEK_SET) < 0) {
  	    endwin();
  	    fprintf (stderr, "Can't position to write Block0\n");
  	    close (fd);
  	    exit (1);
  	}
! 	if (write (fd, &new_block0, bsize) != bsize) {
  	    endwin();
  	    fprintf (stderr, "I/O error writing Block0\n");
  	    close (fd);
  	    exit (1);
  	}
+ 	map.blk[0].pmSigPad = 0;
+     }
+     if (lseek (fd, (off_t)1 * bsize, SEEK_SET) < 0) {
+ 	endwin();
+ 	fprintf (stderr, "Can't position disk to rewrite Disk Map\n");
+ 	close (fd);
+ 	exit (1);
+     }
+     if (write (fd, map.blk, map.size * bsize) != (map.size * bsize)) {
+ 	endwin();
+ 	fprintf(stderr, "I/O error writing Disk Map\n");
+ 	close (fd);
+ 	exit (1);
      }
      /*
       * Well, if we get here the dirty deed has been done.
       */
      close (fd);
      return 0;
  }
  
  int
  md_post_disklabel(void)
  {
! 	return 0;
  }
  
  int
***************
*** 949,958 ****
  	    bsdlabel[i].pi_fsize = 0;
  	    fsmount[i][0] = '\0';
  	}
-         /*
-          * Setup the "raw" partition for the disk
-          */
-         bsdlabel[RAW_PART].pi_size = block0.sbBlkCount;
  	/*
  	 * Now, scan through the Disk Partition Map and transfer the
  	 *  information into the incore disklabel.
--- 761,766 ----
***************
*** 1040,1198 ****
  	return (1);
  }
  
- int
- md_split (int slot, long int size, int fstype, char *type, char *name)
- {
-     int j = slot, k;
-     long int free_size;
-     EBZB *bp;
- 
-     /*
-      * Is there enough space in the partition to handle the request?
-      */
-     if (size > 0 && size < map.blk[j].pmPartBlkCnt) {
-         k = map.in_use_cnt+1;
-         /*
-          * Room in the Map for a new partition?
-          */
-         if (k <= map.size) {
-             memcpy (&map.blk[k], &map.blk[j], sizeof(struct part_map_entry));
-             free_size = map.blk[j].pmPartBlkCnt - size;
-             bp = (EBZB *)&map.blk[j].pmBootArgs;
-             switch (fstype) {
-                case BZB_TYPEFS:
-                   bp->magic = BZB_MAGIC;
-                   bp->type = fstype;
-                   if (strcmp(name, "/") == 0) {
-                      strcpy(map.blk[j].pmPartName, "NetBSD Root");
-                      bp->flags.root = 1;
-                   } else {
-                      strcpy(map.blk[j].pmPartName, "NetBSD Usr");
-                      bp->flags.usr = 1;
-                   }
-                   strcpy(bp->mount_point, name);
-                   break;
-                case BZB_TYPESWAP:
-                   bp->magic = BZB_MAGIC;
-                   bp->type = fstype;
-                   strcpy(map.blk[j].pmPartName, "NetBSD SWAP");
-                   break;
-                default:
-                   strcpy (map.blk[j].pmPartName, name);
-                   break;
-             }
-             strcpy (map.blk[j].pmPartType, type);
-             map.blk[j].pmPartBlkCnt = size;
-             map.blk[j].pmDataCnt = map.blk[j].pmPartBlkCnt;
-             strcpy (map.blk[k].pmPartName, "untitled");
-             strcpy (map.blk[k].pmPartType, "Apple_Free");
-             map.blk[k].pmPyPartStart += size;
-             map.blk[k].pmPartBlkCnt = free_size;
-             map.blk[k].pmDataCnt = map.blk[k].pmPartBlkCnt;
-             map.in_use_cnt += 1;
-             sortmerge();
-         }
-         else
-             return 1;   /* Map is full */
-     }
-     else
-         return 2;       /* Partition not large enough for a split */
-     return 0;           /* Split successful */
- }
- 
- /* Debugging support */
- void
- md_dump_block0 (struct drvr_map *block0)
- {
-     int i;
-     char buff[80];
- 
-     msg_table_add(MSG_dump_line, "Block 0:");
-     sprintf(buff,
-       " sbSig:       %04hx    sbBlkSize:  %04hx    sbBlkCount:  %08x",
-             block0->sbSig, block0->sbBlockSize, block0->sbBlkCount);
-     msg_table_add(MSG_dump_line, buff);
-     sprintf(buff,
-       " sbDevType:   %04hx    sbDevId:    %04hx    sbData:      %08x",
-             block0->sbDevType, block0->sbDevID, block0->sbData);
-     msg_table_add(MSG_dump_line, buff);
-     sprintf(buff, " sbDrvrCount: %04hx", block0->sbDrvrCount);
-     msg_table_add(MSG_dump_line, buff);
-     for (i=0; i<block0->sbDrvrCount; i++) {
-         sprintf(buff,
-        "   [%u]  ddBlock: %08x   ddSize:  %04hx   ddType:  %04hx",
-                i+1, block0->sb_dd[i].descBlock, block0->sb_dd[i].descSize,
-                block0->sb_dd[i].descType);
-         msg_table_add(MSG_dump_line, buff);
-     }
-     return;
- }
- 
- void
- md_dump_map (int blk, struct part_map_entry *entry)
- {
-     char buff[80], name[64], *mount_point;
-     struct blockzeroblock *bp;
- 
-     sprintf(buff, "Partition Map Block #%u Entry %s", blk,
-       blk > entry->pmMapBlkCnt ? "*** Map overflow **" : "");
-     msg_table_add(MSG_dump_line, buff);
-     sprintf(buff, " pmSig:        %04hx      pmSigPad:      %04hx",
-            entry->pmSig, entry->pmSigPad);
-     msg_table_add(MSG_dump_line, buff);
-     sprintf(buff,
-        " pmMapBlkCnt:  %08x  pmPyPartStart: %08x pmPartBlkCnt: %08x",
-            entry->pmMapBlkCnt, entry->pmPyPartStart, entry->pmPartBlkCnt);
-     msg_table_add(MSG_dump_line, buff);
-     memset(name, 0, sizeof(name));
-     strncpy(name, entry->pmPartName, sizeof(entry->pmPartName));
-     sprintf(buff, " pmPartName:   %s", name);
-     msg_table_add(MSG_dump_line, buff);
-     memset(name, 0, sizeof(name));
-     strncpy(name, entry->pmPartType, sizeof(entry->pmPartType));
-     sprintf(buff, " pmParType:    %s", name);
-     msg_table_add(MSG_dump_line, buff);
-     sprintf(buff,
-         " pmLgDataStart:%08x  pmDataCnt:     %08x pmPartStatus: %08x",
-             entry->pmLgDataStart, entry->pmDataCnt, entry->pmPartStatus);
-     msg_table_add(MSG_dump_line, buff);
-     sprintf(buff,
-         " pmLgBootStart:%08x  pmBootSize:    %08x pmBootAddr:   %08x",
-             entry->pmLgBootStart, entry->pmBootSize, entry->pmBootLoad);
-     msg_table_add(MSG_dump_line, buff);
-     sprintf(buff,
-         " pmBootAddr2:  %08x  pmBootEntry:   %08x pmBootEntry2: %08x",
-             entry->pmBootLoad2, entry->pmBootEntry, entry->pmBootEntry2);
-     msg_table_add(MSG_dump_line, buff);
-     memset(name, 0, sizeof(name));
-     strncpy(name, entry->pmProcessor, sizeof(entry->pmProcessor));
-     sprintf(buff, " pmBootCksum:  %08x  pmProcessor:   %s",
-             entry->pmBootCksum, name);
-     msg_table_add(MSG_dump_line, buff);
-     bp = (struct blockzeroblock *)(entry->pmBootArgs);
-     if (bp->bzbMagic == BZB_MAGIC) {
-        sprintf(buff,
-            "Block Zero Block  magic: %08x  cluster: %02x  type: %02x (%s)",
-            bp->bzbMagic, bp->bzbCluster, bp->bzbType,
-            bp->bzbType == 1 ? "FFS/UFS" : bp->bzbType == 2 ? "Auto-recov" : "SWAP");
-        msg_table_add(MSG_dump_line, buff);
-        sprintf(buff,
-            "  inode:  %04hx  flags: %08x (%s %s %s Slice:%d Part:%c)",
-            bp->bzbBadBlockInode, bp->bzbFlags,
-            bp->bzbFlags & BZB_ROOTFS ? "root" : "",
-            bp->bzbFlags & BZB_USRFS ? "usr" : "",
-            bp->bzbFlags & 0x2000 ? "critical" : "",
-            bp->bzbFlags & 0x1f, bp->bzbReserved);
-         msg_table_add(MSG_dump_line, buff);
-         mount_point = (char *)&bp->bzbUMountTime + sizeof(bp->bzbUMountTime);
-         mount_point += (10*sizeof(u_int32_t));
-         memset(name, 0, sizeof(name));
-         strncpy(name, mount_point, 16);
-         sprintf(buff, "  Mount point: %s", name);
-         msg_table_add(MSG_dump_line, buff);
-     }
-     return;
- }
  
  /* Upgrade support */
  int
--- 848,853 ----
*** msg.md.en	Tue Jul  4 17:09:17 2000
--- msg.md.en.orig	Tue Jul  4 18:11:51 2000
***************
*** 153,166 ****
  {Setting up the Disk Partition Map ...
  }
  
- message label_error
- {The new on-disk partition label does not match the one currently in-core.
- Any attempt to proceed will most likely result in damage to any pre-existing
- disk partitions, although your new Disk Partition Map has been written to
- the disk and will be available as soon as this program terminates. If you
- wish to continue with the installation at this time, then completely exit
- sysinst via the menus, and re-invoke it via "./sysinst".\n}
- 
  message mapdebug
  {Partition Map:
  HFS count: %d
--- 153,158 ----
***************
*** 223,228 ****
  
  message parttable_fix_fine
  {Partition %s%c is just fine!\n}
- 
- message dump_line
- {%s\n}
--- 215,217 ----
*** menus.md.en	Tue Jul  4 17:03:30 2000
--- menus.md.en.orig	Tue Jul  4 18:11:38 2000
***************
*** 46,52 ****
  	display action { msg_display (MSG_nodiskmap, diskdev); };
  	option "Abort install",
  		action (endwin)  { exit(1); };
! 	option "Initialize Disk partition Map", exit, action {
  		int i;
  
  		msg_clear();
--- 46,52 ----
  	display action { msg_display (MSG_nodiskmap, diskdev); };
  	option "Abort install",
  		action (endwin)  { exit(1); };
! 	option "Initialize Disk partition Map", action {
  		int i;
  
  		msg_clear();
***************
*** 57,67 ****
  		    return 0;
  		}
  	 	map.size = NEW_MAP_SIZE;
! 		map.in_use_cnt = default_map[0].pmMapBlkCnt;
  		map.blk = (struct part_map_entry *)calloc(map.size,
  			sizeof(struct part_map_entry));
  		for (i=0;i<map.size;i++)
! 		    memcpy (&map.blk[i], &default_map[i],
  			 sizeof(struct part_map_entry));
   	};
  
--- 57,67 ----
  		    return 0;
  		}
  	 	map.size = NEW_MAP_SIZE;
! 		map.in_use_cnt = new_map[0].pmMapBlkCnt;
  		map.blk = (struct part_map_entry *)calloc(map.size,
  			sizeof(struct part_map_entry));
  		for (i=0;i<map.size;i++)
! 		    memcpy (&map.blk[i], &new_map[i],
  			 sizeof(struct part_map_entry));
   	};
  
***************
*** 80,105 ****
  	option "Change selected partition", sub menu chooseid;
  	option "Set mount point for partition", sub menu mount_point;
  	option "Split selected partition", action {
! 		int i, j;
!                 long int size;
!                 char buf[40];
  
  		j = map.mblk[map.selected];
  		msg_display(MSG_split_part, map.blk[j].pmPartBlkCnt);
  		msg_prompt_add (MSG_scratch_size, NULL, buf, sizeof(buf));
  		size = atoi(buf);
!                 if (md_split(j, size, 0, "Apple_Scratch", "untitled")) {
! 	 	   msg_display (MSG_diskfull);
! 		   process_menu (MENU_okabort);
! 		   if (!yesno) {
! 			free (map.blk);
! 	 		map.size = NEW_MAP_SIZE;
! 		 	map.in_use_cnt = default_map[0].pmMapBlkCnt;
! 		 	map.blk = (struct part_map_entry *)calloc(map.size,
  				sizeof(struct part_map_entry));
! 			for (i=0;i<map.size;i++)
! 		    	   memcpy (&map.blk[i], &default_map[i],
  			 	    sizeof(struct part_map_entry));
  		    }
  		} };
          option "Fix selected partition", action {
--- 80,124 ----
  	option "Change selected partition", sub menu chooseid;
  	option "Set mount point for partition", sub menu mount_point;
  	option "Split selected partition", action {
! 		int i, j, k, size, free_size;
! 		char buf[40];
  
  		j = map.mblk[map.selected];
  		msg_display(MSG_split_part, map.blk[j].pmPartBlkCnt);
  		msg_prompt_add (MSG_scratch_size, NULL, buf, sizeof(buf));
  		size = atoi(buf);
! 		if (size > 0 && size < map.blk[j].pmPartBlkCnt) {
! 		    k = map.in_use_cnt+1;
! 		    if (k <= map.size) {
! 			memcpy (&map.blk[k], &map.blk[j],
! 			    sizeof(struct part_map_entry));
! 			free_size = map.blk[j].pmPartBlkCnt - size;
! 			strcpy (map.blk[j].pmPartType, "Apple_Scratch");
! 			map.blk[j].pmPartBlkCnt = size;
! 			map.blk[j].pmDataCnt = size;
! 			strcpy (map.blk[k].pmPartType, "Apple_Free");
! 			map.blk[k].pmPyPartStart += size;
! 			if ((map.blk[k].pmPyPartStart + free_size) > dlsize)
! 			    map.blk[k].pmPartBlkCnt = 
! 				dlsize - map.blk[k].pmPyPartStart;
! 			else
! 			    map.blk[k].pmPartBlkCnt = free_size;
! 			map.blk[k].pmDataCnt = map.blk[k].pmPartBlkCnt;
! 			map.in_use_cnt += 1;
! 		    } else {
! 			msg_display (MSG_diskfull);
! 			process_menu (MENU_okabort);
! 		 	if (!yesno) {
! 			    free (map.blk);
! 	 		    map.size = NEW_MAP_SIZE;
! 			    map.in_use_cnt = new_map[0].pmMapBlkCnt;
! 			    map.blk = (struct part_map_entry *)calloc(map.size,
  				sizeof(struct part_map_entry));
! 			    for (i=0;i<map.size;i++)
! 		    		memcpy (&map.blk[i], &new_map[i],
  			 	    sizeof(struct part_map_entry));
+ 			    map.blk[0].pmSigPad = 0; /* Don't rewrite Block0 */
+ 			}
  		    }
  		} };
          option "Fix selected partition", action {
***************
*** 122,163 ****
                  }
                  process_menu(MENU_ok);
                  };
- 	option "Examine in-core map", exit, action {
-            int map_block_count = NEW_MAP_SIZE;
-            long int i, start_block = 1, max_blocks;
- 
-            msg_clear();
-            md_dump_block0((struct drvr_map *)&block0);
-            max_blocks = block0.sbBlkCount;
-            process_menu(MENU_dumpcont);
-            if (yesno) {
-               i = 0;
-               do {
-                  if (map.blk[i].pmSig == PART_ENTRY_MAGIC ||
-                      map.blk[i].pmSig == 0x5453) {
-                     msg_clear();
-                     md_dump_map(i, (struct part_map_entry *)&map.blk[i] );
-                     if (map.blk[i].pmPyPartStart != start_block)
-                        msg_table_add(MSG_dump_line,
-                           " *Error* - Partition not adjacent to previous");
-                     start_block += map.blk[i].pmPartBlkCnt;
-                     if (start_block > max_blocks)
-                        msg_table_add(MSG_dump_line,
-                           " *Error* - Partition extends past end of disk");
-                     process_menu(MENU_dumpcont);
-                     if (!yesno)
-                        break;
-                  }
-               } while (i++ < map_block_count); 
-            }
-         };
- 
- menu dumpcont, title "Continue dump", y=17;
- 	option "Next block", exit, action { yesno = 1; };
- 	option "End dump", exit, action { yesno = 0; };
  
- menu ok2, title "Continue?", y=17;
- 	option "OK", exit, action { };
  
  menu okabort, title "What do you want to do?";
  	option "OK", exit, action { yesno = 1; };
--- 141,147 ----
***************
*** 173,179 ****
  		reset_part_flags(j);
  		bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
  		bzb->magic = BZB_MAGIC;
-                 strcpy (map.blk[j].pmPartName, "NetBSD Root");
  		strcpy (map.blk[j].pmPartType, "Apple_Unix_SVR2");
  		bzb->type = BZB_TYPEFS;
  		bzb->flags.root = 1;
--- 157,162 ----
***************
*** 204,210 ****
  		reset_part_flags(j);
  		bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
  		bzb->magic = BZB_MAGIC;
-                 strcpy (map.blk[j].pmPartName, "NetBSD SWAP");
  		strcpy (map.blk[j].pmPartType, "Apple_Unix_SVR2");
  		bzb->type = BZB_TYPESWAP; };
  	option "NetBSD Usr", exit, action {
--- 187,192 ----
***************
*** 215,221 ****
  		reset_part_flags(j);
  		bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
  		bzb->magic = BZB_MAGIC;
-                 strcpy (map.blk[j].pmPartName, "NetBSD Usr");
  		strcpy (map.blk[j].pmPartType, "Apple_Unix_SVR2");
  		bzb->type = BZB_TYPEFS;
  		bzb->flags.usr = 1;
--- 197,202 ----
***************
*** 230,236 ****
  		reset_part_flags(j);
  		bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
  		bzb->magic = BZB_MAGIC;
-                 strcpy (map.blk[j].pmPartName, "NetBSD Root&Usr");
  		strcpy (map.blk[j].pmPartType, "Apple_Unix_SVR2");
  		bzb->type = BZB_TYPEFS;
  		bzb->flags.root = 1;
--- 211,216 ----
***************
*** 249,255 ****
  		reset_part_flags(j);
  		bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
  		bzb->mount_point[0] = '\0';
-                 strcpy (map.blk[j].pmPartName, "Macintosh");
  		strcpy (map.blk[j].pmPartType, "Apple_HFS"); };
  	option "Scratch", exit, action {
  		int j;
--- 229,234 ----
***************
*** 259,265 ****
  		reset_part_flags(j);
  		bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
  		bzb->mount_point[0] = '\0';
-                 strcpy (map.blk[j].pmPartName, "assignable");
  		strcpy (map.blk[j].pmPartType, "Apple_Scratch"); };
  	option "Free", exit, action {
  		int j;
--- 238,243 ----
***************
*** 269,275 ****
  		reset_part_flags(j);
  		bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
  		bzb->mount_point[0] = '\0';
-                 strcpy (map.blk[j].pmPartName, "splitable");
  		strcpy (map.blk[j].pmPartType, "Apple_Free"); };
  
  menu mount_point, title  "Mount Point?";
--- 247,252 ----


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