Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86/x86 Use deviter(9) instead of accessing alldevs...



details:   https://anonhg.NetBSD.org/src/rev/9d2e4bbb11d3
branches:  trunk
changeset: 748850:9d2e4bbb11d3
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Fri Nov 06 23:10:22 2009 +0000

description:
Use deviter(9) instead of accessing alldevs directly.

diffstat:

 sys/arch/x86/x86/x86_autoconf.c |  38 +++++++++++++++++++++++++++++---------
 1 files changed, 29 insertions(+), 9 deletions(-)

diffs (148 lines):

diff -r 81a5fecfc5fc -r 9d2e4bbb11d3 sys/arch/x86/x86/x86_autoconf.c
--- a/sys/arch/x86/x86/x86_autoconf.c   Fri Nov 06 23:10:10 2009 +0000
+++ b/sys/arch/x86/x86/x86_autoconf.c   Fri Nov 06 23:10:22 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: x86_autoconf.c,v 1.45 2009/09/21 13:23:43 macallan Exp $       */
+/*     $NetBSD: x86_autoconf.c,v 1.46 2009/11/06 23:10:22 dyoung Exp $ */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.45 2009/09/21 13:23:43 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: x86_autoconf.c,v 1.46 2009/11/06 23:10:22 dyoung Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -152,6 +152,7 @@
        struct btinfo_biosgeom *big;
        struct bi_biosgeom_entry *be;
        device_t dv;
+       deviter_t di;
        int i, ck, error, m, n;
        struct vnode *tv;
        char mbr[DEV_BSIZE];
@@ -163,10 +164,12 @@
        numbig = big ? big->num : 0;
 
        /* First, count all native disks. */
-       TAILQ_FOREACH(dv, &alldevs, dv_list) {
+       for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); dv != NULL;
+            dv = deviter_next(&di)) {
                if (is_valid_disk(dv))
                        x86_ndisks++;
        }
+       deviter_release(&di);
 
        dklist_size = sizeof(struct disklist) + (x86_ndisks - 1) *
            sizeof(struct nativedisk_info);
@@ -196,7 +199,8 @@
 
        /* XXX Code duplication from findroot(). */
        n = -1;
-       TAILQ_FOREACH(dv, &alldevs, dv_list) {
+       for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); dv != NULL;
+            dv = deviter_next(&di)) {
                if (device_class(dv) != DV_DISK)
                        continue;
 #ifdef GEOM_DEBUG
@@ -251,6 +255,7 @@
                        vput(tv);
                }
        }
+       deviter_release(&di);
 }
 
 /*
@@ -364,6 +369,7 @@
        struct btinfo_bootwedge *biw;
        struct btinfo_biosgeom *big;
        device_t dv;
+       deviter_t di;
 
        if (booted_device)
                return;
@@ -380,7 +386,9 @@
        }
 
        if ((biv = lookup_bootinfo(BTINFO_ROOTDEVICE)) != NULL) {
-               TAILQ_FOREACH(dv, &alldevs, dv_list) {
+               for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
+                    dv != NULL;
+                    dv = deviter_next(&di)) {
                        cfdata_t cd;
                        size_t len;
 
@@ -393,9 +401,12 @@
                        if (strncmp(cd->cf_name, biv->devname, len) == 0 &&
                            biv->devname[len] - '0' == cd->cf_unit) {
                                handle_wedges(dv, biv->devname[len + 1] - 'a');
-                               return;
+                               break;
                        }
                }
+               deviter_release(&di);
+               if (dv != NULL)
+                       return;
        }
 
        if ((biw = lookup_bootinfo(BTINFO_BOOTWEDGE)) != NULL) {
@@ -406,7 +417,9 @@
                 * because lower devices numbers are more likely to be the
                 * boot device.
                 */
-               TAILQ_FOREACH(dv, &alldevs, dv_list) {
+               for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
+                    dv != NULL;
+                    dv = deviter_next(&di)) {
                        if (device_class(dv) != DV_DISK)
                                continue;
 
@@ -433,6 +446,7 @@
                        }
                        dkwedge_set_bootwedge(dv, biw->startblk, biw->nblks);
                }
+               deviter_release(&di);
 
                if (booted_wedge)
                        return;
@@ -446,7 +460,9 @@
                 * because lower device numbers are more likely to be the
                 * boot device.
                 */
-               TAILQ_FOREACH(dv, &alldevs, dv_list) {
+               for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
+                    dv != NULL;
+                    dv = deviter_next(&di)) {
                        if (device_class(dv) != DV_DISK)
                                continue;
 
@@ -487,6 +503,7 @@
                        }
                        handle_wedges(dv, bid->partition);
                }
+               deviter_release(&di);
 
                if (booted_device)
                        return;
@@ -509,7 +526,9 @@
                         * recognized as a bootable CD-ROM drive by the BIOS.
                         * Assume the first unit is the one.
                         */
-                       TAILQ_FOREACH(dv, &alldevs, dv_list) {
+                       for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
+                            dv != NULL;
+                            dv = deviter_next(&di)) {
                                if (device_class(dv) == DV_DISK &&
                                    device_is_a(dv, "cd")) {
                                        booted_device = dv;
@@ -517,6 +536,7 @@
                                        break;
                                }
                        }
+                       deviter_release(&di);
                }
        }
 }



Home | Main Index | Thread Index | Old Index