Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm/arm - make errors positive like elsewhere in th...



details:   https://anonhg.NetBSD.org/src/rev/a5d9c3a90808
branches:  trunk
changeset: 785339:a5d9c3a90808
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Mar 09 16:02:25 2013 +0000

description:
- make errors positive like elsewhere in the kernel, document error returns
- KNF
- fix commented out debugging

diffstat:

 sys/arch/arm/arm/disksubr.c       |  29 +++++++++++---------
 sys/arch/arm/arm/disksubr_acorn.c |  54 +++++++++++++++++++++++++-------------
 sys/arch/arm/arm/disksubr_mbr.c   |  44 +++++++++++++++++--------------
 3 files changed, 75 insertions(+), 52 deletions(-)

diffs (truncated from 328 to 300 lines):

diff -r 695e58342bee -r a5d9c3a90808 sys/arch/arm/arm/disksubr.c
--- a/sys/arch/arm/arm/disksubr.c       Sat Mar 09 14:12:08 2013 +0000
+++ b/sys/arch/arm/arm/disksubr.c       Sat Mar 09 16:02:25 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disksubr.c,v 1.23 2009/03/15 22:23:16 cegger Exp $     */
+/*     $NetBSD: disksubr.c,v 1.24 2013/03/09 16:02:25 christos Exp $   */
 
 /*
  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.23 2009/03/15 22:23:16 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disksubr.c,v 1.24 2013/03/09 16:02:25 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -195,7 +195,8 @@
                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 *)bp->b_data + lp->d_secsize
+               - sizeof(*dlp));
            dlp = (struct disklabel *)((char *)dlp + sizeof(long))) {
                if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) {
                        continue;
@@ -262,7 +263,8 @@
  */
 
 int
-setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask, struct cpu_disklabel *osdep)
+setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask,
+    struct cpu_disklabel *osdep)
 {
        int i;
        struct partition *opp, *npp;
@@ -284,7 +286,7 @@
            || dkcksum(nlp) != 0)
                return (EINVAL);
 
