Subject: sysinst changes to handle Apple Disk Partition Map
To: port-macppc <port-macppc@NetBSD.ORG>
From: Bob Nestor <rnestor@augustmail.com>
List: port-macppc
Date: 10/20/2002 18:31:04
I ported the mac68k version of sysinst to the macppc port so it can 
handle the Apple Disk Partition Map.  You should have a good backup of 
your disk before trying this out though.

If anyone tries this out and finds a problem, please let me know.

Thanks,
-bob

Index: md.c
===================================================================
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/arch/macppc/md.c,v
retrieving revision 1.23
diff -u -r1.23 md.c
--- md.c        2002/08/02 05:11:33     1.23
+++ md.c        2002/10/20 23:03:34
@@ -1,11 +1,10 @@
-/*     $NetBSD: md.c,v 1.23 2002/08/02 05:11:33 grant Exp $    */
+/*     $NetBSD$ */

  /*
   * Copyright 1997 Piermont Information Systems Inc.
   * All rights reserved.
   *
- * Based on code written by Philip A. Nelson for Piermont Information
- * Systems Inc.
+ * Written by Philip A. Nelson for Piermont Information Systems Inc.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
@@ -37,93 +36,897 @@
   *
   */

-/* md.c -- macppc machine specific routines */
+/* md.c -- Machine specific code for macppc */

-#include <sys/types.h>
-#include <sys/disklabel.h>
-#include <sys/ioctl.h>
-#include <sys/param.h>
  #include <stdio.h>
-#include <curses.h>
+#include <util.h>
  #include <unistd.h>
  #include <fcntl.h>
-#include <util.h>
-
+#include <sys/ioctl.h>
  #include "defs.h"
  #include "md.h"
  #include "msg_defs.h"
  #include "menu_defs.h"

