From 891bf245b95df30f82f1fbd8b44291e807e7d470 Mon Sep 17 00:00:00 2001 From: jmcneill Date: Sun, 13 Sep 2009 22:45:27 +0000 Subject: [PATCH] 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 > --- 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(-) diff --git a/sys/arch/i386/stand/boot/boot2.c b/sys/arch/i386/stand/boot/boot2.c index cd31be7b59a5..d5171a431c94 100644 --- a/sys/arch/i386/stand/boot/boot2.c +++ b/sys/arch/i386/stand/boot/boot2.c @@ -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 @@ command_dev(char *arg) 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 --git a/sys/arch/i386/stand/lib/biosdisk.c b/sys/arch/i386/stand/lib/biosdisk.c index c307833eb7c4..7570d14cbbb6 100644 --- a/sys/arch/i386/stand/lib/biosdisk.c +++ b/sys/arch/i386/stand/lib/biosdisk.c @@ -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 -#include #include #include +#include #include #include #include #include +#include #include "libi386.h" #include "biosdisk_ll.h" @@ -292,6 +297,79 @@ read_label(struct biosdisk *d) } #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 --git a/sys/arch/i386/stand/lib/libi386.h b/sys/arch/i386/stand/lib/libi386.h index b3ecbafa0343..ecb5796184e0 100644 --- a/sys/arch/i386/stand/lib/libi386.h +++ b/sys/arch/i386/stand/lib/libi386.h @@ -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 @@ int biosdisk_getinfo(int); 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);