Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/utils/sysinst/arch/mac68k Rework sysinst so that it ...



details:   https://anonhg.NetBSD.org/src/rev/13c83c3b3191
branches:  trunk
changeset: 533405:13c83c3b3191
user:      scottr <scottr%NetBSD.org@localhost>
date:      Sat Jun 29 17:00:18 2002 +0000

description:
Rework sysinst so that it actually works for common cases. Notably, the
partition handling has been completely rewritten to address serious data
loss issues with Mac HFS partitions, and the a.out -> ELF upgrade has
been addressed. From Bob Nestor; part 1 of 2 of a fix for PR 15528.

diffstat:

 distrib/utils/sysinst/arch/mac68k/Makefile    |    4 +-
 distrib/utils/sysinst/arch/mac68k/md.c        |  813 ++++++++++++++++---------
 distrib/utils/sysinst/arch/mac68k/md.h        |   50 +-
 distrib/utils/sysinst/arch/mac68k/menus.md.en |   45 +-
 distrib/utils/sysinst/arch/mac68k/msg.md.en   |   23 +-
 5 files changed, 596 insertions(+), 339 deletions(-)

diffs (truncated from 1359 to 300 lines):

diff -r ac36b4f3aa46 -r 13c83c3b3191 distrib/utils/sysinst/arch/mac68k/Makefile
--- a/distrib/utils/sysinst/arch/mac68k/Makefile        Sat Jun 29 15:24:03 2002 +0000
+++ b/distrib/utils/sysinst/arch/mac68k/Makefile        Sat Jun 29 17:00:18 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2001/01/14 02:38:19 mrg Exp $
+#      $NetBSD: Makefile,v 1.3 2002/06/29 17:00:18 scottr Exp $
 #
 # Makefile for mac68k
 #
@@ -7,7 +7,7 @@
 
 SRCS=  menu_defs.c msg_defs.c main.c install.c upgrade.c \
        txtwalk.c run.c factor.c net.c disks.c disks_lfs.c util.c geom.c \
-       label.c target.c md.c
+       label.c target.c md.c aout2elf.c
 
 md.o:  menu_defs.h msg_defs.h
 
diff -r ac36b4f3aa46 -r 13c83c3b3191 distrib/utils/sysinst/arch/mac68k/md.c
--- a/distrib/utils/sysinst/arch/mac68k/md.c    Sat Jun 29 15:24:03 2002 +0000
+++ b/distrib/utils/sysinst/arch/mac68k/md.c    Sat Jun 29 17:00:18 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: md.c,v 1.21 2002/02/03 20:04:31 wormey Exp $ */
+/*     $NetBSD: md.c,v 1.22 2002/06/29 17:00:18 scottr Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <sys/utsname.h>
 #include "defs.h"
 #include "md.h"
 #include "msg_defs.h"
@@ -50,45 +51,6 @@
 
 MAP map = {0, 0, 0, 0, 0, 0, 0, 0, {0}};
 
-/* prototypes */
-
-/*
- * Define the known partition type table that we use to
- *  classify what we find on disk.  The ParType fields here could use
- *  the predefined strings that exist in the NetBSD/mac68k disklabel.h
- *  file, but there they are all in uppercase.  Apple really defined
- *  these to be in mixed case, something not all 3rd party disk formatters
- *  honored.  Just to be a purist we'll use the original Apple definitions
- *  here, not that it makes a lot of difference since we always do a
- *  case insensitive string match anyway.
- *
- * Note also that the "Apple_Unix_SVR2" type is initially classified as
- *  an unknown BSD type partition. This will change to a "4.2BSD" type
- *  classification if the appropiate flags are found in the BootArgs
- *  block.  Not all 3rd party disk formatters properly set these flags
- *  so this could be an important tip-off that the disk is not properly
- *  configured for use by NetBSD.
- */
-PTYPES ptypes[] = {
-       { TYP_RSRVD, "Apple_partition_map", "reserved"},
-       { TYP_RSRVD, "Apple_Driver", "reserved"},
-       { TYP_RSRVD, "Apple_Driver43", "reserved"},
-       { TYP_RSRVD, "Apple_Driver_ATA", "reserved"},
-       { TYP_RSRVD, "Apple_Patches", "reserved"},
-       { TYP_AVAIL, "Apple_MFS", "MFS"},
-       { TYP_HFS,   "Apple_HFS", "HFS"},
-       { TYP_BSD,   "Apple_Unix_SVR2", "?BSD?"},
-       { TYP_AVAIL, "Apple_PRODOS", "PRODOS"},
-       { TYP_AVAIL, "Apple_Free", "free"},
-       { TYP_AVAIL, "Apple_Scratch", "scratch"},
-       { TYP_AVAIL,  NULL, NULL}};
-
-/*
- * Order of the BSD disk parts as they are assigned in the mac68k port
- */
-char bsd_order[] = {'g', 'd', 'e', 'f', 'h'};
-char macos_order[] = {'a', 'd', 'e', 'f', 'g', 'h'};
-
 /*
  * Define a default Disk Partition Map that can be used for an uninitialized
  *  disk.
@@ -96,24 +58,258 @@
 Block0 new_block0 = {0x4552, 512, 0};
  
 /*
- * Compare lexigraphically two strings up to a max length
+ * Compare lexigraphically two strings
  */
 int
-strnicmp(s1, s2, n)
+stricmp(s1, s2)
        const char *s1;
        const char *s2;
-       int n;
+{
+       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;
+{
+       EBZB *bzb;
+       char partyp[32];
+       int type, maxsiz;
+
+       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';
+
+       if (stricmp(PART_TYPE_DRIVER, partyp) == 0 ||
+           stricmp(PART_TYPE_DRIVER43, partyp) == 0 ||
+           stricmp(PART_TYPE_DRIVERATA, partyp) == 0 ||
+           stricmp(PART_TYPE_FWB_COMPONENT, partyp) == 0 ||
+           stricmp(PART_TYPE_PARTMAP, partyp) == 0)
+               type = 0;
+       else if (stricmp(PART_TYPE_UNIX, partyp) == 0) {
+           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 (stricmp(PART_TYPE_MAC, partyp) == 0)
+           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;
 {
-    int i;
-    char c1, c2;
-    for (i=0; i<n; i++) {
-        c1 = tolower(*s1++);
-        c2 = tolower(*s2++);
-        if (c1 < c2) return -1;
-        if (c1 > c2) return 1;
-        if (!c1) return 0;
-    }
-    return 0;
+       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);



Home | Main Index | Thread Index | Old Index