+/*
+ * Compare lexigraphically two strings
+ */
+int
+stricmp(s1, s2)
+       const char *s1;
+       const char *s2;
+{
+       char c1, c2;
+
+       while (1) {
+           c1 = tolower(*s1++);
+           c2 = tolower(*s2++);
+           if (c1 < c2) return -1;
+           if (c1 > c2) return 1;
+           if (c1 == 0) return 0;
+       }
+}
+
+void
+setpartition(part, in_use, slot)
+       struct part_map_entry *part;
+       char in_use[];
+       int slot;
+{
+       EBZB *bzb;
+
+       bzb = (EBZB *)&part->pmBootArgs[0];
+       in_use[slot] = 1;
+       bzb->flags.used = 1;
+       bzb->flags.part = 'a' + slot;
+}
+
+/*
+ * Find an entry in a use array that is unused and return it or
+ *  -1 if no entry is available
+ */
+int
+getFreeLabelEntry(slots)
+       char *slots;
+{
+       int i;
+
+       for ( i = 0; i < MAXPARTITIONS; i++) {
+               if (i != RAW_PART && slots[i] == 0)
+                       return i;
+       }
+       return -1;
+}
+
+/*
+ * Figure out what type type of the given partition is and return it.
+ */
+int
+whichType(part)
+       struct part_map_entry *part;
+{
+       MAP_TYPE *map_entry = (MAP_TYPE *)&map_types;
+       EBZB *bzb;
+       char partyp[32];
+       int type, maxsiz, entry_type = MAP_OTHER;
+
+       bzb = (EBZB *)&part->pmBootArgs[0];
+       if (part->pmSig != PART_ENTRY_MAGIC)
+           return 0;
+       maxsiz = sizeof(part->pmPartType);
+       if (maxsiz > sizeof(partyp))
+           maxsiz = sizeof(partyp);
+       strncpy(partyp, part->pmPartType, maxsiz);
+       partyp[maxsiz-1] = '\0';
+
+       /*
+        * Find out how to treat the partition type under NetBSD
+        */
+       while (map_entry->type != MAP_EOL) {
+           if (stricmp(map_entry->name, partyp) == 0) {
+               entry_type = map_entry->type;
+               break;
+           }
+           map_entry++;
+       }
+
+       /*
+        * Now classify the use for NetBSD
+        */
+       if (entry_type == MAP_RESERVED)
+               type = 0;
+       else if (entry_type == MAP_NETBSD) {
+           if (bzb->magic != BZB_MAGIC)
+               type = 0;
+           else if (bzb->type == BZB_TYPEFS) {
+               if (bzb->flags.root)
+                   type = ROOT_PART;
+               else if (bzb->flags.usr)
+                   type = UFS_PART;
+               else
+                   type = SCRATCH_PART;
+           } else if (bzb->type == BZB_TYPESWAP)
+               type = SWAP_PART;
+           else
+               type = SCRATCH_PART;
+       } else if (entry_type == MAP_MACOS)
+           type = HFS_PART;
+       else
+           type = SCRATCH_PART;
+       return type;
+}
+
+char *
+getFstype(part, len_type, type)
+       struct part_map_entry *part;
+       int len_type;
+       char *type;
+{
+       *type = '\0';
+       switch(whichType(part)) {
+           case ROOT_PART:
+           case UFS_PART:
+               strncpy(type, "4.2BSD", len_type);
+               break;
+           case SWAP_PART:
+               strncpy(type, "swap", len_type);
+               break;
+           case HFS_PART:
+               strncpy(type, "HFS", len_type);
+               break;
+           case SCRATCH_PART:
+           default:
+               break;
+       }
+       return (type);
+}
+
+char *
+getUse(part, len_use, use)
+       struct part_map_entry *part;
+       int len_use;
+       char *use;
+{
+       EBZB *bzb;
+       char partyp[32];
+
+       *use = '\0';
+       bzb = (EBZB *)&part->pmBootArgs[0];
+       switch(whichType(part)) {
+           case ROOT_PART:
+               if (bzb->flags.usr)
+                   strncpy(use, "Root&Usr", len_use);
+               else
+                   strncpy(use, "Root", len_use);
+               break;
+           case UFS_PART:
+               strncpy(use, "Usr", len_use);
+               break;
+           case SWAP_PART:
+               break;
+           case HFS_PART:
+               strncpy(use, "MacOS", len_use);
+               break;
+           case SCRATCH_PART:
+               strncpy(partyp, part->pmPartType, sizeof(partyp));
+               partyp[sizeof(partyp)-1] = '\0';
+               if (stricmp("Apple_Free", partyp) == 0)
+                   strncpy(use, "Free", len_use);
+               else if (stricmp("Apple_Scratch", partyp) == 0)
+                   strncpy(use, "Scratch", len_use);
+               else if (stricmp("Apple_MFS", partyp) == 0)
+                   strncpy(use, "MFS", len_use);
+               else if (stricmp("Apple_PRODOS", partyp) == 0)
+                   strncpy(use, "PRODOS", len_use);
+               else
+                   strncpy(use, "unknown", len_use);
+           default:
+               break;
+       }
+       return(use);
+}
+
+char *
+getName(part, len_name, name)
+       struct part_map_entry *part;
+       int len_name;
+       char *name;
+{
+       EBZB *bzb;
+       int fd;
+       off_t seek;
+       char devname[100], macosblk[512];
+
+       *name = '\0';
+       bzb = (EBZB *)&part->pmBootArgs[0];
+       switch(whichType(part)) {
+           case SCRATCH_PART:
+           case ROOT_PART:
+           case UFS_PART:
+               strncpy(name, bzb->mount_point, len_name);
+               break;
+           case SWAP_PART:
+               break;
+           case HFS_PART:
+               /*
+                * OK, this is stupid but it's damn nice to know!
+                */
+               snprintf (devname, sizeof(devname), "/dev/r%sc", 
diskdev);
+               /*
+                * Open the disk as a raw device
+                */
+               if ((fd = open(devname, O_RDONLY, 0)) >= 0) {
+                   seek = (off_t)part->pmPyPartStart + (off_t)2;
+                   seek *= (off_t)bsize;
+                   lseek(fd, seek, SEEK_SET);
+                   read(fd, &macosblk, sizeof(macosblk));
+                   macosblk[37+32] = '\0';
+                   strncpy(name, bzb->mount_point, len_name);
+                   strncat(name, " (", len_name-strlen(name));
+                   strncat(name, &macosblk[37], len_name-strlen(name));
+                   strncat(name, ")", len_name-strlen(name));
+               }
+               break;
+           default:
+               break;
+       }
+       return(name);
+}
+
+/*
+ * Find the first occurance of a Standard Type partition and
+ *  mark it for use along with the default mount slot.
+ */
+int
+findStdType(num_parts, in_use, type, count, alt)
+       int num_parts;
+       char in_use[];
+       int type;
+       int *count;
+       int alt;
+{
+       EBZB *bzb;
+       int i;
+
+       for (i = 0; i < num_parts; i++) {
+               bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
+               if (whichType(&map.blk[i]) != type || bzb->flags.used)
+                       continue;
+               if (type == ROOT_PART) {
+                       if (alt >= 0 && alt != bzb->cluster)
+                               continue;
+                       setpartition(&map.blk[i], in_use, 0);
+                       strcpy (bzb->mount_point, "/");
+                       *count += 1;
+               } else if (type == UFS_PART) {
+                       if (alt >= 0 && alt != bzb->cluster)
+                               continue;
+                       setpartition(&map.blk[i], in_use, 6);
+                       if (bzb->mount_point[0] == '\0')
+                               strcpy (bzb->mount_point, "/usr");
+                       *count += 1;
+               } else if (type == SWAP_PART) {
+                       setpartition(&map.blk[i], in_use, 1);
+                       *count += 1;
+               }
+               return 0;
+       }
+       return -1;
+}
+
+/*
+ * Reset the flags and reserved fields in the selected partition.
+ * This functions isn't called to process any of the reserved 
partitions
+ * where the boot code for MacOS is stored, so (hopefully) we won't
+ * do more damage that we're trying to avoid.  Eventually the NetBSD
+ * Boot Code will need to go into a partition too, but that should go
+ * into a reserved partition as well.  I'd suggest using a partition
+ * named something like "NetBSD_Boot" with a pmPartName of "Macintosh".
+ * The Apple Start Manager (in ROM) will then recognize the partition
+ * as the one containing the system bootstrip for the volume.
+ */
+void
+reset_part_flags (part)
+       struct part_map_entry *part;
+{
+       EBZB *bzb;
+
+       /*
+        * Clear out the MacOS fields that might be used for booting 
just
+        *  in case we've clobbered the boot code.
+        */
+       part->pmLgDataStart = 0;
+       part->pmPartStatus = 0x77;  /* make sure the partition shows up 
*/
+       part->pmLgBootStart = 0;
+       part->pmBootSize = 0;
+       part->pmBootLoad = 0;
+       part->pmBootLoad2 = 0;
+       part->pmBootEntry = 0;
+       part->pmBootEntry2 = 0;
+       part->pmBootCksum = 0;
+
+       /*
+        * Clear out all the NetBSD fields too.  We only clear out the 
ones
+        *  that should get reset during our processing.
+        */
+       bzb = (EBZB *)&part->pmBootArgs[0];
+       bzb->magic = 0;
+       bzb->cluster = 0;
+       bzb->inode = 0;
+       bzb->type = 0;
+       bzb->flags.root = 0;
+       bzb->flags.usr = 0;
+       bzb->flags.crit = 0;
+       bzb->flags.slice = 0;
+       bzb->flags.used = 0;
+       return;
+}
+
+/*
+ * sortmerge:
+ *  1) Moves all the Partition Map entries to the front of the Map.
+ *     This is required because some disk formatters leave holes.
+ *  2) Sorts all entries by ascending start block number.
+ *     Needed so the NetBSD algorithm for finding partitions works
+ *     consistently from a user perspective.
+ *  3) Collapse multiple adjected "free" entries into a single entry.
+ *  4) Identify the NetBSD mount_points.
+ */
+void
+sortmerge(void)
+{
+    struct part_map_entry tmp_blk;
+    char in_use[MAXPARTITIONS];
+    int i, j;
+    EBZB *bzb;
+
+    /*
+     * Step 1, squeeze out the holes that some disk formatters leave in
+     *  the Map.  Also convert any "old" Map entries to the new entry
+     *  type. Also clear out our used flag which is used to indicte
+     *  we've mapped the partition.
+     */
+    map.in_use_cnt = 0;
+    for (i=0;i<map.size-1;i++) {
+       if (map.blk[i].pmSig == 0x5453)
+           map.blk[i].pmSig = PART_ENTRY_MAGIC;
+       if (map.blk[i].pmSig != PART_ENTRY_MAGIC) {
+           for (j=i+1;j<map.size;j++) {
+               if (map.blk[j].pmSig == 0x5453)
+                   map.blk[j].pmSig = PART_ENTRY_MAGIC;
+               if (map.blk[j].pmSig == PART_ENTRY_MAGIC) {
+                   memcpy (&map.blk[i], &map.blk[j], sizeof(struct 
part_map_entry));
+                   map.blk[j].pmSig = 0;
+                   break;
+               }
+           }
+       } else {
+           map.in_use_cnt += 1;
+           bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
+           bzb->flags.used = 0;
+           bzb->flags.part = 0;
+       }
+    }
+
+    /*
+     * Step 2, sort by ascending starting block number.  Since
+     *         we've already removed the holes we only need to
+     *         deal with the in_use count of blocks.
+     */
+    for (i=0;i<map.in_use_cnt-1;i++) {
+       for (j=i+1;j<map.in_use_cnt;j++) {
+           if (map.blk[i].pmPyPartStart > map.blk[j].pmPyPartStart) {
+               memcpy (&tmp_blk, &map.blk[i],  sizeof(struct 
part_map_entry));
+               memcpy (&map.blk[i], &map.blk[j], sizeof(struct 
part_map_entry));
+               memcpy (&map.blk[j], &tmp_blk, sizeof(struct 
part_map_entry));
+           }
+       }
+    }
+
+    /*
+     * Step 3, merge adjacent free space
+     */
+    for (i=0;i<map.in_use_cnt-1;i++) {
+        if (stricmp("Apple_Free", map.blk[i].pmPartType) == 0 &&
+           stricmp("Apple_Free", map.blk[i+1].pmPartType) == 0) {
+           map.blk[i].pmPartBlkCnt += map.blk[i+1].pmPartBlkCnt;
+           map.blk[i].pmDataCnt += map.blk[i+1].pmDataCnt;
+           map.blk[i+1].pmSig = 0;
+           for (j=i+1;j<map.in_use_cnt-1;j++) {
+               memcpy (&map.blk[j], &map.blk[j+1], sizeof(struct 
part_map_entry));
+               map.blk[j+1].pmSig = 0;
+           }
+           map.in_use_cnt -= 1;
+       }
+    }
+
+    /*
+     * Step 4, try to identify the mount points for the partitions
+     *         and adjust the pmMapBlkCnt in each Map entry.  Set
+     *         up the display array for the non-reserved partitions,
+     *         and count the number of NetBSD usable partitions
+     */
+    map.hfs_cnt = 0;
+    map.root_cnt = 0;
+    map.swap_cnt = 0;
+    map.usr_cnt = 0;
+    map.usable_cnt = 0;
+    /*
+     * Clear out record of partition slots already in use
+     */
+    memset(&in_use, 0, sizeof(in_use));
+    for (i=0,j=0;i<map.in_use_cnt;i++) {
+        map.blk[i].pmSig = PART_ENTRY_MAGIC;
+        map.blk[i].pmMapBlkCnt = map.in_use_cnt;
+        if (whichType(&map.blk[i]) && (j < MAXPARTITIONS)) {
+               map.mblk[j++] = i;
+               map.usable_cnt += 1;
+       }
+    }
+    /*
+     * Fill in standard partitions.  Look for a Cluster "0" first and 
use
+     *  it, otherwise take any Cluster value.
+     */
+    if (findStdType(map.in_use_cnt, in_use, ROOT_PART, &map.root_cnt, 
0))
+       findStdType(map.in_use_cnt, in_use, ROOT_PART, &map.root_cnt, 
-1);
+    if (findStdType(map.in_use_cnt, in_use, UFS_PART, &map.usr_cnt, 0))
+       findStdType(map.in_use_cnt, in_use, UFS_PART, &map.usr_cnt, -1);
+    if (findStdType(map.in_use_cnt, in_use, SWAP_PART, &map.swap_cnt, 
0))
+       findStdType(map.in_use_cnt, in_use, SWAP_PART, &map.swap_cnt, 
-1);
+
+#if 0
+       md_debug_dump("After marking Standard Types");
+#endif
+    /*
+     * Now fill in the remaining partitions counting them by type and
+     *  assigning them the slot the where the kernel should map them.
+     * This will be where they are displayed in the Edit Map.
+     */
+    for (i=0; i < map.in_use_cnt; i++) {
+       bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
+       if (bzb->flags.used == 0) {
+           if ((j = getFreeLabelEntry(in_use)) < 0)
+               break;
+           switch (whichType(&map.blk[i])) {
+               case ROOT_PART:
+                   map.root_cnt += 1;
+                   setpartition(&map.blk[i], in_use, j);
+                   break;
+               case UFS_PART:
+                   map.usr_cnt += 1;
+                   setpartition(&map.blk[i], in_use, j);
+                   break;
+               case SWAP_PART:
+                   map.swap_cnt += 1;
+                   setpartition(&map.blk[i], in_use, j);
+                   break;
+               case HFS_PART:
+                   map.hfs_cnt += 1;
+                   setpartition(&map.blk[i], in_use, j);
+                   break;
+               case SCRATCH_PART:
+                   setpartition(&map.blk[i], in_use, j);
+               default:
+                   break;
+           }
+       }
+    }
+#if 0
+       md_debug_dump("After sort merge");
+#endif
+    return;
+}
+
+void
+disp_selected_part(sel)
+       int sel;
+{
+       int i,j;
+       char fstyp[16], use[16], name[32];
+       EBZB *bzb;
+
+       msg_table_add(MSG_part_header);
+       for (i=0;i<map.usable_cnt;i++) {
+           if (i == sel) msg_standout();
+           j = map.mblk[i];
+           getFstype(&map.blk[j], sizeof(fstyp), fstyp);
+           getUse(&map.blk[j], sizeof(use), use);
+           getName(&map.blk[j], sizeof(name), name);
+           bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+           msg_table_add(MSG_part_row, diskdev,
+               bzb->flags.part, map.blk[j].pmPyPartStart,
+                 map.blk[j].pmPartBlkCnt, fstyp, use, name);
+           if (i == sel) msg_standend();
+       }
+       return;
+}
+
+/*
+ * check for any anomalies on the requested setup
+ */
+int
+check_for_errors()
+{
+    int i, j;
+    int errs = 0;
+
+    errs = (!map.root_cnt) || (map.root_cnt > 1) || (!map.swap_cnt) ||
+          (map.swap_cnt > 1);
+
+    for (i=0;i<map.usable_cnt;i++) {
+       j = map.mblk[i];
+       if (map.blk[j].pmPyPartStart > dlsize)
+               errs++;
+       if ((map.blk[j].pmPyPartStart + map.blk[j].pmPartBlkCnt) > 
dlsize + 1)
+               errs++;
+    }
+    return(errs);
+}
+
  /*
- * Symbolic names for disk partitions.
+ * check for and report anomalies on the requested setup
   */
