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
  >
This commit is contained in:
jmcneill 2009-09-13 22:45:27 +00:00
parent 86dbe4a721
commit 891bf245b9
3 changed files with 85 additions and 5 deletions

View File

@ -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;
}

View File

@ -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 @@ 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.
*/

View File

@ -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);