-       /* XXX missing check if other acorn/dos partitions will be overwritten */
+       /* XXX add check if other acorn/dos partitions will be overwritten */
 
        while (openmask != 0) {
                i = ffs(openmask) - 1;
@@ -339,13 +341,11 @@
 
        if (osdep) {
                if ((rv = filecore_label_locate(dev, strat,lp, osdep, &cyl,
-                     &netbsdpartoff)) != 0||
+                     &netbsdpartoff)) != 0 ||
                    (rv = mbr_label_locate(dev, strat, lp, osdep, &cyl,
                      &netbsdpartoff)) != 0) {
-                       if (rv < 0) {
-                           error = -rv;
+                       if (rv > 0)
                            goto done;
-                       }
                } else {
                        /*
                         * We didn't find anything we like; NetBSD native.
@@ -356,10 +356,12 @@
                } 
        }
 
-/* writelabel: */
+       /* writelabel: */
 
-/*     printf("writedisklabel: Reading disklabel addr=%08x\n",
-            netbsdpartoff * DEV_BSIZE);*/
+#ifdef DEBUG_LABEL
+       printf("%s: Reading disklabel addr=%08x\n", __func__,
+            netbsdpartoff * DEV_BSIZE);
+#endif
 
        /* next, dig out disk label */
 
@@ -375,7 +377,8 @@
        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 *)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) {
diff -r 695e58342bee -r a5d9c3a90808 sys/arch/arm/arm/disksubr_acorn.c
--- a/sys/arch/arm/arm/disksubr_acorn.c Sat Mar 09 14:12:08 2013 +0000
+++ b/sys/arch/arm/arm/disksubr_acorn.c Sat Mar 09 16:02:25 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disksubr_acorn.c,v 1.11 2013/03/09 10:10:45 mlelstv Exp $      */
+/*     $NetBSD: disksubr_acorn.c,v 1.12 2013/03/09 16:02:25 christos Exp $     */
 
 /*
  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
@@ -97,7 +97,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr_acorn.c,v 1.11 2013/03/09 10:10:45 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disksubr_acorn.c,v 1.12 2013/03/09 16:02:25 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -237,7 +237,10 @@
        /* Do we have a NETBSD partition table ? */
 
        if (bb->partition_type == PARTITION_FORMAT_RISCBSD) {
-/*             printf("heads = %d nsectors = %d\n", heads, sectors);*/
+#ifdef DEBUG_LABEL
+               printf("%s; heads = %d nsectors = %d\n",
+                   __func__, heads, sectors);
+#endif
                netbsdpartoff = cyl * heads * sectors;
        } else if (bb->partition_type == PARTITION_FORMAT_RISCIX) {
                struct riscix_partition_table *rpt;
@@ -251,8 +254,10 @@
                 */
 
                bp->b_blkno = cyl * heads * sectors;
-/*             printf("Found RiscIX partition table @ %08x\n",
-                   bp->b_blkno);*/
+#ifdef DEBUG_LABEL
+               printf("%s: Found RiscIX partition table @ %08x\n",
+                   __func__, bp->b_blkno);
+#endif
                bp->b_cylinder = bp->b_blkno / lp->d_secpercyl;
                bp->b_bcount = lp->d_secsize;
                bp->b_oflags &= ~(BO_DONE);
@@ -270,13 +275,14 @@
                }
 
                rpt = (struct riscix_partition_table *)bp->b_data;
-/*             for (loop = 0; loop < NRISCIX_PARTITIONS; ++loop)
-                       printf("p%d: %16s %08x %08x %08x\n", loop,
-                           rpt->partitions[loop].rp_name,
+#ifdef DEBUG_LABEL
+               for (loop = 0; loop < NRISCIX_PARTITIONS; ++loop)
+                       printf("%s: p%d: %16s %08x %08x %08x\n", loop,
+                           __func__, rpt->partitions[loop].rp_name,
                            rpt->partitions[loop].rp_start,
                            rpt->partitions[loop].rp_length,
                            rpt->partitions[loop].rp_type);
-*/
+#endif
                for (loop = 0; loop < NRISCIX_PARTITIONS; ++loop) {
                        if (strcmp(rpt->partitions[loop].rp_name,
                            "RiscBSD") == 0 ||
@@ -307,6 +313,9 @@
 }
 
 
+/*
+ * Return -1 not found, 0 found positive errno
+ */
 int
 filecore_label_locate(dev_t dev,
        void (*strat)(struct buf *),
@@ -327,7 +336,9 @@
 
        /* read the filecore boot block */
 
-/*     printf("writedisklabel: Reading boot block\n");*/
+#ifdef DEBUG_LABEL
+       printf("%s: Reading boot block\n", __func__);
+#endif
 
        bp->b_blkno = FILECORE_BOOT_SECTOR;
        bp->b_bcount = lp->d_secsize;
@@ -341,12 +352,11 @@
         */
 
        if ((rv = biowait(bp)) != 0) {
-               rv = -rv;
                goto out;
        }
 
        bb = (struct filecore_bootblock *)bp->b_data;
-       rv = 1;
+       rv = 0;
 
        /* Validate boot block */
        
@@ -355,17 +365,21 @@
                 * Invalid boot block so lets assume the
                 * entire disc is NetBSD
                 */
-
-/*             printf("writedisklabel: Invalid filecore boot block (incorrect checksum)\n");*/
-               rv = 0;
+#ifdef DEBUG_LABEL
+               printf("%s: Bad filecore boot block (incorrect checksum)\n",
+                   __func__);
+#endif
+               rv = -1;
                goto out;
        }
 
        /* Do we have a NetBSD partition ? */
 
        if (bb->partition_type != PARTITION_FORMAT_RISCBSD) {
-               printf("writedisklabel: Invalid partition format\n");
-               rv = -EINVAL;
+#ifdef DEBUG_LABEL
+               printf("%s: Invalid partition format\n", __func__);
+#endif
+               rv = EINVAL;
                goto out;
        }
 
@@ -373,8 +387,10 @@
 
        heads = bb->heads;
        sectors = bb->secspertrack;
-                       
-       /*printf("heads = %d nsectors = %d\n", heads, sectors);*/
+
+#ifdef DEBUG_LABEL
+       printf("%s: heads = %d nsectors = %d\n", __func__, heads, sectors);
+#endif
 
        netbsdpartoff = cyl * heads * sectors;
 
diff -r 695e58342bee -r a5d9c3a90808 sys/arch/arm/arm/disksubr_mbr.c
--- a/sys/arch/arm/arm/disksubr_mbr.c   Sat Mar 09 14:12:08 2013 +0000
+++ b/sys/arch/arm/arm/disksubr_mbr.c   Sat Mar 09 16:02:25 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disksubr_mbr.c,v 1.15 2013/01/18 02:46:30 msaitoh Exp $        */
+/*     $NetBSD: disksubr_mbr.c,v 1.16 2013/03/09 16:02:25 christos Exp $       */
 
 /*
  * Copyright (c) 1998 Christopher G. Demetriou.  All rights reserved.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: disksubr_mbr.c,v 1.15 2013/01/18 02:46:30 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: disksubr_mbr.c,v 1.16 2013/03/09 16:02:25 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -120,7 +120,8 @@
                int nfound = 0;
 
                /* XXX "there has to be a better check than this." */
-               if (memcmp((char *)bp->b_data + MBRSIGOFS, mbrsig, sizeof(mbrsig))) {
+               if (memcmp((char *)bp->b_data + MBRSIGOFS, mbrsig,
+                   sizeof(mbrsig))) {
                        rv = 0;
                        goto out;
                }
@@ -162,22 +163,22 @@
                        pp->p_fstype = xlat_mbr_fstype(mbrp->mbrp_type);
 
                        /* is this ours? */
-                       if (mbrp == ourmbrp) {
-                               /* need sector address for SCSI/IDE,
-                                cylinder for ESDI/ST506/RLL */
-                               mbrpartoff = le32toh(mbrp->mbrp_start);
-                               cyl = MBR_PCYL(mbrp->mbrp_scyl, mbrp->mbrp_ssect);
+                       if (mbrp != ourmbrp)
+                               continue;
+
+                       /* need sector address for SCSI/IDE,
+                          cylinder for ESDI/ST506/RLL */
+                       mbrpartoff = le32toh(mbrp->mbrp_start);
+                       cyl = MBR_PCYL(mbrp->mbrp_scyl, mbrp->mbrp_ssect);
 
 #ifdef __i386__ /* XXX? */
-                               /* update disklabel with details */
-                               lp->d_partitions[2].p_size =
-                                   le32toh(mbrp->mbrp_size);
-                               lp->d_partitions[2].p_offset = 
-                                   le32toh(mbrp->mbrp_start);
-                               lp->d_ntracks = mbrp->mbrp_ehd + 1;
-                               lp->d_nsectors = MBR_PSECT(mbrp->mbrp_esect);
-                               lp->d_secpercyl =
-                                   lp->d_ntracks * lp->d_nsectors;
+                       /* update disklabel with details */
+                       lp->d_partitions[2].p_size = le32toh(mbrp->mbrp_size);
+                       lp->d_partitions[2].p_offset = 
+                           le32toh(mbrp->mbrp_start);
+                       lp->d_ntracks = mbrp->mbrp_ehd + 1;
+                       lp->d_nsectors = MBR_PSECT(mbrp->mbrp_esect);
+                       lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
 #endif
                        }
                }
@@ -196,6 +197,9 @@
        return (rv);
 }
 
+/*
+ * Return -1 not found, 0 found positive errno
+ */
 int
 mbr_label_locate(dev_t dev,



Home | Main Index | Thread Index | Old Index