-#define        PART_ROOT       A
-#define        PART_RAW        C
-#define        PART_USR        G
+void
+report_errors()
+{
+    int i, j;
+    int errs = 0;
+    EBZB *bzb;
+
+    if (!map.root_cnt) {
+       msg_display_add(MSG_disksetup_no_root);
+       errs++;
+    }
+    if (map.root_cnt > 1) {
+       msg_display_add(MSG_disksetup_multiple_roots);
+       errs++;
+    }
+    if (!map.swap_cnt) {
+       msg_display_add(MSG_disksetup_no_swap);
+       errs++;
+    }
+    if (map.swap_cnt > 1) {
+       msg_display_add(MSG_disksetup_multiple_swaps);
+       errs++;
+    }
+    for (i=0;i<map.usable_cnt;i++) {
+       j = map.mblk[i];
+       if (map.blk[j].pmPyPartStart > dlsize) {
+           bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+           msg_display_add(MSG_disksetup_part_beginning,
+               diskdev, bzb->flags.part);
+           errs++;
+       }
+       if ((map.blk[j].pmPyPartStart + map.blk[j].pmPartBlkCnt) > 
dlsize) {
+           bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+           msg_display_add(MSG_disksetup_part_size,
+               diskdev, bzb->flags.part);
+           errs++;
+       }
+    }
+    if (!errs)
+       msg_display_add(MSG_disksetup_noerrors);
+    return;
+}

  int
+edit_diskmap(void)
+{
+    int i;
+
+       /* Ask full/part */
+       msg_display (MSG_fullpart, diskdev);
+       process_menu (MENU_fullpart);
+
+       map.selected = 0;
+       sortmerge();
+
+       /* If blowing away the whole disk, let user know if there
+        *  are any active disk partitions */
+       if (usefull) {
+           if (map.usable_cnt > 
(map.root_cnt+map.swap_cnt+map.usr_cnt)) {
+               msg_display (MSG_ovrwrite);
+               process_menu (MENU_noyes);
+               if (!yesno) {
+                       endwin();
+                       return (0);
+               }
+           }
+           /*
+            * mark all non-reserved partitions as "free"
+            *  then sort and merge the map into something sensible
+            */
+           for (i=0;i<map.size;i++)
+               if (whichType(&map.blk[i]))
+                   strcpy (map.blk[i].pmPartType, "Apple_Free");
+           sortmerge();
+       }
+       process_menu (MENU_editparttable);
+       return (1);
+}
+
+int
  md_get_info()
  {
         struct disklabel disklabel;
-       int fd;
+       int fd, i;
         char devname[100];
+       struct part_map_entry block;

-       snprintf (devname, 100, "/dev/r%sc", diskdev);
+       snprintf (devname, sizeof(devname), "/dev/r%sc", diskdev);

-       fd = open (devname, O_RDONLY, 0);
+       /*
+        * Open the disk as a raw device
+        */
+       fd = open(devname, O_RDONLY, 0);
         if (fd < 0) {
                 endwin();
                 fprintf (stderr, "Can't open %s\n", devname);
                 exit(1);
         }
+       /*
+        * Try to get the default disklabel info for the device
+        */
         if (ioctl(fd, DIOCGDINFO, &disklabel) == -1) {
                 endwin();
-               fprintf (stderr, "Can't read disklabel on %s.\n", 
devname);
+               fprintf (stderr, "Can't read disklabel on %s\n", 
devname);
                 close(fd);
                 exit(1);
         }
-       close(fd);
-
+       /*
+        * Get the disk parameters from the disk driver.  It should have
+        *  obained them by querying the disk itself.
+        */
+       bsize = disklabel.d_secsize;
         dlcyl = disklabel.d_ncylinders;
         dlhead = disklabel.d_ntracks;
         dlsec = disklabel.d_nsectors;
-       sectorsize = disklabel.d_secsize;
-       dlcylsize = disklabel.d_secpercyl;
-
         /*
-        * Compute whole disk size. Take max of (dlcyl*dlhead*dlsec)
-        * and secperunit,  just in case the disk is already labelled.
-        * (If our new label's RAW_PART size ends up smaller than the
-        * in-core RAW_PART size  value, updating the label will fail.)
+        * Just in case, initialize the structures we'll need if we
+        *  need to completely initialize the disk.
          */
-       dlsize = dlcyl*dlhead*dlsec;
-       if (disklabel.d_secperunit > dlsize)
-               dlsize = disklabel.d_secperunit;
-
-       /* Compute minimum NetBSD partition sizes (in sectors). */
-       minfsdmb = (80 + 4*rammb) * (MEG / sectorsize);
+       dlsize = disklabel.d_secperunit;
+       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 == 0) {
+               new_map[i].pmPartBlkCnt = dlsize;
+               new_map[i].pmDataCnt = dlsize;
+               break;
+          }
+          dlsize -= new_map[i].pmPartBlkCnt;
+       }
+       dlsize = disklabel.d_secperunit;
+#if 0
+       msg_display(MSG_dldebug, bsize, dlcyl, dlhead, dlsec, dlsize);
+       process_menu(MENU_ok);
+#endif
+       map.size = 0;
+       /*
+        * 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 {
+          /*
+           * Scan for the Partition Map entry that describes the 
Partition
+           *  Map itself.  We need to know the number of blocks 
allocated
+           *  to it and the number currently in use.
+           */
+          for (i=0;i<MAXMAXPARTITIONS;i++) {
+               lseek(fd, (off_t)(i+1) * bsize, SEEK_SET);
+               read(fd, &block, sizeof(struct part_map_entry));
+               if (stricmp("Apple_partition_map", block.pmPartType) == 
0) {
+                   map.size = block.pmPartBlkCnt;
+                   map.in_use_cnt = block.pmMapBlkCnt;
+                   map.blk = (struct part_map_entry *)malloc(map.size 
* bsize);
+                   break;
+               }
+            }
+           lseek(fd, (off_t)1 * bsize, SEEK_SET);
+           read(fd, map.blk, map.size * bsize);
+       }
+       close(fd);
+       /*
+        * Setup the disktype so /etc/disktab gets proper info
+        */
+       if (strncmp (disk->dd_name, "sd", 2) == 0) {
+           disktype = "SCSI";
+           doessf = "sf:";
+       }
+       else
+           disktype = "IDE";

-       return 1;
+       return edit_diskmap();
  }

-/*
- * hook called before writing new disklabel.
- */
  int
  md_pre_disklabel()
  {
-       return 0;
+    int fd;
+    char devname[100];
+    struct disklabel lp;
+    Block0 new_block0 = {DRIVER_MAP_MAGIC, 512, 0};
+
+    /*
+     * Danger Will Robinson!  We're about to turn that nice MacOS disk
+     *  into an expensive doorstop...
+     */
+    printf ("%s", msg_string (MSG_dodiskmap));
+
+    snprintf (devname, sizeof(devname), "/dev/r%sc", diskdev);
+    /*
+     * Open the disk as a raw device
+     */
+    if ((fd = open(devname, O_WRONLY, 0)) < 0) {
+       endwin();
+       fprintf(stderr, "Can't open %s to rewrite the Disk Map\n", 
devname);
+       exit (1);
+    }
+    /*
+     *  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);
+       }
+       new_block0.sbBlkCount = dlsize;         /* Set disk size */
+       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);
+    }
+    fsync(fd);
+    /*
+     * Well, if we get here the dirty deed has been done.
+     *
+     * Now we need to force the incore disk table to get updated. This
+     * should be done by disklabel -- which is normally called right 
after
+     * we return -- but may be commented out for the mac68k port. We'll
+     * instead update the incore table by forcing a dummy write here. 
This
+     * relies on a change in the mac68k-specific writedisklabel() 
routine.
+     * If that change doesn't exist nothing bad happens here. If 
disklabel
+     * properly updates the ondisk and incore labels everything still
+     * works. Only if we fail here and if disklabel fails are we in
+     * in a state where we've updated the disk but not the incore and
+     * a reboot is necessary.
+     *
+     * First, we grab a copy of the incore label as it existed before
+     * we did anything to it. Then we invoke the "write label" ioctl to
+     * rewrite it to disk. As a result, the ondisk partition map is
+     * re-read and the incore label is reconstructed from it. If
+     * disklabel() is then called to update again, either that fails
+     * because the mac68k port doesn't support native disklabels, or it
+     * succeeds and writes out a new ondisk copy.
+     */
+    ioctl(fd, DIOCGDINFO, &lp);    /* Get the current disk label */
+    ioctl(fd, DIOCWDINFO, &lp);    /* Write it out again */
+
+    close (fd);
+    return 0;
  }

