Module Name: src Committed By: jmcneill Date: Sun Sep 13 22:45:27 UTC 2009
Modified Files: src/sys/arch/i386/stand/boot: boot2.c src/sys/arch/i386/stand/lib: biosdisk.c libi386.h Log Message: 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 > To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/sys/arch/i386/stand/boot/boot2.c cvs rdiff -u -r1.28 -r1.29 src/sys/arch/i386/stand/lib/biosdisk.c cvs rdiff -u -r1.31 -r1.32 src/sys/arch/i386/stand/lib/libi386.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/i386/stand/boot/boot2.c diff -u src/sys/arch/i386/stand/boot/boot2.c:1.44 src/sys/arch/i386/stand/boot/boot2.c:1.45 --- src/sys/arch/i386/stand/boot/boot2.c:1.44 Sat Mar 21 15:01:56 2009 +++ src/sys/arch/i386/stand/boot/boot2.c Sun Sep 13 22:45:27 2009 @@ -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; } Index: src/sys/arch/i386/stand/lib/biosdisk.c diff -u src/sys/arch/i386/stand/lib/biosdisk.c:1.28 src/sys/arch/i386/stand/lib/biosdisk.c:1.29 --- src/sys/arch/i386/stand/lib/biosdisk.c:1.28 Sat Jan 5 15:28:43 2008 +++ src/sys/arch/i386/stand/lib/biosdisk.c Sun Sep 13 22:45:27 2009 @@ -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. */ Index: src/sys/arch/i386/stand/lib/libi386.h diff -u src/sys/arch/i386/stand/lib/libi386.h:1.31 src/sys/arch/i386/stand/lib/libi386.h:1.32 --- src/sys/arch/i386/stand/lib/libi386.h:1.31 Sat Mar 21 15:01:56 2009 +++ src/sys/arch/i386/stand/lib/libi386.h Sun Sep 13 22:45:27 2009 @@ -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);