Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-6]: src/distrib/utils/sysinst/arch/mac68k Pull up revision 1.22...
details: https://anonhg.NetBSD.org/src/rev/3c0b429cc7d7
branches: netbsd-1-6
changeset: 528295:3c0b429cc7d7
user: lukem <lukem%NetBSD.org@localhost>
date: Sat Jun 29 23:23:46 2002 +0000
description:
Pull up revision 1.22 (requested by scottr in ticket #403):
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/md.c | 813 +++++++++++++++++++++-----------
1 files changed, 519 insertions(+), 294 deletions(-)
diffs (truncated from 1049 to 300 lines):
diff -r 199cf973bfef -r 3c0b429cc7d7 distrib/utils/sysinst/arch/mac68k/md.c
--- a/distrib/utils/sysinst/arch/mac68k/md.c Sat Jun 29 23:23:37 2002 +0000
+++ b/distrib/utils/sysinst/arch/mac68k/md.c Sat Jun 29 23:23:46 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.21.2.1 2002/06/29 23:23:46 lukem 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);
+ 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;
Home |
Main Index |
Thread Index |
Old Index