-/*
- * hook called after writing disklabel to new target disk.
- */
  int
  md_post_disklabel(void)
  {
-       return 0;
+    struct disklabel updated_label;
+    int fd, i, no_match;
+    char devname[100], buf[80];
+    char *fst[] = {"free", "swap", " v6 ", " v7 ", "sysv", "v71k",
+                   " v8 ", "ffs ", "dos ", "lfs ", "othr", "hpfs",
+                   "9660", "boot", "ados", "hfs ", "fcor", "ex2f",
+                   "ntfs", "raid", "ccd "};
+
+    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 aren't
+     *  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 on-disk: offset      size 
type");
+       for (i=0;i<MAXPARTITIONS;i++) {
+           sprintf(buf, " %c:%13.8x%10.8x%5s%16.8x%10.8x%5s", i+'a',
+              bsdlabel[i].pi_offset, bsdlabel[i].pi_size,
+              fst[bsdlabel[i].pi_fstype],
+              updated_label.d_partitions[i].p_offset,
+              updated_label.d_partitions[i].p_size,
+              fst[updated_label.d_partitions[i].p_fstype]);
+           msg_table_add(MSG_dump_line, buf);
+       }
+       process_menu(MENU_ok2);
+    }
+    return no_match;
  }

+int
+md_debug_dump(title)
+       char *title;
+{
+       char buf[96], type;
+       char fstyp[16], use[16], name[64];
+       int i, j;
+       EBZB *bzb;
+
+       msg_clear();
+       sprintf(buf, "Apple Disk Partition Map: %s", title);
+       msg_table_add(MSG_dump_line, buf);
+       msg_table_add(MSG_dump_line,
+           "slot      base   fstype        use name");
+       for (i=0;i<map.in_use_cnt;i++) {
+          j = whichType(&map.blk[i]);
+          getFstype(&map.blk[i], sizeof(fstyp), fstyp);
+          getUse(&map.blk[i], sizeof(use), use);
+          getName(&map.blk[i], sizeof(name), name);
+          bzb = (EBZB *) &map.blk[i].pmBootArgs[0];
+          type = bzb->flags.part;
+          if (type < 'a' || type > 'h') type = '?';
+          if (j == 0) strcpy (name, "reserved for Apple");
+           sprintf(buf, " %02d:%c %08x %8s %10s %s", i+1,  type,
+               map.blk[i].pmPyPartStart, fstyp, use, name);
+           msg_table_add(MSG_dump_line, buf);
+       }
+       process_menu(MENU_okabort);
+       msg_clear();
+       return(yesno);
+}
+
  /*
   * MD hook called after upgrade() or install() has finished setting
   * up the target disk but immediately before the user is given the
@@ -134,7 +937,7 @@
   * On the macppc, we use this opportunity to install the boot blocks.
   */
  int
-md_post_newfs()
+md_post_newfs(void)
  {
         const char *bootfile = "/boot";

@@ -142,213 +945,153 @@
         cp_to_target("/usr/mdec/ofwboot", bootfile);
         sync();
         run_prog(RUN_DISPLAY, NULL, "/usr/sbin/installboot /dev/r%sa %s 
%s",
-           diskdev, "/usr/mdec/bootxx", bootfile);
+           diskdev, "/usr/mdec/bootxx", bootfile);
         return 0;
  }

-/*
- * some ports use this to copy the MD filesystem, we do not.
- */
  int
-md_copy_filesystem()
+md_copy_filesystem(void)
  {
+       if (target_already_root()) {
+               return 1;
+       }
+
         return 0;
  }

+
+
  int
