Source-Changes-HG archive

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

[src/netbsd-1-4]: src/sys/arch/macppc/macppc Pull up revision 1.5 (requested ...



details:   https://anonhg.NetBSD.org/src/rev/62b9e37a5aee
branches:  netbsd-1-4
changeset: 469608:62b9e37a5aee
user:      he <he%NetBSD.org@localhost>
date:      Tue Oct 19 16:49:10 1999 +0000

description:
Pull up revision 1.5 (requested by wrstuden):
  Add support for reading MacOS-partitioned disks. Stolen from the mac68k
  port, but modified in that macppc searches for netbsd-partitioned
  disks before MacOS partitioned disks, since installboot generates a
  fake MacOS partition table which isn't the one we want to use.

diffstat:

 sys/arch/macppc/macppc/disksubr.c |  579 ++++++++++++++++++++++++++++---------
 1 files changed, 436 insertions(+), 143 deletions(-)

diffs (truncated from 636 to 300 lines):

diff -r 6cfc262a0a13 -r 62b9e37a5aee sys/arch/macppc/macppc/disksubr.c
--- a/sys/arch/macppc/macppc/disksubr.c Tue Oct 19 16:42:59 1999 +0000
+++ b/sys/arch/macppc/macppc/disksubr.c Tue Oct 19 16:49:10 1999 +0000
@@ -1,6 +1,73 @@
-/*     $NetBSD: disksubr.c,v 1.4 1999/01/31 13:54:24 tsubai Exp $      */
+/*     $NetBSD: disksubr.c,v 1.4.2.1 1999/10/19 16:49:10 he Exp $      */
 
 /*
+ * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)ufs_disksubr.c      7.16 (Berkeley) 5/4/91
+ */
+/*-
+ * Copyright (C) 1993  Allen K. Briggs, Chris P. Caputo,
+ *                     Michael L. Finch, Bradley A. Grantham, and
+ *                     Lawrence A. Kesteloot
+ * All rights reserved.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the Alice Group.
+ * 4. The names of the Alice Group or any of its members may not be used
+ *    to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+/*
  * Copyright (C) 1996 Wolfgang Solfrank.
  * Copyright (C) 1996 TooLs GmbH.
  * All rights reserved.
@@ -30,47 +97,345 @@
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
+/* rewritten, 2-5-93 MLF */
+/* its alot cleaner now, and adding support for new partition types
+ * isn't a bitch anymore
+ * known bugs:
+ * 1) when only an HFS_PART part exists on a drive it gets assigned to "B"
+ * this is because of line 623 of sd.c, I think this line should go.
+ * 2) /sbin/disklabel expects the whole disk to be in "D", we put it in
+ * "C" (I think) and we don't set that position in the disklabel structure
+ * as used.  Again, not my fault.
+ */
 #include <sys/param.h>
+#include <sys/systm.h>
 #include <sys/buf.h>
 #include <sys/conf.h>
-#include <sys/device.h>
 #include <sys/disk.h>
 #include <sys/disklabel.h>
 #include <sys/disklabel_mbr.h>
-#include <sys/fcntl.h>
-#include <sys/ioctl.h>
-#include <sys/malloc.h>
-#include <sys/stat.h>
-#include <sys/systm.h>
+#include <sys/syslog.h>
+
+#include <machine/bswap.h>
+
+#define        b_cylin b_resid
+
+#define NUM_PARTS 32
+
+#define ROOT_PART 1
+#define UFS_PART 2
+#define SWAP_PART 3
+#define HFS_PART 4
+#define SCRATCH_PART 5
+
+int fat_types[] = { MBR_PTYPE_FAT12, MBR_PTYPE_FAT16S,
+                   MBR_PTYPE_FAT16B, MBR_PTYPE_FAT32,
+                   MBR_PTYPE_FAT32L, MBR_PTYPE_FAT16L,
+                   -1 };
+
+static int getFreeLabelEntry __P((struct disklabel *));
+static int whichType __P((struct part_map_entry *));
+static void setpartition __P((struct part_map_entry *,
+               struct partition *, int));
+static int getNamedType __P((struct part_map_entry *, int,
+               struct disklabel *, int, int, int *));
+static char *read_mac_label __P((dev_t, void (*)(struct buf *),
+               struct disklabel *, struct cpu_disklabel *));
+static char *read_dos_label __P((dev_t, void (*)(struct buf *),
+               struct disklabel *, struct cpu_disklabel *));
+static int get_netbsd_label __P((dev_t dev, void (*strat)(struct buf *),
+               struct disklabel *lp, daddr_t bno));
+
+/*
+ * Find an entry in the disk label that is unused and return it
+ * or -1 if no entry
+ */
+static int
+getFreeLabelEntry(lp)
+       struct disklabel *lp;
+{
+       int i = 0;
+
+       for (i = 0; i < MAXPARTITIONS; i++) {
+               if ((i != RAW_PART)
+                   && (lp->d_partitions[i].p_fstype == FS_UNUSED))
+                       return i;
+       }
+
+       return -1;
+}
+
+/*
+ * figure out what the type of the given part is and return it
+ */
+static int
+whichType(part)
+       struct part_map_entry *part;
+{
+       struct blockzeroblock *bzb;
+       char typestr[32], *s;
+       int type;
+
+       if (part->pmSig != PART_ENTRY_MAGIC || part->pmPartType[0] == '\0')
+               return 0;
+
+       strncpy(typestr, (char *)part->pmPartType, sizeof(typestr));
+       typestr[sizeof(typestr) - 1] = '\0';
+       for (s = typestr; *s; s++)
+               if ((*s >= 'a') && (*s <= 'z'))
+                       *s = (*s - 'a' + 'A');
 
-static inline unsigned short get_short __P((void *p));
-static inline unsigned long get_long __P((void *p));
-static int get_netbsd_label __P((dev_t dev, void (*strat)(struct buf *),
-                                struct disklabel *lp, daddr_t bno));
-static int mbr_to_label __P((dev_t dev, void (*strat)(struct buf *),
-                            daddr_t bno, struct disklabel *lp,
-                            unsigned short *pnpart,
-                            struct cpu_disklabel *osdep, daddr_t off));
+       if (strcmp(PART_TYPE_DRIVER, typestr) == 0 ||
+           strcmp(PART_TYPE_DRIVER43, typestr) == 0 ||
+           strcmp(PART_TYPE_DRIVERATA, typestr) == 0 ||
+           strcmp(PART_TYPE_FWB_COMPONENT, typestr) == 0 ||
+           strcmp(PART_TYPE_PARTMAP, typestr) == 0)
+               type = 0;
+       else if (strcmp(PART_TYPE_UNIX, typestr) == 0) {
+               /* unix part, swap, root, usr */
+               bzb = (struct blockzeroblock *)(&part->pmBootArgs);
+               if (bzb->bzbMagic != BZB_MAGIC)
+                       type = 0;
+               else if (bzb->bzbFlags & BZB_ROOTFS)
+                       type = ROOT_PART;
+               else if (bzb->bzbFlags & BZB_USRFS)
+                       type = UFS_PART;
+               else if (bzb->bzbType == BZB_TYPESWAP)
+                       type = SWAP_PART;
+               else
+                       type = SCRATCH_PART;
+       } else if (strcmp(PART_TYPE_MAC, typestr) == 0)
+               type = HFS_PART;
+       else
+               type = SCRATCH_PART;    /* no known type */
+
+       return type;
+}
+
+static void
+setpartition(part, pp, fstype)
+       struct part_map_entry *part;
+       struct partition *pp;
+{
+       pp->p_size = part->pmPartBlkCnt;
+       pp->p_offset = part->pmPyPartStart;
+       pp->p_fstype = fstype;
+
+       part->pmPartType[0] = '\0';
+}
+
+static int
+getNamedType(part, num_parts, lp, type, alt, maxslot)
+       struct part_map_entry *part;
+       int num_parts;
+       struct disklabel *lp;
+       int type, alt;
+       int *maxslot;
+{
+       struct blockzeroblock *bzb;
+       int i = 0;
+
+       for (i = 0; i < num_parts; i++) {
+               if (whichType(part + i) != type)
+                       continue;
+
+               if (type == ROOT_PART) {
+                       bzb = (struct blockzeroblock *)
+                           (&(part + i)->pmBootArgs);
+                       if (alt >= 0 && alt != bzb->bzbCluster)
+                               continue;
+                       setpartition(part + i, &lp->d_partitions[0], FS_BSDFFS);
+               } else if (type == UFS_PART) {
+                       bzb = (struct blockzeroblock *)
+                           (&(part + i)->pmBootArgs);
+                       if (alt >= 0 && alt != bzb->bzbCluster)
+                               continue;
+                       setpartition(part + i, &lp->d_partitions[6], FS_BSDFFS);
+                       if (*maxslot < 6)
+                               *maxslot = 6;
+               } else if (type == SWAP_PART) {
+                       setpartition(part + i, &lp->d_partitions[1], FS_SWAP);
+                       if (*maxslot < 1)
+                               *maxslot = 1;
+               } else
+                       printf("disksubr.c: can't do type %d\n", type);
+
+               return 0;
+       }
+
+       return -1;
+}
 
 /*
- * Little endian access routines
+ * MF --
+ * here's what i'm gonna do:
+ * read in the entire diskpartition table, it may be bigger or smaller
+ * than NUM_PARTS but read that many entries.  Each entry has a magic
+ * number so we'll know if an entry is crap.
+ * next fill in the disklabel with info like this
+ * next fill in the root, usr, and swap parts.
+ * then look for anything else and fit it in.
+ *     A: root
+ *     B: Swap
+ *     C: Whole disk
+ *     G: Usr
+ *
+ *
+ * I'm not entirely sure what netbsd386 wants in c & d
+ * 386bsd wants other stuff, so i'll leave them alone
+ *
+ * AKB -- I added to Mike's original algorithm by searching for a bzbCluster
+ *     of zero for root, first.  This allows A/UX to live on cluster 1 and
+ *     NetBSD to live on cluster 0--regardless of the actual order on the
+ *     disk.  This whole algorithm should probably be changed in the future.
  */
-static inline unsigned short
-get_short(p)
-       void *p;
+static char *
+read_mac_label(dev, strat, lp, osdep)
+       dev_t dev;
+       void (*strat)(struct buf *);
+       struct disklabel *lp;
+       struct cpu_disklabel *osdep;
 {



Home | Main Index | Thread Index | Old Index