Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/i386/stand Make the 'dev' command print out a list ...



details:   https://anonhg.NetBSD.org/src/rev/a069ae58cd11
branches:  trunk
changeset: 747406:a069ae58cd11
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Sep 13 22:45:27 2009 +0000

description:
Make the 'dev' command print out a list of known boot devices based on
information from the BIOS in addition to the currently selected default
partition. Handy when you don't know where to boot from. Here's a demo:

  type "?" or "help" for help.
  > dev
  disk hd0 size 3815 MB
    hd0a(4.2BSD) hd0b(swap)
  disk cd0
    cd0a(unknown)
  default hd0a
  >

diffstat:

 sys/arch/i386/stand/boot/boot2.c   |   5 +-
 sys/arch/i386/stand/lib/biosdisk.c |  82 +++++++++++++++++++++++++++++++++++++-
 sys/arch/i386/stand/lib/libi386.h  |   3 +-
 3 files changed, 85 insertions(+), 5 deletions(-)

diffs (148 lines):

diff -r d4cfb1bbdbf3 -r a069ae58cd11 sys/arch/i386/stand/boot/boot2.c
--- a/sys/arch/i386/stand/boot/boot2.c  Sun Sep 13 22:16:45 2009 +0000
+++ b/sys/arch/i386/stand/boot/boot2.c  Sun Sep 13 22:45:27 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: boot2.c,v 1.44 2009/03/21 15:01:56 ad Exp $    */
+/*     $NetBSD: boot2.c,v 1.45 2009/09/13 22:45:27 jmcneill Exp $      */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -420,7 +420,8 @@
        const char *file; /* dummy */
 
        if (*arg == '\0') {
-               printf("%s%d%c:\n", default_devname, default_unit,
+               biosdisk_probe();
+               printf("default %s%d%c\n", default_devname, default_unit,
                       'a' + default_partition);
                return;
        }
diff -r d4cfb1bbdbf3 -r a069ae58cd11 sys/arch/i386/stand/lib/biosdisk.c
--- a/sys/arch/i386/stand/lib/biosdisk.c        Sun Sep 13 22:16:45 2009 +0000
+++ b/sys/arch/i386/stand/lib/biosdisk.c        Sun Sep 13 22:45:27 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: biosdisk.c,v 1.28 2008/01/05 15:28:43 dsl Exp $        */
+/*     $NetBSD: biosdisk.c,v 1.29 2009/09/13 22:45:27 jmcneill Exp $   */
 
 /*
  * Copyright (c) 1996, 1998
@@ -63,16 +63,21 @@
  * the rights to redistribute these changes.
  */
 
+#ifndef NO_DISKLABEL
+#define FSTYPENAMES
+#endif
+
 #include <sys/types.h>
-#include <sys/disklabel.h>
 #include <sys/md5.h>
 #include <sys/param.h>
+#include <sys/disklabel.h>
 
 #include <fs/cd9660/iso.h>
 
 #include <lib/libsa/stand.h>
 #include <lib/libsa/saerrno.h>
 #include <machine/stdarg.h>
+#include <machine/cpu.h>
 
 #include "libi386.h"
 #include "biosdisk_ll.h"
@@ -292,6 +297,79 @@
 }
 #endif /* NO_DISKLABEL */
 
+void
+biosdisk_probe(void)
+{
+#ifndef NO_DISKLABEL
+       struct disklabel *lp;
+       int first, part;
+#endif
+       struct biosdisk d;
+       struct biosdisk_extinfo ed;
+       uint64_t size;
+       int i;
+
+       for (i = 0; i < MAX_BIOSDISKS + 2; i++) {
+               first = 1;
+               memset(&d, 0, sizeof(d));
+               memset(&ed, 0, sizeof(ed));
+               if (i >= MAX_BIOSDISKS)
+                       d.ll.dev = 0x00 + i - MAX_BIOSDISKS;    /* fd */
+               else
+                       d.ll.dev = 0x80 + i;                    /* hd/cd */
+               if (set_geometry(&d.ll, &ed))
+                       continue;
+               switch (d.ll.type) {
+               case BIOSDISK_TYPE_CD:
+                       printf("disk cd0\n");
+                       printf("  cd0a(unknown)\n");
+                       break;
+               case BIOSDISK_TYPE_FD:
+                       printf("disk fd%d\n", d.ll.dev & 0x7f);
+                       printf("  fd%da(unknown)\n", d.ll.dev & 0x7f);
+                       break;
+               case BIOSDISK_TYPE_HD:
+                       printf("disk hd%d", d.ll.dev & 0x7f);
+                       if (d.ll.flags & BIOSDISK_INT13EXT) {
+                               printf(" size ");
+                               size = ed.totsec * ed.sbytes;
+                               if (size >= (10ULL * 1024 * 1024 * 1024))
+                                       printf("%llu GB",
+                                           size / (1024 * 1024 * 1024));
+                               else
+                                       printf("%llu MB",
+                                           size / (1024 * 1024));
+                       }
+                       printf("\n");
+                       break;
+               }
+#ifndef NO_DISKLABEL
+               if (read_label(&d) == -1)
+                       break;
+               lp = (struct disklabel *)(d.buf + LABELOFFSET);
+               for (part = 0; part < lp->d_npartitions; part++) {
+                       if (lp->d_partitions[part].p_size == 0)
+                               continue;
+                       if (lp->d_partitions[part].p_fstype == FS_UNUSED)
+                               continue;
+                       if (first) {
+                               printf(" ");
+                               first = 0;
+                       }
+                       printf(" hd%d%c(", d.ll.dev & 0x7f, part + 'a');
+                       if (lp->d_partitions[part].p_fstype < FSMAXTYPES)
+                               printf("%s",
+                                 fstypenames[lp->d_partitions[part].p_fstype]);
+                       else
+                               printf("%d", lp->d_partitions[part].p_fstype);
+                       printf(")");
+               }
+               if (first == 0)
+                       printf("\n");
+#endif
+       }
+}
+
 /* Determine likely partition for possible sector number of dos
  * partition.
  */
diff -r d4cfb1bbdbf3 -r a069ae58cd11 sys/arch/i386/stand/lib/libi386.h
--- a/sys/arch/i386/stand/lib/libi386.h Sun Sep 13 22:16:45 2009 +0000
+++ b/sys/arch/i386/stand/lib/libi386.h Sun Sep 13 22:45:27 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: libi386.h,v 1.31 2009/03/21 15:01:56 ad Exp $  */
+/*     $NetBSD: libi386.h,v 1.32 2009/09/13 22:45:27 jmcneill Exp $    */
 
 /*
  * Copyright (c) 1996
@@ -122,6 +122,7 @@
 struct biosdisk_extinfo;
 void biosdisk_getextinfo(int, struct biosdisk_extinfo *);
 int get_harddrives(void);
+void biosdisk_probe(void);
 
 int pcibios_cfgread(unsigned int, int, int *);
 int pcibios_cfgwrite(unsigned int, int, int);



Home | Main Index | Thread Index | Old Index