-md_make_bsd_partitions()
+md_make_bsd_partitions(void)
  {
-       int i, part;
-       int remain;
-       char isize[20];
-       int maxpart = getmaxpartitions();
-
-       /*
-        * Initialize global variables that track  space used on this 
disk.
-        * Standard 4.3BSD 8-partition labels always cover whole disk.
-        */
-       ptsize = dlsize - ptstart;
-       fsdsize = dlsize;               /* actually means `whole disk' 
*/
-       fsptsize = dlsize - ptstart;    /* netbsd partition -- same as 
above */
-       fsdmb = fsdsize / MEG;
-
-       /* Ask for layout type -- standard or special */
-       msg_display (MSG_layout,
-                       (1.0*fsptsize*sectorsize)/MEG,
-                       (1.0*minfsdmb*sectorsize)/MEG,
-                       (1.0*minfsdmb*sectorsize)/MEG+rammb+XNEEDMB);
-       process_menu (MENU_layout);
+       FILE *f;
+       int i, j, pl;
+       EBZB *bzb;

-       if (layoutkind == 3) {
-               ask_sizemult(dlcylsize);
-       } else {
-               sizemult = MEG / sectorsize;
-               multname = msg_string(MSG_megname);
+       /*
+        * Scan for any problems and report them before continuing.
+        *  The user can abort installation and we'll take them back
+        *  to the main menu; continue ignoring the warnings, or
+        *  ask to reedit the Disk Partition Map.
+        */
+       while (1) {
+           if (check_for_errors()) {
+               process_menu (MENU_sanity);
+               if (yesno < 0)
+                   return (0);
+               else if (yesno)
+                   break;
+               edit_diskmap();
+           } else
+               break;
         }

-
         /* Build standard partitions */
         emptylabel(bsdlabel);

-       /* Partitions C is predefined (whole  disk). */
-       bsdlabel[C].pi_fstype = FS_UNUSED;
-       bsdlabel[C].pi_offset = 0;
-       bsdlabel[C].pi_size = dlsize;
-
-       /* Standard fstypes */
-       bsdlabel[A].pi_fstype = FS_BSDFFS;
-       bsdlabel[A].pi_bsize  = 8192;
-       bsdlabel[A].pi_fsize  = 1024;
-       bsdlabel[B].pi_fstype = FS_SWAP;
-       /* Conventionally, C is whole disk. */
-       bsdlabel[D].pi_fstype = FS_UNUSED;      /* fill out below */
-       bsdlabel[E].pi_fstype = FS_UNUSED;
-       bsdlabel[F].pi_fstype = FS_UNUSED;
-       bsdlabel[G].pi_fstype = FS_UNUSED;
-       bsdlabel[H].pi_fstype = FS_UNUSED;
-       part = D;
-
-
-       switch (layoutkind) {
-       case 1: /* standard: a root, b swap, c "unused", d /usr */
-       case 2: /* standard X: a root, b swap (big), c "unused", d /usr 
*/
-               partstart = ptstart;
-
-               /* Root */
-               /* By convention, NetBSD/macppc uses a 32Mbyte root */
-               partsize= NUMSEC(32, MEG/sectorsize, dlcylsize);
-               bsdlabel[A].pi_offset = partstart;
-               bsdlabel[A].pi_size = partsize;
-               bsdlabel[A].pi_bsize = 8192;
-               bsdlabel[A].pi_fsize = 1024;
-               strcpy (fsmount[A], "/");
-               partstart += partsize;
-
-               /* swap */
-               i = NUMSEC(layoutkind * 2 * (rammb < 32 ? 32 : rammb),
-                          MEG/sectorsize, dlcylsize) + partstart;
-               partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
-                          dlcylsize) - partstart;
-               bsdlabel[B].pi_offset = partstart;
-               bsdlabel[B].pi_size = partsize;
-               partstart += partsize;
-
-               /* /usr */
-               partsize = fsdsize - partstart;
-               bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
-               bsdlabel[PART_USR].pi_offset = partstart;
-               bsdlabel[PART_USR].pi_size = partsize;
-               bsdlabel[PART_USR].pi_bsize = 8192;
-               bsdlabel[PART_USR].pi_fsize = 1024;
-               strcpy (fsmount[PART_USR], "/usr");
-
-               break;
-
-       case 3: /* custom: ask user for all sizes */
-               ask_sizemult(dlcylsize);
-               /* root */
-               partstart = ptstart;
-               remain = fsdsize - partstart;
-               /* By convention, NetBSD/macppc uses a 32Mbyte root */
-               partsize = NUMSEC (32, MEG/sectorsize, dlcylsize);
-               snprintf (isize, 20, "%d", partsize/sizemult);
-               msg_prompt (MSG_askfsroot, isize, isize, 20,
-                           remain/sizemult, multname);
-               partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
-               bsdlabel[A].pi_offset = partstart;
-               bsdlabel[A].pi_size = partsize;
-               bsdlabel[A].pi_bsize = 8192;
-               bsdlabel[A].pi_fsize = 1024;
-               strcpy (fsmount[A], "/");
-               partstart += partsize;
-
-               /* swap */
-               remain = fsdsize - partstart;
-               i = NUMSEC(2 * (rammb < 32 ? 32 : rammb),
-                          MEG/sectorsize, dlcylsize) + partstart;
-               partsize = NUMSEC (i/(MEG/sectorsize)+1, MEG/sectorsize,
-                          dlcylsize) - partstart;
-               snprintf (isize, 20, "%d", partsize/sizemult);
-               msg_prompt_add (MSG_askfsswap, isize, isize, 20,
-                           remain/sizemult, multname);
-               partsize = NUMSEC(atoi(isize),sizemult, dlcylsize);
-               bsdlabel[B].pi_offset = partstart;
-               bsdlabel[B].pi_size = partsize;
-               partstart += partsize;
-
-               /* /usr */
-               remain = fsdsize - partstart;
-               if (remain > 0) {
-                       partsize = fsdsize - partstart;
-                       snprintf (isize, 20, "%d", partsize/sizemult);
-                       msg_prompt_add (MSG_askfsusr, isize, isize, 20,
-                                   remain/sizemult, multname);
-                       partsize = NUMSEC(atoi(isize),sizemult, 
dlcylsize);
-                       if (remain - partsize < sizemult)
-                               partsize = remain;
-                       bsdlabel[PART_USR].pi_fstype = FS_BSDFFS;
-                       bsdlabel[PART_USR].pi_offset = partstart;
-                       bsdlabel[PART_USR].pi_size = partsize;
-                       bsdlabel[PART_USR].pi_bsize = 8192;
-                       bsdlabel[PART_USR].pi_fsize = 1024;
-                       strcpy (fsmount[PART_USR], "/usr");
-                       partstart += partsize;
-               }
-
-               /* Others ... */
-               remain = fsdsize - partstart;
-               part = F;
-               if (remain > 0)
-                       msg_display (MSG_otherparts);
-               while (remain > 0 && part <= H) {
-                       partsize = fsdsize - partstart;
-                       snprintf (isize, 20, "%d", partsize/sizemult);
-                       msg_prompt_add (MSG_askfspart, isize, isize, 20,
-                                       diskdev, partition_name(part),
-                                       remain/sizemult, multname);
-                       partsize = NUMSEC(atoi(isize),sizemult, 
dlcylsize);
-                       if (remain - partsize < sizemult)
-                               partsize = remain;
-                       bsdlabel[part].pi_fstype = FS_BSDFFS;
-                       bsdlabel[part].pi_offset = partstart;
-                       bsdlabel[part].pi_size = partsize;
-                       bsdlabel[part].pi_bsize = 8192;
-                       bsdlabel[part].pi_fsize = 1024;
-                       msg_prompt_add (MSG_mountpoint, NULL,
-                                       fsmount[part], 20);
-                       partstart += partsize;
-                       remain = fsdsize - partstart;
-                       part++;
-               }
-
-               break;
+       /*
+        * The macppc port has a predefined partition for "c" which
+        *  is the size of the disk, everything else is unused.
+        */
+       for (i=0;i<MAXPARTITIONS;i++) {
+               bsdlabel[i].pi_size = 0;
+               bsdlabel[i].pi_offset = 0;
+               bsdlabel[i].pi_fstype = FS_UNUSED;
+               bsdlabel[i].pi_bsize = 0;
+               bsdlabel[i].pi_fsize = 0;
+               fsmount[i][0] = '\0';
         }
-
-
+       bsdlabel[RAW_PART].pi_size = dlsize;
         /*
-        * OK, we have a partition table. Give the user the chance to
-        * edit it and verify it's OK, or abort altogether.
+        * Now, scan through the Disk Partition Map and transfer the
+        *  information into the incore disklabel.
          */
-       if (edit_and_check_label(bsdlabel, maxpart, RAW_PART, RAW_PART) 
== 0) {
-               msg_display(MSG_abort);
-               return 0;
+       for (i=0;i<map.usable_cnt;i++) {
+           j = map.mblk[i];
+           bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+           if (bzb->flags.part) {
+               pl = bzb->flags.part - 'a';
+               switch (whichType(&map.blk[j])) {
+                   case HFS_PART:
+                       bsdlabel[pl].pi_fstype = FS_HFS;
+                       strcpy (fsmount[pl], bzb->mount_point);
+                       break;
+                   case ROOT_PART:
+                   case UFS_PART:
+                       bsdlabel[pl].pi_fstype = FS_BSDFFS;
+                       strcpy (fsmount[pl], bzb->mount_point);
+                       break;
+                   case SWAP_PART:
+                       bsdlabel[pl].pi_fstype = FS_SWAP;
+                       break;
+                   case SCRATCH_PART:
+                       bsdlabel[pl].pi_fstype = FS_OTHER;
+                       strcpy (fsmount[pl], bzb->mount_point);
+                   default:
+                       break;
+               }
+               if (bsdlabel[pl].pi_fstype != FS_UNUSED) {
+                   bsdlabel[pl].pi_size = map.blk[j].pmPartBlkCnt;
+                   bsdlabel[pl].pi_offset = map.blk[j].pmPyPartStart;
+                   if (bsdlabel[pl].pi_fstype != FS_SWAP) {
+                       bsdlabel[pl].pi_bsize = 8192;
+                       bsdlabel[pl].pi_fsize = 1024;
+                   }
+               }
+           }
         }

-       /* Disk name */
-       msg_prompt (MSG_packname, "mydisk", bsddiskname, DISKNAME_SIZE);
+       /* Disk name  - don't bother asking, just use the physical 
name*/
+       strcpy (bsddiskname, diskdev);

-       /* save label to disk for MI code to update. */
-       (void) savenewlabel(bsdlabel, 8);       /* 8 partitions in  
label */
+       /* Create the disktab.preinstall */
+       run_prog (0, NULL, "cp /etc/disktab.preinstall /etc/disktab");
+#ifdef DEBUG
+       f = fopen ("/tmp/disktab", "a");
+#else
+       f = fopen ("/etc/disktab", "a");
+#endif
+       if (f == NULL) {
+               endwin();
+               (void) fprintf (stderr, "Could not open /etc/disktab");
+               exit (1);
+       }
+       (void)fprintf (f, "%s|NetBSD installation generated:\\\n", 
bsddiskname);
+       (void)fprintf (f, "\t:dt=%s:ty=winchester:\\\n", disktype);
+       (void)fprintf (f, "\t:nc#%d:nt#%d:ns#%d:\\\n", dlcyl, dlhead, 
dlsec);
+       (void)fprintf (f, "\t:sc#%d:su#%d:\\\n", dlhead*dlsec, dlsize);
+       (void)fprintf (f, "\t:se#%d:%s\\\n", bsize, doessf);
+       for (i=0; i<8; i++) {
+               if (bsdlabel[i].pi_fstype == FS_HFS)
+                   (void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=macos:",
+                              'a'+i, bsdlabel[i].pi_size,
+                              'a'+i, bsdlabel[i].pi_offset,
+                              'a'+i);
+               else
+                   (void)fprintf (f, "\t:p%c#%d:o%c#%d:t%c=%s:",
+                              'a'+i, bsdlabel[i].pi_size,
+                              'a'+i, bsdlabel[i].pi_offset,
+                              'a'+i, 
fstypenames[bsdlabel[i].pi_fstype]);
+               if (bsdlabel[i].pi_fstype == FS_BSDFFS)
+                       (void)fprintf (f, "b%c#%d:f%c#%d",
+                                      'a'+i, bsdlabel[i].pi_bsize,
+                                      'a'+i, bsdlabel[i].pi_fsize);
+               if (i < 7)
+                       (void)fprintf (f, "\\\n");
+               else
+                       (void)fprintf (f, "\n");
+       }
+       fclose (f);

         /* Everything looks OK. */
         return (1);
  }

+
  /* Upgrade support */
  int
-md_update()
+md_update (void)
  {
-
         endwin();
         md_copy_filesystem ();
         md_post_newfs();
@@ -359,16 +1102,32 @@
         return 1;
  }

+
  void
-md_cleanup_install()
+md_cleanup_install(void)
  {
-
+       char realfrom[STRSIZE];
+       char realto[STRSIZE];
+       char sedcmd[STRSIZE];
+
+       strncpy(realfrom, target_expand("/etc/rc.conf"), STRSIZE);
+       strncpy(realto, target_expand("/etc/rc.conf.install"), STRSIZE);
+
+       sprintf(sedcmd, "sed 's/rc_configured=NO/rc_configured=YES/' < 
%s > %s",
+           realfrom, realto);
+       scripting_fprintf(log, "%s\n", sedcmd);
+       do_system(sedcmd);
+
+       run_prog(RUN_FATAL, NULL, "mv -f %s %s", realto, realfrom);
+       run_prog(0, NULL, "rm -f %s", target_expand("/sysinst"));
+       run_prog(0, NULL, "rm -f %s", target_expand("/.termcap"));
+       run_prog(0, NULL, "rm -f %s", target_expand("/.profile"));
  }

  int
  md_pre_update()
  {
-       return 1;
+       return 0;
  }

  void
Index: md.h
===================================================================
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/arch/macppc/md.h,v
retrieving revision 1.7
diff -u -r1.7 md.h
--- md.h        2001/11/29 23:20:59     1.7
+++ md.h        2002/10/20 23:03:35
@@ -1,17 +1,16 @@
-/*     $NetBSD: md.h,v 1.7 2001/11/29 23:20:59 thorpej Exp $   */
+/*     $NetBSD$        */

  /*
   * Copyright 1997 Piermont Information Systems Inc.
   * All rights reserved.
   *
- * Based on code written by Philip A. Nelson for Piermont Information
- * Systems Inc.
+ * Written by Philip A. Nelson for Piermont Information Systems Inc.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
+ *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in 
the
   *    documentation and/or other materials provided with the 
distribution.
@@ -37,21 +36,218 @@
   *
   */

+#include <sys/disklabel.h>
+
  /* md.h -- Machine specific definitions for the macppc */
+
+/*
+ * Apple Partition Map Types
+ *    Reserved - Entry hidden by sysinst from user
+ *    NetBSD   - Entry used for NetBSD
+ *    MacOS    - Entry used for MacOS and mapped to NetBSD
+ *    Other    - Entry use unknown, mapped for scratch. This may
+ *               include partitions used by other systems (Linux).
+ */
+#define MAP_EOL      0
+#define MAP_RESERVED 1
+#define MAP_NETBSD   2
+#define MAP_MACOS    3
+#define MAP_OTHER    4
+
+typedef struct {
+       int type;               /* Entry type from above */
+       char *name;             /* Partition Type string */
+} MAP_TYPE;
+
+/*
+ * Define Apple Partition Map types typically seen on 68k Macs
+ *    This should match the definitions in include/machine/disklabel.h
+ *    and must conform to the matching rules in 
arch/macppc/macppc/disksubr.c
+ */
+EXTERN MAP_TYPE map_types[]
+#ifdef MAIN
+= {
+       {MAP_RESERVED, PART_TYPE_DRIVER},
+       {MAP_RESERVED, PART_TYPE_DRIVER43},
+       {MAP_RESERVED, PART_TYPE_DRIVERATA},
+       {MAP_RESERVED, PART_TYPE_DRIVERIOKIT},
+       {MAP_RESERVED, PART_TYPE_FWDRIVER},
+       {MAP_RESERVED, PART_TYPE_FWB_COMPONENT},
+       {MAP_OTHER,    PART_TYPE_FREE},
+       {MAP_MACOS,    PART_TYPE_MAC},
+       {MAP_MACOS,    PART_TYPE_APPLEUFS},
+       {MAP_NETBSD,   PART_TYPE_NETBSD},
+       {MAP_RESERVED, PART_TYPE_NBSD_PPCBOOT},
+       {MAP_RESERVED, PART_TYPE_NBSD_68KBOOT},
+       {MAP_RESERVED, PART_TYPE_PATCHES},
+       {MAP_RESERVED, PART_TYPE_PARTMAP},
+       {MAP_OTHER,    PART_TYPE_SCRATCH},
+       {MAP_OTHER,    PART_TYPE_BOOT},
+       {MAP_OTHER,    PART_TYPE_LOADER},
+       {MAP_NETBSD,   PART_TYPE_UNIX},
+       {MAP_OTHER,    PART_TYPE_LINUX},
+       {MAP_OTHER,    PART_TYPE_LINUX_SWAP},
+       {MAP_EOL,      NULL}
+}
+#endif
+;
+
+/*
+ * Define NetBSD partition types
+ */
+#define ROOT_PART 1
+#define UFS_PART 2
+#define SWAP_PART 3
+#define HFS_PART 4
+#define SCRATCH_PART 5
+
+EXTERN int bcyl, bhead, bsec, bsize, bcylsize;
+EXTERN int part[4][5] INIT({{0}});
+EXTERN int bsdpart;                    /* partition in use by NetBSD */
+EXTERN int usefull;                    /* on install, clobber entire 
disk */

-/* Constants and defines */
+typedef struct {
+        int size;               /* number of blocks in map for I/O */
+        int in_use_cnt;         /* number of block in current use in 
map */
+        int usable_cnt;         /* number of partitions usable by 
NetBSD */
+        int hfs_cnt;            /* number of MacOS partitions found */
+        int root_cnt;           /* number of root partitions in map */
+        int swap_cnt;           /* number of swap partitions in map */
+        int usr_cnt;            /* number of usr partitions in map */
+        int selected;           /* current partition selection in mblk 
*/
+       int mblk[MAXPARTITIONS];/* map block number of usable partition 
*/
+        struct part_map_entry *blk;
+} MAP;

+/*
+ * Define the default size for the Disk Partition Map if we have to
+ *  write one to the disk.  It should be a power of two minus one for
+ *  the Block0 block, i.e. 7, 15, 31, 63.
+ */
+#define NEW_MAP_SIZE 15
+
+EXTERN MAP map
+#ifdef MAIN
+= {0, 0, 0, 0, 0, 0, 0, 0, {0}}
+#endif
+;
+
+int    edit_diskmap (void);
+void   disp_selected_part (int sel);
+int    whichType(struct part_map_entry *);
+char   *getFstype(struct part_map_entry *, int, char *);
+char   *getUse(struct part_map_entry *, int, char *);
+char   *getName(struct part_map_entry *, int, char *);
+int    stricmp(const char *c1, const char *c2);
+int    getFreeLabelEntry(char *);
+int    findStdType(int, char *, int, int *, int);
+void   setpartition(struct part_map_entry *, char *, int);
+void   sortmerge(void);
+void   reset_part_flags(struct part_map_entry *);
+int    check_for_errors(void);
+void   report_errors(void);
+void   set_fdisk_info (void);          /* write incore info into disk 
*/
+int    get_diskmap_info (void);
+void   md_select_kernel(void);
+int    md_debug_dump(char *);
+
+/* constants and defines */
+
+/*
+ * The Block Zero Block is stored in the Partition Map Entry in the
+ *  pmPad (or pmBootArgs) area.  The current NetBSD definition of this
+ *  area is incomplete, so we have our own local definition here.
+ */
+typedef struct {
+    u_int32_t magic;   /* magic number that identifes Block Zero Block 
*/
+    u_int8_t cluster;  /* Autorecovery cluster grouping */
+    u_int8_t type;     /* 1=>Std FS, 2=>Autorecovery FS, 3=>SWAP FS */
+    u_int16_t inode;   /* bad block inode number */
+    struct {
+       unsigned int root : 1;  /* FS contains a Root FS */
+       unsigned int usr  : 1;  /* FS contains a Usr FS */
+       unsigned int crit : 1;  /* FS contains a "Critical"? FS */
+       unsigned int used : 1;  /* FS in use */
+       unsigned int      : 7;
+       unsigned int slice : 5; /* Slice number to assocate with plus 
one */
+       unsigned int part  : 16; /* reserved, but we'll hide disk part 
here */
+    } flags;
+    u_int32_t tmade;   /* time FS was created */
+    u_int32_t tmount;  /* time of last mount */
+    u_int32_t tumount; /* time of last umount */
+    struct {
+       u_int32_t size;         /* size of map in bytes */
+       u_int32_t ents;         /* number of used entries */
+       u_int32_t start;        /* start of cltblk map */
+    } abm;             /* altblk map */
+    u_int32_t filler[7];       /* reserved for abm expansion */
+    u_int8_t mount_point[64];  /* mount point for the FS */
+} 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;
+
+/*
+ * Default Disk Partition Map used for an uninitilized disk.
+ *  Has minimal entry for an old Apple SCSI driver, a newer 43 SCSI
+ *  driver and an IDE driver (for those Macs with IDE).
+ */
+EXTERN struct part_map_entry new_map[]
+#ifdef MAIN
+= {
+  {PART_ENTRY_MAGIC, 0xa5a5, 6,   1,   NEW_MAP_SIZE & 0x7e, "Apple",
+       "Apple_Partition_Map", 0,NEW_MAP_SIZE, 0x37},
+  {PART_ENTRY_MAGIC, 0, 6, 64, 32, "Macintosh", "Apple_Driver", 
0,0,0x37},
+  {PART_ENTRY_MAGIC, 0, 6, 96, 64, "Macintosh", "Apple_Driver43", 
0,0,0x37},
+  {PART_ENTRY_MAGIC, 0, 6, 160, 64, "Macintosh", "Apple_Driver_ATA", 
0,0,0x37},
+  {PART_ENTRY_MAGIC, 0, 6, 224, 4096, "untitled", "Apple_HFS", 
0,0,0x37},
+  {PART_ENTRY_MAGIC, 0, 6,4320, 0, "untitled", "Apple_Free", 0,0,0x37}
+}
+#endif
+;
+
  /* Megs required for a full X installation. */
-#define XNEEDMB 35     /* XXXTHORPEJ */
+#define XNEEDMB 35      /* XXXTHORPEJ */
+
+/* Disk names. */
+EXTERN char *disk_names[]
+#ifdef MAIN
+= {"wd", "sd", NULL}
+#endif
+;

+/* Legal start character for a disk for checking input. */
+#define ISDISKSTART(dn)        (dn == 'w' || dn == 's')
+
  /*
- * Default filesets to fetch and install during installation
- * or upgrade.
+ * Machine-specific command to write a new label to a disk.
+ * If not defined, we assume the port does not support disklabels and
+ * the hand-edited disklabel will NOT be written by MI code.
   */
+#define DISKLABEL_CMD   "disklabel -w -r"
+
+/* Definition of files to retrieve from ftp. */
  EXTERN distinfo dist_list[]
  #ifdef MAIN
  = {
-    {"kern-GENERIC",   1, NULL, "Kernel       : "},
+    {"kern-GENERIC",   0, NULL, "Kernel       : "},
      {"base",           1, NULL, "Base         : "},
      {"etc",            1, NULL, "System (/etc): "},
      {"comp",           1, NULL, "Compiler     : "},
@@ -71,30 +267,12 @@
  #endif
  ;

-/*
- * Disk names accepted as valid targets for a from-scratch 
installation.
- */
-EXTERN char *disk_names[]
-#ifdef MAIN
-= {"sd", "wd", NULL}
-#endif
-;
-
  /*
- * Legal start character for a disk for checking input.
- * this must return 1 for a character that matches the first
- * characters of each member of disk_names.
+ * Default fileystem type for floppy disks.
   */
-#define ISDISKSTART(dn)        (dn == 's' || dn == 'w')
+EXTERN char *fdtype INIT("msdos");

  /*
- * Machine-specific command to write a new label to a disk.
- * If not defined, we assume the port does not support disklabels and
- * the hand-edited disklabel will NOT be written by MI code.
+ *  prototypes for MD code.
   */
-#define        DISKLABEL_CMD   "disklabel -w -r"

-/*
- * Default file system type for floppies.
- */
-EXTERN char *fdtype INIT("msdos");
Index: menus.md.en
===================================================================
RCS file: 
/cvsroot/basesrc/distrib/utils/sysinst/arch/macppc/menus.md.en,v
retrieving revision 1.15
diff -u -r1.15 menus.md.en
--- menus.md.en 2001/11/29 23:20:59     1.15
+++ menus.md.en 2002/10/20 23:03:37
@@ -1,11 +1,10 @@
-/*     $NetBSD: menus.md.en,v 1.15 2001/11/29 23:20:59 thorpej Exp $   
*/
+/*     $NetBSD$        */

  /*
   * Copyright 1997 Piermont Information Systems Inc.
   * All rights reserved.
   *
- * Based on code written by Philip A. Nelson for Piermont Information
- * Systems Inc.
+ * Written by Philip A. Nelson for Piermont Information Systems Inc.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
@@ -37,9 +36,304 @@
   *
   */

-/* macppc machine dependent menus, english */
+/* Menu definitions for sysinst. macppc version, machine dependent. */

-menu editfsparts, y=12, exit;
+menu fullpart, title  "Select your choice";
+       option "Use only part of the disk", exit, action  {usefull = 
0;};
+       option "Use the entire disk",       exit, action  {usefull = 
1;};
+
+menu nodiskmap, title "Choose an option", y=16;
+       display action { msg_display (MSG_nodiskmap, diskdev); };
+       option "Abort install", exit, action {
+               endwin();  exit(1);
+       };
+       option "Initialize Disk partition Map", exit, action {
+               int i;
+
+               msg_clear();
+               msg_display (MSG_okwritediskmap);
+               process_menu (MENU_okabort);
+               if (!yesno) {
+                   endwin();
+                   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));
+       };
+
+menu editparttable, title  "Choose your partition", exit, y=15;
+       display action  { msg_display (MSG_editparttable);
+                         sortmerge();
+                         if (map.selected >= map.usable_cnt)
+                               map.selected = 0;
+                          disp_selected_part (map.selected);
+                       };
+       option "Select next partition",  action {
+               map.selected += 1;
+               if (map.selected >= map.usable_cnt)
+                       map.selected = 0;
+               };
+       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];
+               EBZB *bzb;
+
+               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;
+                       bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+                       bzb->magic = 0;
+                       bzb->mount_point[0] = '\0';
+                       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;
+                       bzb = (EBZB *)&map.blk[k].pmBootArgs[0];
+                       bzb->magic = 0;
+                       bzb->mount_point[0] = '\0';
+                       map.in_use_cnt += 1;    /* Count new part as 
usable */
+                       sortmerge();
+                   } 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 {
+                int i = map.mblk[map.selected];
+                EBZB *bzb = (EBZB *)&map.blk[i].pmBootArgs[0];
+                msg_display(MSG_partdebug, diskdev, bzb->flags.part,
+                        map.blk[i].pmPyPartStart,
+                        map.blk[i].pmPartBlkCnt);
+                if ((map.blk[i].pmPyPartStart +
+                    map.blk[i].pmPartBlkCnt) > dlsize) {
+                       msg_display_add(MSG_parttable_fix_fixing,
+                                diskdev, bzb->flags.part);
+                        map.blk[i].pmPartBlkCnt =
+                            dlsize - map.blk[i].pmPyPartStart;
+                        map.blk[i].pmDataCnt =
+                            map.blk[i].pmPartBlkCnt;
+                } else {
+                   msg_display_add(MSG_parttable_fix_fine,
+                        diskdev, bzb->flags.part);
+                }
+                process_menu(MENU_ok);
+                };
+
+
+menu ok2, title "Abort?", y=17;
+       option "OK", exit, action { };
+
+menu okabort, title "What do you want to do?", y=17;
+       option "Continue", exit, action { yesno = 1; };
+       option "Abort install", exit, action { yesno = 0; };
+
+menu chooseid, title  "Partition Type?";
+       option "NetBSD Root", exit, action {
+               int i, j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               reset_part_flags(&map.blk[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;
+               /*
+                * Automatically determine root mount points.  The first
+                *  root-type filesystem is mounted on "/", all others
+                *  will mount on "/altroot".  If there are multiple
+                *  occurances of "/altroot" they will be picked up on
+                *  the sanity_scan in the next step of the 
installation.
+                */
+               for (i=0,map.root_cnt=0;i<map.usable_cnt;i++) {
+                   j = map.mblk[i];
+                   if (whichType(&map.blk[j]) == ROOT_PART) {
+                       bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+                       if (bzb->type == BZB_TYPEFS && bzb->flags.root) 
{
+                          if (map.root_cnt++ == 0)
+                               strcpy (bzb->mount_point, "/");
+                          else
+                               strcpy (bzb->mount_point, "/altroot");
+                       }
+                   }
+               } };
+       option "NetBSD SWAP", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               reset_part_flags(&map.blk[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 {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               reset_part_flags(&map.blk[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;
+               if (map.usr_cnt++ == 0)
+                   strcpy (bzb->mount_point, "/usr");
+               };
+       option "NetBSD Root&Usr", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               reset_part_flags(&map.blk[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;
+               bzb->flags.usr = 1;
+               if (map.root_cnt++ == 0)
+                   strcpy (bzb->mount_point, "/");
+               else {
+                    if (map.usr_cnt++ == 0)
+                       strcpy (bzb->mount_point, "/usr");
+               } };
+       option "MacOS HFS", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               reset_part_flags(&map.blk[j]);
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               bzb->magic = 0;
+               bzb->mount_point[0] = '\0';
+               strcpy (map.blk[j].pmPartName, "untitled (HFS)");
+               strcpy (map.blk[j].pmPartType, "Apple_HFS"); };
+       option "Scratch", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               reset_part_flags(&map.blk[j]);
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               bzb->magic = 0;
+               bzb->mount_point[0] = '\0';
+               strcpy (map.blk[j].pmPartName, "untitled (Scratch)");
+               strcpy (map.blk[j].pmPartType, "Apple_Scratch"); };
+       option "Free", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               reset_part_flags(&map.blk[j]);
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               bzb->magic = 0;
+               bzb->mount_point[0] = '\0';
+               strcpy (map.blk[j].pmPartName, "untitled (Free)");
+               strcpy (map.blk[j].pmPartType, "Apple_Free"); };
+
+menu mount_point, title  "Mount Point?";
+       option "/usr", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               strcpy (bzb->mount_point, "/usr"); };
+       option "/home", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               strcpy (bzb->mount_point, "/home"); };
+       option "/var", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               strcpy (bzb->mount_point, "/var"); };
+       option "/tmp", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               strcpy (bzb->mount_point, "/tmp"); };
+       option "None", exit, action {
+               int j;
+               EBZB *bzb;
+
+               j = map.mblk[map.selected];
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               bzb->mount_point[0] = '\0'; };
+       option "other", exit, action {
+               int j;
+               char buf[60];
+               EBZB *bzb;
+
+               msg_display (MSG_custom_mount_point);
+               msg_prompt_add (MSG_mountpoint, NULL, buf, sizeof(buf));
+               j = map.mblk[map.selected];
+               bzb = (EBZB *)&map.blk[j].pmBootArgs[0];
+               if (buf[0] != '\0') {
+                   bzb->mount_point[0] = '\0';
+                   if (buf[0] != '/')
+                       strcpy (bzb->mount_point, "/");
+                   strcat(bzb->mount_point, buf);
+               } };
+
+menu sanity, title "Choose an option";
+       display action {msg_display (MSG_sanity_check);
+               report_errors(); };
+       option "Abort installation", exit, action {yesno = -1; };
+       option "Ignore warnings and continue", exit, action {yesno = 
1;};
+       option "Re-edit Disk Partition Map", exit, action {yesno = 0; };
+
+/*
+ * This menu shouldn't be used in the macppc port, but it needs to be
+ *  defined because it's referenced from the toplevel code.
+ */
+menu editfsparts, y=13, exit;
         display action  {
                         ask_sizemult(dlcylsize);
                         msg_display(MSG_fspart, multname);
@@ -47,27 +341,26 @@
                 };
         option "Change a", action { editpart = A;}, sub menu edfspart;
         option "Change b", action { editpart = B;}, sub menu edfspart;
