Source-Changes-HG archive

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

[src/trunk]: src Commit changes proposed on tech-kern Thu, 6 Nov 2003



details:   https://anonhg.NetBSD.org/src/rev/38c2005abb73
branches:  trunk
changeset: 555361:38c2005abb73
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Sat Nov 15 17:52:30 2003 +0000

description:
Commit changes proposed on tech-kern Thu, 6 Nov 2003
- factor out disksubr.c between sun3, sparc and sparc64. Keep the sun3
  groveling code to find a NetBSD disklabel in the first sector (so that it
  can find a label at the old sun3 LABELOFFSET) as a fallback is not
  label at LABELOFFSET, or sun label is present.
- Fix the sun3 LABELOFFSET (was 64, but the kernel wrote the NetBSD label at
  128)
- Make next68k disksubr.c always write a next-compatible disklabel.
- remove #ifdef __sparc__ hack from disklabel(8), and change it to issue
  a DIOCWDINFO after writing the disklabel to the raw partition in the
  -r/-I case (so that the kernel can convert the label if needed).

diffstat:

 sbin/disklabel/disklabel.c           |   17 +-
 sys/arch/next68k/include/disklabel.h |   16 +-
 sys/arch/next68k/next68k/disksubr.c  |  176 +++++------
 sys/arch/sparc/conf/files.sparc      |    4 +-
 sys/arch/sparc/sparc/disksubr.c      |  469 -------------------------------
 sys/arch/sparc64/conf/files.sparc64  |    4 +-
 sys/arch/sparc64/sparc64/disksubr.c  |  467 -------------------------------
 sys/arch/sun3/conf/files.sun3        |    4 +-
 sys/arch/sun3/include/disklabel.h    |    4 +-
 sys/arch/sun3/sun3/disksubr.c        |  516 -----------------------------------
 sys/dev/sun/disksubr.c               |  503 ++++++++++++++++++++++++++++++++++
 11 files changed, 620 insertions(+), 1560 deletions(-)

diffs (truncated from 2393 to 300 lines):

diff -r 62d95f9d4392 -r 38c2005abb73 sbin/disklabel/disklabel.c
--- a/sbin/disklabel/disklabel.c        Sat Nov 15 17:45:34 2003 +0000
+++ b/sbin/disklabel/disklabel.c        Sat Nov 15 17:52:30 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.121 2003/11/10 09:22:09 fvdl Exp $     */
+/*     $NetBSD: disklabel.c,v 1.122 2003/11/15 17:52:30 bouyer Exp $   */
 
 /*
  * Copyright (c) 1987, 1993
@@ -43,7 +43,7 @@
 static char sccsid[] = "@(#)disklabel.c        8.4 (Berkeley) 5/4/95";
 /* from static char sccsid[] = "@(#)disklabel.c        1.2 (Symmetric) 11/28/85"; */
 #else
-__RCSID("$NetBSD: disklabel.c,v 1.121 2003/11/10 09:22:09 fvdl Exp $");
+__RCSID("$NetBSD: disklabel.c,v 1.122 2003/11/15 17:52:30 bouyer Exp $");
 #endif
 #endif /* not lint */
 
@@ -476,12 +476,7 @@
        lp->d_checksum = 0;
        lp->d_checksum = dkcksum(lp);
 
-#ifdef __sparc__
-       /* Let the kernel deal with SunOS disklabel compatibility */
-       if (0)
-#else  /* ! __sparc__ */
        if (rflag || Iflag)