-       option "Whole disk - can't change", action {};
-       option "Change d", action { editpart = D;}, sub menu edfspart;
         option "Change e", action { editpart = E;}, sub menu edfspart;
         option "Change f", action { editpart = F;}, sub menu edfspart;
         option "Change g", action { editpart = G;}, sub menu edfspart;
         option "Change h", action { editpart = H;}, sub menu edfspart;
         option "Set new allocation size", action { 
reask_sizemult(dlcylsize); };
-
+
  menu md_distcustom, x=26, y=5, exit, title "Selection toggles 
inclusion";
         display action { show_cur_distsets (); };
         option  "Kernel (GENERIC)",      action { toggle_getit (0); };
-       option  "Base",                  action { toggle_getit (1); };
-       option  "System (/etc)",         action { toggle_getit (2); };
-       option  "Compiler Tools",        action { toggle_getit (3); };
-       option  "Games",                 action { toggle_getit (4); };
-       option  "Online Manual Pages",   action { toggle_getit (5); };
-       option  "Miscellaneous",         action { toggle_getit (6); };
-       option  "Text Processing Tools", action { toggle_getit (7); };
-       option  "X11 base and clients",  action { toggle_getit (8); };
-       option  "X11 fonts",             action { toggle_getit (9); };
-       option  "X11 servers",           action { toggle_getit (10); };
-       option  "X contrib clients",     action { toggle_getit (11); };
-       option  "X11 programming",       action { toggle_getit (12); };
-       option  "X11 Misc.",             action { toggle_getit (13); };
+       option  "Kernel (GENERICSBC)",   action { toggle_getit (1); };
+       option  "Base",                  action { toggle_getit (2); };
+       option  "System (/etc)",         action { toggle_getit (3); };
+       option  "Compiler Tools",        action { toggle_getit (4); };
+       option  "Games",                 action { toggle_getit (5); };
+       option  "Online Manual Pages",   action { toggle_getit (6); };
+       option  "Miscellaneous",         action { toggle_getit (7); };
+       option  "Text Processing Tools", action { toggle_getit (8); };
+       option  "X11 base and clients",  action { toggle_getit (9); };
+       option  "X11 fonts",             action { toggle_getit (10); };
+       option  "X11 servers",           action { toggle_getit (11); };
+       option  "X contrib clients",     action { toggle_getit (12); };
+       option  "X11 programming",       action { toggle_getit (13); };
+       option  "X11 Misc.",             action { toggle_getit (14); };
Index: msg.md.en
===================================================================
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/arch/macppc/msg.md.en,v
retrieving revision 1.5
diff -u -r1.5 msg.md.en
--- msg.md.en   2000/12/03 01:54:48     1.5
+++ msg.md.en   2002/10/20 23:03:40
@@ -1,11 +1,10 @@
-/*     $NetBSD: msg.md.en,v 1.5 2000/12/03 01:54:48 minoura Exp $      
*/
+/*     $NetBSD$        */

  /*
   * Copyright 1997 Piermont Information Systems Inc.
   * All rights reserved.
   *
- * Based on code written by Philip A. Nelson for Piermont Information
- * Systems Inc.
+ * Written by Philip A. Nelson for Piermont Information Systems Inc.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
@@ -37,12 +36,14 @@
   *
   */

-/* macppc machine dependent messages, english */
+/* MD Message catalog -- english, macppc version */

-
  message md_hello
-{If you booted from a floppy, you may now remove the disk.
+{
+}

+message dobootblks
+{Installing boot blocks on %s....
  }

  message fullpart
@@ -51,32 +52,189 @@
  Which would you like to do?
  }

-message dobootblks
-{Installing boot blocks on %s....
+message nodiskmap
+{It appears that your disk, %s, has not been formatted and initialized
+for use on MacOS.  This program gets the disk layout of your disk by
+reading the Disk Partition Map which is written by the disk formatter
+when it prepared the disk for use with the Macintosh system.  Your
+options are:
+
+* Abort the install. You can format and define a preliminary
+partition structure with any disk formatter.  Partitions do not
+have to be defined as A/UX types; the NetBSD install process will
+allow you to redefine them as necessary.
+
+* Allow sysinst to initialize the Disk Partition Map for you. The
+disk will not be MacOS bootable and may not be usable by MacOS unless
+MacOS drivers are installed with a MacOS compatible disk formatter.
+
  }

-message askfsroot
-{I will be asking for partition sizes and on some, mount points.
+message okwritediskmap
+{Sysinst will attempt to initialize your disk with a new Disk Partition
+Map using values obtained from the disk driver.  This default Map will
+include a minimal Block0 definition, a Partition Map allowing for up to
+15 disk partitions, and pre-defined partitions for the Map, disk 
drivers,
+and a minimal MacOS HFS partition. The rest of the disk will be marked
+as available for use.  The disk driver partitions will not be 
initialized
+so the volume will not be MacOS bootable.  If you choose to proceed 
from
+this point with the installation you may edit this new partition map to
+suit your NetBSD needs.  The Map will not be written to the disk until
+you have completed your partition setups.
+
+Shall we continue?}
+
+message part_header
+{Part      start       size fstype use       mount point (name)
+---- ---------- ---------- ------ --------- ------------------\n}
+
+message part_row
+{%3s%c %10d %10d %6s %-9s %s\n}
+
+message ovrwrite
+{Your disk currently has at least one MacOS HFS/HFS+ partition.  
Overwriting
+the entire disk will delete the partition and may make the disk 
unusable
+under MacOS/MacOSX.  You should consider creating a single small 
HFS/HFS+
+partition to insure that the disk can be mounted under MacOS/MacOSX.

-First the root partition.  You have %d %s left on your disk.
-Root partition size? }
+Are you really sure you want to overwrite the MacOS HFS/HFS+ 
partition(s)?
+}

-message askfsswap
-{
-Next the swap partition.  You have %d %s left on your disk.
-Swap partition size? }
+message editparttable
+{Edit Disk Partition Map: The Map on the disk has been scanned for all
+user-level partitions, but only those usable by NetBSD are displayed.
+The partition table currently looks like:

-message askfsusr
-{
-Next the /usr partition.  You have %d %s left on your disk.
-/usr partition size? }
+}
+
+message split_part
+{The disk partition you have selected will be split into two 
partitions.
+One will be an Apple_Scratch type partition and the other an Apple_Free
+type partition.  You may then change either of the partitions into one 
of
+another type.  If the Apple_Free part is physically adjacent to another
+partition which is also an Apple_Free type, the two will be 
automatically
+merged into a single Apple_Free type partition.
+
+There are %d disk blocks in the selected partition. Enter the number
+of disk blocks you would like allocated to the Apple_Scratch partition.
+Entering a value of zero, or a value greater than the number available
+will leave the selected partition unchanged.
+
+}
+
+message scratch_size
+{Size of the Apple_Scratch part of the split}
+
+message diskfull
+{You have tried to split an existing disk partition into two parts but
+there is no room in the Disk Partition Map to map the second part. This
+is probably because your disk formatter didn't reserve additional space
+in the original Disk Partition Map for future modifications such as 
this.
+Your options at this point are:
+
+* Abandon any hope of splitting this partition, with the present
+Disk Partition Map, or
+
+* Allow sysinst to install a new Disk Map on your disk. This will
+destroy all existing data on all partitions on the volume.  USE WITH 
CARE!
+
+Would you like to Abandon splitting this partition?}
+
+message custom_mount_point
+{Specify a Mount Point for the currently selected disk partition.  This
+should be a unique name, starting with a "/",  which is not being used
+for any other partition.
+
+}
+
+message sanity_check
+{In setting up the disklabel for your volume the following anomalies 
were
+found.  You may choose to ignore these and continue, but doing so may 
result
+in an installation failure. The following problems were found:
+
+}

-message otherparts
-{You still have some space remaining unallocated on your disk.  Please
-give sizes and mount points for the following partitions.
+message dodiskmap
+{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. However your new Disk Partition Map has been written 
to
+the disk and will be available the next time NetBSD is booted. Please
+reboot immediately and restart the Installation Process.
+}
+
+message mapdebug
+{Partition Map:
+HFS count: %d
+Root count: %d
+Swap count: %d
+Usr count: %d
+Usable count: %d
+}
+
+message dldebug
+{Disklabel:
+bsize: %d
+dlcyl: %d
+dlhead: %d
+dlsec: %d
+dlsize: %d
+}
+
+message partdebug
+{Partition %s%c:
+Offset: %d
+Size: %d
+}
+
+message newfsdebug
+{Running newfs on partition: %s\n
+}
+
+message geomdebug
+{Calling: %s %s\n
+}

+message geomdebug2
+{Calling: %s %d\n"
  }
+
+message disksetup_no_root
+{* No Disk Partition defined for Root!\n}
+
+message disksetup_multiple_roots
+{* Multiple Disk Partitions defined for Root\n}
+
+message disksetup_no_swap
+{* No Disk Partition defined for SWAP!\n}
+
+message disksetup_multiple_swaps
+{* Multiple Disk Partitions defined for SWAP\n}
+
+message disksetup_part_beginning
+{* Partition %s%c begins beyond end of disk\n}

-message askfspart
-{The next partition is /dev/%s%c.  You have %d %s left on your disk.
-Partition size? }
+message disksetup_part_size
+{* Partition %s%c extends beyond end of disk\n}
+
+message disksetup_noerrors
+{** No errors or anomalies found in disk setup.\n}
+
+message parttable_fix_fixing
+{Fixing partition %s%c\n}
+
+message parttable_fix_fine
+{Partition %s%c is just fine!\n}
+
+message dump_line
+{%s\n}
+
+message emulbackup
+{Either the /emul/aout or /emul directory on your system was a 
symbolic link
+pointing to an unmounted file system. It has been given a '.old' 
extension.
+Once you bring your upgraded system back up, you may need to take care
+of merging the newly created /emul/aout directory with the old one.
+}