-#endif /* ! __sparc__ */
        {
 #ifdef USE_MBR
                struct partition *pp = &lp->d_partitions[2];
@@ -569,6 +564,14 @@
                writable = 0;
                if (ioctl(f, DIOCWLABEL, &writable) < 0)
                        perror("ioctl DIOCWLABEL");
+               /* 
+                * Now issue a DIOCWDINFO. This will let the kernel convert the
+                * disklabel to some machdep format if needed.
+                */
+               if (ioctl(f, DIOCWDINFO, lp) < 0) {
+                       l_perror("ioctl DIOCWDINFO");
+                       return (1);
+               }
        } else {
                if (ioctl(f, DIOCWDINFO, lp) < 0) {
                        l_perror("ioctl DIOCWDINFO");
diff -r 62d95f9d4392 -r 38c2005abb73 sys/arch/next68k/include/disklabel.h
--- a/sys/arch/next68k/include/disklabel.h      Sat Nov 15 17:45:34 2003 +0000
+++ b/sys/arch/next68k/include/disklabel.h      Sat Nov 15 17:52:30 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.h,v 1.3 2003/10/27 16:48:08 cl Exp $ */
+/*     $NetBSD: disklabel.h,v 1.4 2003/11/15 17:52:30 bouyer Exp $     */
 /*
  * Copyright (c) 1994 Rolf Grossmann
  * All rights reserved.
@@ -34,9 +34,17 @@
 
 #include <sys/bootblock.h>
 
-#define        LABELSECTOR     NEXT68K_LABEL_SECTOR    /* sector containing label */
-#define        LABELOFFSET     NEXT68K_LABEL_OFFSET    /* offset of label in sector */
-#define LABELSIZE      NEXT68K_LABEL_SIZE      /* size of label */
+#if 0 /* XXX the following doesn't work - still need to find a proper place for the NetBSD disklabel */
+/*
+ * The NetBSD disklabel is located in the last sector of the next68k label
+ * area, so that it can coexists with a next68k v3 label
+ */
+#define        LABELSECTOR     15      /* sector containing label */
+#define        LABELOFFSET     0       /* offset of label in sector */
+#else
+#define LABELSECTOR 0
+#define LABELOFFSET 0
+#endif /* 0 */
 #define        MAXPARTITIONS   8       /* number of partitions */
 #define        RAW_PART        2       /* raw partition: xx?c */
 
diff -r 62d95f9d4392 -r 38c2005abb73 sys/arch/next68k/next68k/disksubr.c
--- a/sys/arch/next68k/next68k/disksubr.c       Sat Nov 15 17:45:34 2003 +0000
+++ b/sys/arch/next68k/next68k/disksubr.c       Sat Nov 15 17:52:30 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disksubr.c,v 1.15 2003/10/27 16:48:08 cl Exp $ */
+/*     $NetBSD: disksubr.c,v 1.16 2003/11/15 17:52:30 bouyer Exp $     */
 
 /*
  * Copyright (c) 1982, 1986, 1988, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.15 2003/10/27 16:48:08 cl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.16 2003/11/15 17:52:30 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -58,7 +58,7 @@
 static char * parse_nextstep_label __P((struct next68k_disklabel *, 
                        struct disklabel *, struct cpu_disklabel *));
 static int build_nextstep_label __P((struct next68k_disklabel *, 
-                       struct disklabel *, struct cpu_disklabel *));
+                       struct disklabel *));
 
 static unsigned short
 nextstep_checksum(buf, limit)
@@ -116,7 +116,7 @@
        lp->d_rpm = ondisk->cd_rpm;
        lp->d_flags = ondisk->cd_flags;
 
-       lp->d_bbsize = LABELSIZE;
+       lp->d_bbsize = NEXT68K_LABEL_SIZE;
        lp->d_sbsize = SBLOCKSIZE;
 
        lp->d_npartitions = nbp = 0;
@@ -171,38 +171,34 @@
 }
 
 static int
-build_nextstep_label(ondisk, lp, osdep)
+build_nextstep_label(ondisk, lp)
        struct next68k_disklabel *ondisk;
        struct disklabel *lp;
-       struct cpu_disklabel *osdep;
 {
        int i, t, nbp;
        int front_porch = NEXT68K_LABEL_DEFAULTFRONTPORCH;
        unsigned short *checksum;
 
-       if (osdep->od_version == 0) {
-               osdep->od_version = NEXT68K_LABEL_CD_V3;
 
-               memset (ondisk, 0, sizeof (ondisk));
+       memset (ondisk, 0, sizeof (ondisk));
 
-               /* ondisk->cd_label_blkno = 0; */
-               /* ondisk->cd_size = 0; */
-               /* ondisk->cd_tag = 0; */
-               strncpy (ondisk->cd_type, "fixed_rw_scsi", sizeof (ondisk->cd_type));
-               ondisk->cd_secsize = lp->d_secsize;
-               /* ondisk->cd_back = 0; */
-               /* ondisk->cd_ngroups = 0; */
-               /* ondisk->cd_ag_size = 0; */
-               /* ondisk->cd_ag_alts = 0; */
-               /* ondisk->cd_ag_off = 0; */
-               /* ondisk->kernel */
-               /* ondisk->hostname */
-               /* ondisk->rootpartition */
-               /* ondisk->rwpartition */
-       }
+       ondisk->cd_version = NEXT68K_LABEL_CD_V3;
+       /* ondisk->cd_label_blkno = 0; */
+       /* ondisk->cd_size = 0; */
+       /* ondisk->cd_tag = 0; */
+       strncpy (ondisk->cd_type, "fixed_rw_scsi", sizeof (ondisk->cd_type));
+       ondisk->cd_secsize = lp->d_secsize;
+       /* ondisk->cd_back = 0; */
+       /* ondisk->cd_ngroups = 0; */
+       /* ondisk->cd_ag_size = 0; */
+       /* ondisk->cd_ag_alts = 0; */
+       /* ondisk->cd_ag_off = 0; */
+       /* ondisk->kernel */
+       /* ondisk->hostname */
+       /* ondisk->rootpartition */
+       /* ondisk->rwpartition */
        KASSERT(ondisk->cd_secsize >= lp->d_secsize);
 
-       ondisk->cd_version = osdep->od_version;
        if (memcmp (ondisk->cd_name, lp->d_typename,
                     min (sizeof (lp->d_typename), sizeof (ondisk->cd_name))) &&
            sizeof (ondisk->cd_name) > sizeof (lp->d_typename))
@@ -348,35 +344,57 @@
                lp->d_partitions[i].p_size = 0x1fffffff;
        lp->d_partitions[i].p_offset = 0;
 
-       bp = geteblk(LABELSIZE);
+       bp = geteblk(NEXT68K_LABEL_SIZE);
        bp->b_dev = dev;
-       bp->b_blkno = LABELSECTOR;
-       bp->b_bcount = LABELSIZE;
+       bp->b_blkno = NEXT68K_LABEL_SECTOR;
+       bp->b_bcount = NEXT68K_LABEL_SIZE;
        bp->b_flags |= B_READ;
-       bp->b_cylinder = LABELSECTOR / lp->d_secpercyl;
+       bp->b_cylinder = NEXT68K_LABEL_SECTOR / lp->d_secpercyl;
        (*strat)(bp);
        
        if (osdep)
                osdep->od_version = 0;
 
-       if (biowait(bp))
-               msg = "I/O error";
-       else if (IS_DISKLABEL ((struct next68k_disklabel *)bp->b_data))
+       if (biowait(bp)) {
+               brelse(bp);
+               return("I/O error");
+       }
+       dlp = (struct disklabel *)
+           ((char *)bp->b_data + LABELSECTOR * lp->d_secsize + LABELOFFSET);
+       if (dlp->d_magic == DISKMAGIC || dlp->d_magic2 == DISKMAGIC) {
+               /* got a NetBSD disklabel */
+               if (osdep)
+                       osdep->od_version = DISKMAGIC;
+               if (dlp->d_npartitions > MAXPARTITIONS ||
+                          dkcksum(dlp) != 0)
+                       msg = "disk label corrupted";
+               else {
+                       *lp = *dlp;
+                       msg = NULL;
+               }
+               brelse(bp);
+               return msg;
+       }
+       if (IS_DISKLABEL ((struct next68k_disklabel *)bp->b_data)) {
+               /* got a NeXT disklabel */
                msg = parse_nextstep_label
                        ((struct next68k_disklabel *)bp->b_data, lp, osdep);
-       else {
-               if (osdep &&
-                   ((struct disklabel *)bp->b_data)->d_magic == DISKMAGIC)
-                       osdep->od_version = DISKMAGIC;
-               for (dlp = (struct disklabel *)bp->b_data;
-                    dlp <= (struct disklabel *)((char *)bp->b_data +
-                                                DEV_BSIZE - sizeof(*dlp));
-                    dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
-                       if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
-                               if (msg == NULL)
-                                       msg = "no disk label";
-                       } else if (dlp->d_npartitions > MAXPARTITIONS ||
-                                  dkcksum(dlp) != 0)
+               brelse(bp);
+               return msg;
+       }
+       /*
+        * no disklabel at the usual places. Try to locate a NetBSD disklabel
+        * in the first sector. This ensure compatibility with others
+        * big-endian systems, and with next68k when LABELSECTOR was 0.
+        */
+       msg = "no disk label";
+       for (dlp = (struct disklabel *)bp->b_data;
+            dlp <= (struct disklabel *)((char *)bp->b_data +
+                                        DEV_BSIZE - sizeof(*dlp));
+            dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
+               if (dlp->d_magic == DISKMAGIC || dlp->d_magic2 == DISKMAGIC) {
+                       if (dlp->d_npartitions > MAXPARTITIONS ||
+                          dkcksum(dlp) != 0)
                                msg = "disk label corrupted";
                        else {
                                *lp = *dlp;
@@ -443,7 +461,9 @@
        struct cpu_disklabel *osdep;
 {
        struct buf *bp;
+#if 0
        struct disklabel *dlp;
+#endif
        int labelpart;
        int error = 0;
 
@@ -453,50 +473,28 @@
                        return (EXDEV);                 /* not quite right */
                labelpart = 0;
        }
-       if (osdep->od_version != DISKMAGIC) {
-               bp = geteblk(LABELSIZE);
-               bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), labelpart);
-               bp->b_blkno = LABELSECTOR;
-               bp->b_bcount = LABELSIZE;
-               bp->b_flags |= B_READ;
-               bp->b_cylinder = LABELSECTOR / lp->d_secpercyl;
-               (*strat)(bp);
-               error = biowait(bp);
-               if (error)
-                       goto done;
-               error = build_nextstep_label 
-                       ((struct next68k_disklabel *)bp->b_data, lp, osdep);
-               if (error)
-                       goto done;
-               bp->b_flags &= ~(B_READ|B_DONE);
-               bp->b_flags |= B_WRITE;
-               (*strat)(bp);
-               error = biowait(bp);
-       } else {
-               bp = geteblk((int)lp->d_secsize);
-               bp->b_dev = MAKEDISKDEV(major(dev), DISKUNIT(dev), labelpart);
-               bp->b_blkno = LABELSECTOR;
-               bp->b_bcount = lp->d_secsize;
-               bp->b_flags |= B_READ;
-               (*strat)(bp);
-               if ((error = biowait(bp)))
-                       goto done;
-               for (dlp = (struct disklabel *)bp->b_data;
-                    dlp <= (struct disklabel *)
-                            ((char *)bp->b_data + lp->d_secsize - sizeof(*dlp));
-                    dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
-                       if (dlp->d_magic == DISKMAGIC && dlp->d_magic2 == DISKMAGIC &&
-                           dkcksum(dlp) == 0) {
-                               *dlp = *lp;
-                               bp->b_flags &= ~(B_READ|B_DONE);
-                               bp->b_flags |= B_WRITE;
-                               (*strat)(bp);
-                               error = biowait(bp);
-                               goto done;



Home | Main Index | Thread Index | Old Index