summaryrefslogtreecommitdiffstats
path: root/sys/boot/i386
diff options
context:
space:
mode:
authorae <ae@FreeBSD.org>2012-08-05 14:37:48 +0000
committerae <ae@FreeBSD.org>2012-08-05 14:37:48 +0000
commit1a92e54c097925600a6073cc61038ce2e97c13d2 (patch)
treed6e7608b80cf635a7876088027a6b2c51f4dd6b3 /sys/boot/i386
parentcac2fe116fb1431e5d9f22d2c536ee13c925eaa8 (diff)
downloadFreeBSD-src-1a92e54c097925600a6073cc61038ce2e97c13d2.zip
FreeBSD-src-1a92e54c097925600a6073cc61038ce2e97c13d2.tar.gz
Add offset field to the i386_devdesc structure to be compatible with
disk_devdesc structure. Update biosdisk driver to the new disk API.
Diffstat (limited to 'sys/boot/i386')
-rw-r--r--sys/boot/i386/libi386/Makefile4
-rw-r--r--sys/boot/i386/libi386/biosdisk.c1223
-rw-r--r--sys/boot/i386/libi386/devicename.c85
-rw-r--r--sys/boot/i386/libi386/libi386.h1
4 files changed, 243 insertions, 1070 deletions
diff --git a/sys/boot/i386/libi386/Makefile b/sys/boot/i386/libi386/Makefile
index c968746..20ed02c 100644
--- a/sys/boot/i386/libi386/Makefile
+++ b/sys/boot/i386/libi386/Makefile
@@ -39,10 +39,6 @@ CFLAGS+= -DSMBIOS_LITTLE_ENDIAN_UUID
.endif
.endif
-.if !defined(LOADER_NO_GPT_SUPPORT)
-CFLAGS+= -DLOADER_GPT_SUPPORT
-.endif
-
# Include simple terminal emulation (cons25-compatible)
CFLAGS+= -DTERM_EMU
diff --git a/sys/boot/i386/libi386/biosdisk.c b/sys/boot/i386/libi386/biosdisk.c
index 23bbef7..c821c17 100644
--- a/sys/boot/i386/libi386/biosdisk.c
+++ b/sys/boot/i386/libi386/biosdisk.c
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
+ * Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -37,21 +38,19 @@ __FBSDID("$FreeBSD$");
*
*/
+#include <sys/disk.h>
#include <stand.h>
-
-#include <sys/disklabel.h>
-#include <sys/diskmbr.h>
-#include <sys/gpt.h>
#include <machine/bootinfo.h>
-
#include <stdarg.h>
-#include <uuid.h>
#include <bootstrap.h>
#include <btxv86.h>
#include <edd.h>
+#include "disk.h"
#include "libi386.h"
+CTASSERT(sizeof(struct i386_devdesc) >= sizeof(struct disk_devdesc));
+
#define BIOS_NUMDRIVES 0x475
#define BIOSDISK_SECSIZE 512
#define BUFSIZE (1 * BIOSDISK_SECSIZE)
@@ -68,174 +67,118 @@ __FBSDID("$FreeBSD$");
# define DEBUG(fmt, args...)
#endif
-#ifdef LOADER_GPT_SUPPORT
-struct gpt_part {
- int gp_index;
- uuid_t gp_type;
- uint64_t gp_start;
- uint64_t gp_end;
-};
-#endif
-
-struct open_disk {
- int od_dkunit; /* disk unit number */
- int od_unit; /* BIOS unit number */
- int od_cyl; /* BIOS geometry */
- int od_hds;
- int od_sec;
- daddr_t od_boff; /* block offset from beginning of BIOS disk */
- int od_flags;
-#define BD_MODEINT13 0x0000
-#define BD_MODEEDD1 0x0001
-#define BD_MODEEDD3 0x0002
-#define BD_MODEMASK 0x0003
-#define BD_FLOPPY 0x0004
-#define BD_LABELOK 0x0008
-#define BD_PARTTABOK 0x0010
-#ifdef LOADER_GPT_SUPPORT
-#define BD_GPTOK 0x0020
-#endif
- union {
- struct {
- struct disklabel mbr_disklabel;
- int mbr_nslices; /* slice count */
- struct dos_partition mbr_slicetab[NEXTDOSPART];
- } _mbr;
-#ifdef LOADER_GPT_SUPPORT
- struct {
- int gpt_nparts;
- struct gpt_part *gpt_partitions;
- } _gpt;
-#endif
- } _data;
-};
-
-#define od_disklabel _data._mbr.mbr_disklabel
-#define od_nslices _data._mbr.mbr_nslices
-#define od_slicetab _data._mbr.mbr_slicetab
-#ifdef LOADER_GPT_SUPPORT
-#define od_nparts _data._gpt.gpt_nparts
-#define od_partitions _data._gpt.gpt_partitions
-#endif
-
/*
* List of BIOS devices, translation from disk unit number to
* BIOS unit number.
*/
static struct bdinfo
{
- int bd_unit; /* BIOS unit number */
- int bd_flags;
- int bd_type; /* BIOS 'drive type' (floppy only) */
+ int bd_unit; /* BIOS unit number */
+ int bd_cyl; /* BIOS geometry */
+ int bd_hds;
+ int bd_sec;
+ int bd_flags;
+#define BD_MODEINT13 0x0000
+#define BD_MODEEDD1 0x0001
+#define BD_MODEEDD3 0x0002
+#define BD_MODEMASK 0x0003
+#define BD_FLOPPY 0x0004
+ int bd_type; /* BIOS 'drive type' (floppy only) */
+ uint16_t bd_sectorsize; /* Sector size */
+ uint64_t bd_sectors; /* Disk size */
} bdinfo [MAXBDDEV];
static int nbdinfo = 0;
-static int bd_getgeom(struct open_disk *od);
-static int bd_read(struct open_disk *od, daddr_t dblk, int blks,
- caddr_t dest);
-static int bd_write(struct open_disk *od, daddr_t dblk, int blks,
- caddr_t dest);
+#define BD(dev) (bdinfo[(dev)->d_unit])
-static int bd_int13probe(struct bdinfo *bd);
+static int bd_read(struct disk_devdesc *dev, daddr_t dblk, int blks,
+ caddr_t dest);
+static int bd_write(struct disk_devdesc *dev, daddr_t dblk, int blks,
+ caddr_t dest);
+static int bd_int13probe(struct bdinfo *bd);
-#ifdef LOADER_GPT_SUPPORT
-static void bd_printgptpart(struct open_disk *od, struct gpt_part *gp,
- char *prefix, int verbose);
-#endif
-static void bd_printslice(struct open_disk *od, struct dos_partition *dp,
- char *prefix, int verbose);
-static void bd_printbsdslice(struct open_disk *od, daddr_t offset,
- char *prefix, int verbose);
-
-static int bd_init(void);
-static int bd_strategy(void *devdata, int flag, daddr_t dblk,
- size_t size, char *buf, size_t *rsize);
-static int bd_realstrategy(void *devdata, int flag, daddr_t dblk,
- size_t size, char *buf, size_t *rsize);
-static int bd_open(struct open_file *f, ...);
-static int bd_close(struct open_file *f);
-static void bd_print(int verbose);
+static int bd_init(void);
+static int bd_strategy(void *devdata, int flag, daddr_t dblk, size_t size,
+ char *buf, size_t *rsize);
+static int bd_realstrategy(void *devdata, int flag, daddr_t dblk,
+ size_t size, char *buf, size_t *rsize);
+static int bd_open(struct open_file *f, ...);
+static int bd_close(struct open_file *f);
+static int bd_ioctl(struct open_file *f, u_long cmd, void *data);
+static void bd_print(int verbose);
struct devsw biosdisk = {
- "disk",
- DEVT_DISK,
- bd_init,
- bd_strategy,
- bd_open,
- bd_close,
- noioctl,
- bd_print,
- NULL
+ "disk",
+ DEVT_DISK,
+ bd_init,
+ bd_strategy,
+ bd_open,
+ bd_close,
+ bd_ioctl,
+ bd_print,
+ NULL
};
-static int bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev);
-static void bd_closedisk(struct open_disk *od);
-static int bd_open_mbr(struct open_disk *od, struct i386_devdesc *dev);
-static int bd_bestslice(struct open_disk *od);
-static void bd_checkextended(struct open_disk *od, int slicenum);
-#ifdef LOADER_GPT_SUPPORT
-static int bd_open_gpt(struct open_disk *od, struct i386_devdesc *dev);
-static struct gpt_part *bd_best_gptpart(struct open_disk *od);
-#endif
-
/*
* Translate between BIOS device numbers and our private unit numbers.
*/
int
bd_bios2unit(int biosdev)
{
- int i;
-
- DEBUG("looking for bios device 0x%x", biosdev);
- for (i = 0; i < nbdinfo; i++) {
- DEBUG("bd unit %d is BIOS device 0x%x", i, bdinfo[i].bd_unit);
- if (bdinfo[i].bd_unit == biosdev)
- return(i);
- }
- return(-1);
+ int i;
+
+ DEBUG("looking for bios device 0x%x", biosdev);
+ for (i = 0; i < nbdinfo; i++) {
+ DEBUG("bd unit %d is BIOS device 0x%x", i, bdinfo[i].bd_unit);
+ if (bdinfo[i].bd_unit == biosdev)
+ return (i);
+ }
+ return (-1);
}
int
bd_unit2bios(int unit)
{
- if ((unit >= 0) && (unit < nbdinfo))
- return(bdinfo[unit].bd_unit);
- return(-1);
+
+ if ((unit >= 0) && (unit < nbdinfo))
+ return (bdinfo[unit].bd_unit);
+ return (-1);
}
-/*
+/*
* Quiz the BIOS for disk devices, save a little info about them.
*/
static int
-bd_init(void)
+bd_init(void)
{
- int base, unit, nfd = 0;
+ int base, unit, nfd = 0;
- /* sequence 0, 0x80 */
- for (base = 0; base <= 0x80; base += 0x80) {
- for (unit = base; (nbdinfo < MAXBDDEV); unit++) {
+ /* sequence 0, 0x80 */
+ for (base = 0; base <= 0x80; base += 0x80) {
+ for (unit = base; (nbdinfo < MAXBDDEV); unit++) {
#ifndef VIRTUALBOX
- /* check the BIOS equipment list for number of fixed disks */
- if((base == 0x80) &&
- (nfd >= *(unsigned char *)PTOV(BIOS_NUMDRIVES)))
- break;
+ /*
+ * Check the BIOS equipment list for number
+ * of fixed disks.
+ */
+ if(base == 0x80 &&
+ (nfd >= *(unsigned char *)PTOV(BIOS_NUMDRIVES)))
+ break;
#endif
-
- bdinfo[nbdinfo].bd_unit = unit;
- bdinfo[nbdinfo].bd_flags = (unit < 0x80) ? BD_FLOPPY : 0;
-
- if (!bd_int13probe(&bdinfo[nbdinfo]))
- break;
-
- /* XXX we need "disk aliases" to make this simpler */
- printf("BIOS drive %c: is disk%d\n",
- (unit < 0x80) ? ('A' + unit) : ('C' + unit - 0x80), nbdinfo);
- nbdinfo++;
- if (base == 0x80)
- nfd++;
+ bdinfo[nbdinfo].bd_unit = unit;
+ bdinfo[nbdinfo].bd_flags = unit < 0x80 ? BD_FLOPPY: 0;
+ if (!bd_int13probe(&bdinfo[nbdinfo]))
+ break;
+
+ /* XXX we need "disk aliases" to make this simpler */
+ printf("BIOS drive %c: is disk%d\n", (unit < 0x80) ?
+ ('A' + unit): ('C' + unit - 0x80), nbdinfo);
+ nbdinfo++;
+ if (base == 0x80)
+ nfd++;
+ }
}
- }
- return(0);
+ return(0);
}
/*
@@ -244,36 +187,60 @@ bd_init(void)
static int
bd_int13probe(struct bdinfo *bd)
{
- v86.ctl = V86_FLAGS;
- v86.addr = 0x13;
- v86.eax = 0x800;
- v86.edx = bd->bd_unit;
- v86int();
-
- if (!(V86_CY(v86.efl)) && /* carry clear */
- ((v86.edx & 0xff) > ((unsigned)bd->bd_unit & 0x7f))) { /* unit # OK */
- if ((v86.ecx & 0x3f) == 0) { /* absurd sector size */
- DEBUG("Invalid geometry for unit %d", bd->bd_unit);
- return(0); /* skip device */
- }
- bd->bd_flags |= BD_MODEINT13;
+ struct edd_params params;
+
+ v86.ctl = V86_FLAGS;
+ v86.addr = 0x13;
+ v86.eax = 0x800;
+ v86.edx = bd->bd_unit;
+ v86int();
+
+ if (V86_CY(v86.efl) || /* carry set */
+ (v86.ecx & 0x3f) == 0 || /* absurd sector number */
+ (v86.edx & 0xff) <= (unsigned)(bd->bd_unit & 0x7f)) /* unit # bad */
+ return (0); /* skip device */
+
+ /* Convert max cyl # -> # of cylinders */
+ bd->bd_cyl = ((v86.ecx & 0xc0) << 2) + ((v86.ecx & 0xff00) >> 8) + 1;
+ /* Convert max head # -> # of heads */
+ bd->bd_hds = ((v86.edx & 0xff00) >> 8) + 1;
+ bd->bd_sec = v86.ecx & 0x3f;
bd->bd_type = v86.ebx & 0xff;
+ bd->bd_flags |= BD_MODEINT13;
+
+ /* Calculate sectors count from the geometry */
+ bd->bd_sectors = bd->bd_cyl * bd->bd_hds * bd->bd_sec;
+ bd->bd_sectorsize = BIOSDISK_SECSIZE;
+ DEBUG("unit 0x%x geometry %d/%d/%d", bd->bd_unit, bd->bd_cyl,
+ bd->bd_hds, bd->bd_sec);
/* Determine if we can use EDD with this device. */
v86.eax = 0x4100;
v86.edx = bd->bd_unit;
v86.ebx = 0x55aa;
v86int();
- if (!(V86_CY(v86.efl)) && /* carry clear */
- ((v86.ebx & 0xffff) == 0xaa55) && /* signature */
- (v86.ecx & EDD_INTERFACE_FIXED_DISK)) { /* packets mode ok */
- bd->bd_flags |= BD_MODEEDD1;
- if ((v86.eax & 0xff00) >= 0x3000)
- bd->bd_flags |= BD_MODEEDD3;
+ if (V86_CY(v86.efl) || /* carry set */
+ (v86.ebx & 0xffff) != 0xaa55 || /* signature */
+ (v86.ecx & EDD_INTERFACE_FIXED_DISK) == 0)
+ return (1);
+ /* EDD supported */
+ bd->bd_flags |= BD_MODEEDD1;
+ if ((v86.eax & 0xff00) >= 0x3000)
+ bd->bd_flags |= BD_MODEEDD3;
+ /* Get disk params */
+ params.len = sizeof(struct edd_params);
+ v86.ctl = V86_FLAGS;
+ v86.addr = 0x13;
+ v86.eax = 0x4800;
+ v86.edx = bd->bd_unit;
+ v86.ds = VTOPSEG(&params);
+ v86.esi = VTOPOFF(&params);
+ v86int();
+ if (!V86_CY(v86.efl)) {
+ bd->bd_sectors = params.sectors;
+ bd->bd_sectorsize = params.sector_size;
}
- return(1);
- }
- return(0);
+ return (1);
}
/*
@@ -282,237 +249,29 @@ bd_int13probe(struct bdinfo *bd)
static void
bd_print(int verbose)
{
- int i, j;
- char line[80];
- struct i386_devdesc dev;
- struct open_disk *od;
- struct dos_partition *dptr;
-
- for (i = 0; i < nbdinfo; i++) {
- sprintf(line, " disk%d: BIOS drive %c:\n", i,
- (bdinfo[i].bd_unit < 0x80) ? ('A' + bdinfo[i].bd_unit) : ('C' + bdinfo[i].bd_unit - 0x80));
- pager_output(line);
-
- /* try to open the whole disk */
- dev.d_unit = i;
- dev.d_kind.biosdisk.slice = -1;
- dev.d_kind.biosdisk.partition = -1;
-
- if (!bd_opendisk(&od, &dev)) {
-
-#ifdef LOADER_GPT_SUPPORT
- /* Do we have a GPT table? */
- if (od->od_flags & BD_GPTOK) {
- for (j = 0; j < od->od_nparts; j++) {
- sprintf(line, " disk%dp%d", i,
- od->od_partitions[j].gp_index);
- bd_printgptpart(od, &od->od_partitions[j], line, verbose);
+ static char line[80];
+ struct disk_devdesc dev;
+ int i;
+
+ for (i = 0; i < nbdinfo; i++) {
+ sprintf(line, " disk%d: BIOS drive %c:\n", i,
+ (bdinfo[i].bd_unit < 0x80) ? ('A' + bdinfo[i].bd_unit):
+ ('C' + bdinfo[i].bd_unit - 0x80));
+ pager_output(line);
+ dev.d_dev = &biosdisk;
+ dev.d_unit = i;
+ dev.d_slice = -1;
+ dev.d_partition = -1;
+ if (disk_open(&dev,
+ bdinfo[i].bd_sectorsize * bdinfo[i].bd_sectors,
+ bdinfo[i].bd_sectorsize) == 0) {
+ sprintf(line, " disk%d", i);
+ disk_print(&dev, line, verbose);
+ disk_close(&dev);
}
- } else
-#endif
- /* Do we have a partition table? */
- if (od->od_flags & BD_PARTTABOK) {
- dptr = &od->od_slicetab[0];
-
- /* Check for a "dedicated" disk */
- if ((dptr[3].dp_typ == DOSPTYP_386BSD) &&
- (dptr[3].dp_start == 0) &&
- (dptr[3].dp_size == 50000)) {
- sprintf(line, " disk%d", i);
- bd_printbsdslice(od, 0, line, verbose);
- } else {
- for (j = 0; j < od->od_nslices; j++) {
- sprintf(line, " disk%ds%d", i, j + 1);
- bd_printslice(od, &dptr[j], line, verbose);
- }
- }
- }
- bd_closedisk(od);
- }
- }
-}
-
-/* Given a size in 512 byte sectors, convert it to a human-readable number. */
-static char *
-display_size(uint64_t size)
-{
- static char buf[80];
- char unit;
-
- size /= 2;
- unit = 'K';
- if (size >= 10485760000LL) {
- size /= 1073741824;
- unit = 'T';
- } else if (size >= 10240000) {
- size /= 1048576;
- unit = 'G';
- } else if (size >= 10000) {
- size /= 1024;
- unit = 'M';
- }
- sprintf(buf, "%.6ld%cB", (long)size, unit);
- return (buf);
-}
-
-#ifdef LOADER_GPT_SUPPORT
-static uuid_t efi = GPT_ENT_TYPE_EFI;
-static uuid_t freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT;
-static uuid_t freebsd_ufs = GPT_ENT_TYPE_FREEBSD_UFS;
-static uuid_t freebsd_swap = GPT_ENT_TYPE_FREEBSD_SWAP;
-static uuid_t freebsd_zfs = GPT_ENT_TYPE_FREEBSD_ZFS;
-static uuid_t ms_basic_data = GPT_ENT_TYPE_MS_BASIC_DATA;
-
-static void
-bd_printgptpart(struct open_disk *od, struct gpt_part *gp, char *prefix,
- int verbose)
-{
- char stats[80];
- char line[96];
-
- if (verbose)
- sprintf(stats, " %s", display_size(gp->gp_end + 1 - gp->gp_start));
- else
- stats[0] = '\0';
-
- if (uuid_equal(&gp->gp_type, &efi, NULL))
- sprintf(line, "%s: EFI %s\n", prefix, stats);
- else if (uuid_equal(&gp->gp_type, &ms_basic_data, NULL))
- sprintf(line, "%s: FAT/NTFS %s\n", prefix, stats);
- else if (uuid_equal(&gp->gp_type, &freebsd_boot, NULL))
- sprintf(line, "%s: FreeBSD boot%s\n", prefix, stats);
- else if (uuid_equal(&gp->gp_type, &freebsd_ufs, NULL))
- sprintf(line, "%s: FreeBSD UFS %s\n", prefix, stats);
- else if (uuid_equal(&gp->gp_type, &freebsd_zfs, NULL))
- sprintf(line, "%s: FreeBSD ZFS %s\n", prefix, stats);
- else if (uuid_equal(&gp->gp_type, &freebsd_swap, NULL))
- sprintf(line, "%s: FreeBSD swap%s\n", prefix, stats);
- else
- sprintf(line, "%s: %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x%s\n",
- prefix,
- gp->gp_type.time_low, gp->gp_type.time_mid,
- gp->gp_type.time_hi_and_version,
- gp->gp_type.clock_seq_hi_and_reserved, gp->gp_type.clock_seq_low,
- gp->gp_type.node[0], gp->gp_type.node[1], gp->gp_type.node[2],
- gp->gp_type.node[3], gp->gp_type.node[4], gp->gp_type.node[5],
- stats);
- pager_output(line);
-}
-#endif
-
-/*
- * Print information about slices on a disk. For the size calculations we
- * assume a 512 byte sector.
- */
-static void
-bd_printslice(struct open_disk *od, struct dos_partition *dp, char *prefix,
- int verbose)
-{
- char stats[80];
- char line[80];
-
- if (verbose)
- sprintf(stats, " %s (%d - %d)", display_size(dp->dp_size),
- dp->dp_start, dp->dp_start + dp->dp_size);
- else
- stats[0] = '\0';
-
- switch (dp->dp_typ) {
- case DOSPTYP_386BSD:
- bd_printbsdslice(od, (daddr_t)dp->dp_start, prefix, verbose);
- return;
- case DOSPTYP_LINSWP:
- sprintf(line, "%s: Linux swap%s\n", prefix, stats);
- break;
- case DOSPTYP_LINUX:
- /*
- * XXX
- * read the superblock to confirm this is an ext2fs partition?
- */
- sprintf(line, "%s: ext2fs%s\n", prefix, stats);
- break;
- case 0x00: /* unused partition */
- case DOSPTYP_EXT:
- return;
- case 0x01:
- sprintf(line, "%s: FAT-12%s\n", prefix, stats);
- break;
- case 0x04:
- case 0x06:
- case 0x0e:
- sprintf(line, "%s: FAT-16%s\n", prefix, stats);
- break;
- case 0x07:
- sprintf(line, "%s: NTFS/HPFS%s\n", prefix, stats);
- break;
- case 0x0b:
- case 0x0c:
- sprintf(line, "%s: FAT-32%s\n", prefix, stats);
- break;
- default:
- sprintf(line, "%s: Unknown fs: 0x%x %s\n", prefix, dp->dp_typ,
- stats);
- }
- pager_output(line);
-}
-
-/*
- * Print out each valid partition in the disklabel of a FreeBSD slice.
- * For size calculations, we assume a 512 byte sector size.
- */
-static void
-bd_printbsdslice(struct open_disk *od, daddr_t offset, char *prefix,
- int verbose)
-{
- char line[80];
- char buf[BIOSDISK_SECSIZE];
- struct disklabel *lp;
- int i;
-
- /* read disklabel */
- if (bd_read(od, offset + LABELSECTOR, 1, buf))
- return;
- lp =(struct disklabel *)(&buf[0]);
- if (lp->d_magic != DISKMAGIC) {
- sprintf(line, "%s: FFS bad disklabel\n", prefix);
- pager_output(line);
- return;
- }
-
- /* Print partitions */
- for (i = 0; i < lp->d_npartitions; i++) {
- /*
- * For each partition, make sure we know what type of fs it is. If
- * not, then skip it. However, since floppies often have bogus
- * fstypes, print the 'a' partition on a floppy even if it is marked
- * unused.
- */
- if ((lp->d_partitions[i].p_fstype == FS_BSDFFS) ||
- (lp->d_partitions[i].p_fstype == FS_SWAP) ||
- (lp->d_partitions[i].p_fstype == FS_VINUM) ||
- ((lp->d_partitions[i].p_fstype == FS_UNUSED) &&
- (od->od_flags & BD_FLOPPY) && (i == 0))) {
-
- /* Only print out statistics in verbose mode */
- if (verbose)
- sprintf(line, " %s%c: %s %s (%d - %d)\n", prefix, 'a' + i,
- (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap " :
- (lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" :
- "FFS ",
- display_size(lp->d_partitions[i].p_size),
- lp->d_partitions[i].p_offset,
- lp->d_partitions[i].p_offset + lp->d_partitions[i].p_size);
- else
- sprintf(line, " %s%c: %s\n", prefix, 'a' + i,
- (lp->d_partitions[i].p_fstype == FS_SWAP) ? "swap" :
- (lp->d_partitions[i].p_fstype == FS_VINUM) ? "vinum" :
- "FFS");
- pager_output(line);
}
- }
}
-
/*
* Attempt to open the disk described by (dev) for use by (f).
*
@@ -523,564 +282,83 @@ bd_printbsdslice(struct open_disk *od, daddr_t offset, char *prefix,
* sliced - are they after the first BSD slice, or the DOS
* slice before it?)
*/
-static int
-bd_open(struct open_file *f, ...)
-{
- va_list ap;
- struct i386_devdesc *dev;
- struct open_disk *od;
- int error;
-
- va_start(ap, f);
- dev = va_arg(ap, struct i386_devdesc *);
- va_end(ap);
- if ((error = bd_opendisk(&od, dev)))
- return(error);
-
- /*
- * Save our context
- */
- ((struct i386_devdesc *)(f->f_devdata))->d_kind.biosdisk.data = od;
- DEBUG("open_disk %p, partition at 0x%x", od, od->od_boff);
- return(0);
-}
-
static int
-bd_opendisk(struct open_disk **odp, struct i386_devdesc *dev)
+bd_open(struct open_file *f, ...)
{
- struct open_disk *od;
- int error;
+ struct disk_devdesc *dev;
+ va_list ap;
- if (dev->d_unit >= nbdinfo) {
- DEBUG("attempt to open nonexistent disk");
- return(ENXIO);
- }
-
- od = (struct open_disk *)malloc(sizeof(struct open_disk));
- if (!od) {
- DEBUG("no memory");
- return (ENOMEM);
- }
+ va_start(ap, f);
+ dev = va_arg(ap, struct disk_devdesc *);
+ va_end(ap);
- /* Look up BIOS unit number, initalise open_disk structure */
- od->od_dkunit = dev->d_unit;
- od->od_unit = bdinfo[od->od_dkunit].bd_unit;
- od->od_flags = bdinfo[od->od_dkunit].bd_flags;
- od->od_boff = 0;
- error = 0;
- DEBUG("open '%s', unit 0x%x slice %d partition %d",
- i386_fmtdev(dev), dev->d_unit,
- dev->d_kind.biosdisk.slice, dev->d_kind.biosdisk.partition);
-
- /* Get geometry for this open (removable device may have changed) */
- if (bd_getgeom(od)) {
- DEBUG("can't get geometry");
- error = ENXIO;
- goto out;
- }
+ if (dev->d_unit < 0 || dev->d_unit >= nbdinfo)
+ return (EIO);
- /* Determine disk layout. */
-#ifdef LOADER_GPT_SUPPORT
- error = bd_open_gpt(od, dev);
- if (error)
-#endif
- error = bd_open_mbr(od, dev);
-
- out:
- if (error) {
- free(od);
- } else {
- *odp = od; /* return the open disk */
- }
- return(error);
+ return (disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
+ BD(dev).bd_sectorsize));
}
static int
-bd_open_mbr(struct open_disk *od, struct i386_devdesc *dev)
-{
- struct dos_partition *dptr;
- struct disklabel *lp;
- int sector, slice, i;
- int error;
- char buf[BUFSIZE];
-
- /*
- * Following calculations attempt to determine the correct value
- * for d->od_boff by looking for the slice and partition specified,
- * or searching for reasonable defaults.
- */
-
- /*
- * Find the slice in the DOS slice table.
- */
- od->od_nslices = 0;
- if (bd_read(od, 0, 1, buf)) {
- DEBUG("error reading MBR");
- return (EIO);
- }
-
- /*
- * Check the slice table magic.
- */
- if (((u_char)buf[0x1fe] != 0x55) || ((u_char)buf[0x1ff] != 0xaa)) {
- /* If a slice number was explicitly supplied, this is an error */
- if (dev->d_kind.biosdisk.slice > 0) {
- DEBUG("no slice table/MBR (no magic)");
- return (ENOENT);
- }
- sector = 0;
- goto unsliced; /* may be a floppy */
- }
-
- /*
- * copy the partition table, then pick up any extended partitions.
- */
- bcopy(buf + DOSPARTOFF, &od->od_slicetab,
- sizeof(struct dos_partition) * NDOSPART);
- od->od_nslices = 4; /* extended slices start here */
- for (i = 0; i < NDOSPART; i++)
- bd_checkextended(od, i);
- od->od_flags |= BD_PARTTABOK;
- dptr = &od->od_slicetab[0];
-
- /* Is this a request for the whole disk? */
- if (dev->d_kind.biosdisk.slice == -1) {
- sector = 0;
- goto unsliced;
- }
-
- /*
- * if a slice number was supplied but not found, this is an error.
- */
- if (dev->d_kind.biosdisk.slice > 0) {
- slice = dev->d_kind.biosdisk.slice - 1;
- if (slice >= od->od_nslices) {
- DEBUG("slice %d not found", slice);
- return (ENOENT);
- }
- }
-
- /*
- * Check for the historically bogus MBR found on true dedicated disks
- */
- if ((dptr[3].dp_typ == DOSPTYP_386BSD) &&
- (dptr[3].dp_start == 0) &&
- (dptr[3].dp_size == 50000)) {
- sector = 0;
- goto unsliced;
- }
-
- /* Try to auto-detect the best slice; this should always give a slice number */
- if (dev->d_kind.biosdisk.slice == 0) {
- slice = bd_bestslice(od);
- if (slice == -1) {
- return (ENOENT);
- }
- dev->d_kind.biosdisk.slice = slice;
- }
-
- dptr = &od->od_slicetab[0];
- /*
- * Accept the supplied slice number unequivocally (we may be looking
- * at a DOS partition).
- */
- dptr += (dev->d_kind.biosdisk.slice - 1); /* we number 1-4, offsets are 0-3 */
- sector = dptr->dp_start;
- DEBUG("slice entry %d at %d, %d sectors", dev->d_kind.biosdisk.slice - 1, sector, dptr->dp_size);
-
- /*
- * If we are looking at a BSD slice, and the partition is < 0, assume the 'a' partition
- */
- if ((dptr->dp_typ == DOSPTYP_386BSD) && (dev->d_kind.biosdisk.partition < 0))
- dev->d_kind.biosdisk.partition = 0;
-
- unsliced:
- /*
- * Now we have the slice offset, look for the partition in the disklabel if we have
- * a partition to start with.
- *
- * XXX we might want to check the label checksum.
- */
- if (dev->d_kind.biosdisk.partition < 0) {
- od->od_boff = sector; /* no partition, must be after the slice */
- DEBUG("opening raw slice");
- } else {
-
- if (bd_read(od, sector + LABELSECTOR, 1, buf)) {
- DEBUG("error reading disklabel");
- return (EIO);
- }
- DEBUG("copy %d bytes of label from %p to %p", sizeof(struct disklabel), buf + LABELOFFSET, &od->od_disklabel);
- bcopy(buf + LABELOFFSET, &od->od_disklabel, sizeof(struct disklabel));
- lp = &od->od_disklabel;
- od->od_flags |= BD_LABELOK;
-
- if (lp->d_magic != DISKMAGIC) {
- DEBUG("no disklabel");
- return (ENOENT);
- }
- if (dev->d_kind.biosdisk.partition >= lp->d_npartitions) {
- DEBUG("partition '%c' exceeds partitions in table (a-'%c')",
- 'a' + dev->d_kind.biosdisk.partition, 'a' + lp->d_npartitions);
- return (EPART);
- }
-
-#ifdef DISK_DEBUG
- /* Complain if the partition is unused unless this is a floppy. */
- if ((lp->d_partitions[dev->d_kind.biosdisk.partition].p_fstype == FS_UNUSED) &&
- !(od->od_flags & BD_FLOPPY))
- DEBUG("warning, partition marked as unused");
-#endif
-
- od->od_boff =
- lp->d_partitions[dev->d_kind.biosdisk.partition].p_offset -
- lp->d_partitions[RAW_PART].p_offset +
- sector;
- }
- return (0);
-}
-
-static void
-bd_checkextended(struct open_disk *od, int slicenum)
+bd_close(struct open_file *f)
{
- char buf[BIOSDISK_SECSIZE];
- struct dos_partition *dp;
- u_int base;
- int i, start, end;
-
- dp = &od->od_slicetab[slicenum];
- start = od->od_nslices;
-
- if (dp->dp_size == 0)
- goto done;
- if (dp->dp_typ != DOSPTYP_EXT)
- goto done;
- if (bd_read(od, (daddr_t)dp->dp_start, 1, buf))
- goto done;
- if (((u_char)buf[0x1fe] != 0x55) || ((u_char)buf[0x1ff] != 0xaa)) {
- DEBUG("no magic in extended table");
- goto done;
- }
- base = dp->dp_start;
- dp = (struct dos_partition *)(&buf[DOSPARTOFF]);
- for (i = 0; i < NDOSPART; i++, dp++) {
- if (dp->dp_size == 0)
- continue;
- if (od->od_nslices == NEXTDOSPART)
- goto done;
- dp->dp_start += base;
- bcopy(dp, &od->od_slicetab[od->od_nslices], sizeof(*dp));
- od->od_nslices++;
- }
- end = od->od_nslices;
-
- /*
- * now, recursively check the slices we just added
- */
- for (i = start; i < end; i++)
- bd_checkextended(od, i);
-done:
- return;
-}
-
-/*
- * Search for a slice with the following preferences:
- *
- * 1: Active FreeBSD slice
- * 2: Non-active FreeBSD slice
- * 3: Active Linux slice
- * 4: non-active Linux slice
- * 5: Active FAT/FAT32 slice
- * 6: non-active FAT/FAT32 slice
- */
-#define PREF_RAWDISK 0
-#define PREF_FBSD_ACT 1
-#define PREF_FBSD 2
-#define PREF_LINUX_ACT 3
-#define PREF_LINUX 4
-#define PREF_DOS_ACT 5
-#define PREF_DOS 6
-#define PREF_NONE 7
+ struct disk_devdesc *dev;
-/*
- * slicelimit is in the range 0 .. NDOSPART
- */
-static int
-bd_bestslice(struct open_disk *od)
-{
- struct dos_partition *dp;
- int pref, preflevel;
- int i, prefslice;
-
- prefslice = 0;
- preflevel = PREF_NONE;
-
- dp = &od->od_slicetab[0];
- for (i = 0; i < od->od_nslices; i++, dp++) {
-
- switch (dp->dp_typ) {
- case DOSPTYP_386BSD: /* FreeBSD */
- pref = dp->dp_flag & 0x80 ? PREF_FBSD_ACT : PREF_FBSD;
- break;
-
- case DOSPTYP_LINUX:
- pref = dp->dp_flag & 0x80 ? PREF_LINUX_ACT : PREF_LINUX;
- break;
-
- case 0x01: /* DOS/Windows */
- case 0x04:
- case 0x06:
- case 0x0b:
- case 0x0c:
- case 0x0e:
- pref = dp->dp_flag & 0x80 ? PREF_DOS_ACT : PREF_DOS;
- break;
-
- default:
- pref = PREF_NONE;
- }
- if (pref < preflevel) {
- preflevel = pref;
- prefslice = i + 1;
- }
- }
- return (prefslice);
+ dev = (struct disk_devdesc *)f->f_devdata;
+ return (disk_close(dev));
}
-#ifdef LOADER_GPT_SUPPORT
static int
-bd_open_gpt(struct open_disk *od, struct i386_devdesc *dev)
+bd_ioctl(struct open_file *f, u_long cmd, void *data)
{
- struct dos_partition *dp;
- struct gpt_hdr *hdr;
- struct gpt_ent *ent;
- struct gpt_part *gp;
- int entries_per_sec, error, i, part;
- daddr_t lba, elba;
- char gpt[BIOSDISK_SECSIZE], tbl[BIOSDISK_SECSIZE];
-
- /*
- * Following calculations attempt to determine the correct value
- * for d->od_boff by looking for the slice and partition specified,
- * or searching for reasonable defaults.
- */
- error = 0;
-
- /* First, read the MBR and see if we have a PMBR. */
- if (bd_read(od, 0, 1, tbl)) {
- DEBUG("error reading MBR");
- return (EIO);
- }
-
- /* Check the slice table magic. */
- if (((u_char)tbl[0x1fe] != 0x55) || ((u_char)tbl[0x1ff] != 0xaa))
- return (ENXIO);
-
- /* Check for GPT slice. */
- part = 0;
- dp = (struct dos_partition *)(tbl + DOSPARTOFF);
- for (i = 0; i < NDOSPART; i++) {
- if (dp[i].dp_typ == 0xee)
- part++;
- else if ((part != 1) && (dp[i].dp_typ != 0x00))
- return (EINVAL);
- }
- if (part != 1)
- return (EINVAL);
-
- /* Read primary GPT table header. */
- if (bd_read(od, 1, 1, gpt)) {
- DEBUG("error reading GPT header");
- return (EIO);
- }
- hdr = (struct gpt_hdr *)gpt;
- if (bcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) != 0 ||
- hdr->hdr_lba_self != 1 || hdr->hdr_revision < 0x00010000 ||
- hdr->hdr_entsz < sizeof(*ent) ||
- BIOSDISK_SECSIZE % hdr->hdr_entsz != 0) {
- DEBUG("Invalid GPT header\n");
- return (EINVAL);
- }
-
- /* Now walk the partition table to count the number of valid partitions. */
- part = 0;
- entries_per_sec = BIOSDISK_SECSIZE / hdr->hdr_entsz;
- elba = hdr->hdr_lba_table + hdr->hdr_entries / entries_per_sec;
- for (lba = hdr->hdr_lba_table; lba < elba; lba++) {
- if (bd_read(od, lba, 1, tbl)) {
- DEBUG("error reading GPT table");
- return (EIO);
- }
- for (i = 0; i < entries_per_sec; i++) {
- ent = (struct gpt_ent *)(tbl + i * hdr->hdr_entsz);
- if (uuid_is_nil(&ent->ent_type, NULL) || ent->ent_lba_start == 0 ||
- ent->ent_lba_end < ent->ent_lba_start)
- continue;
- part++;
- }
- }
-
- /* Save the important information about all the valid partitions. */
- od->od_nparts = part;
- if (part != 0) {
- od->od_partitions = malloc(part * sizeof(struct gpt_part));
- part = 0;
- for (lba = hdr->hdr_lba_table; lba < elba; lba++) {
- if (bd_read(od, lba, 1, tbl)) {
- DEBUG("error reading GPT table");
- error = EIO;
- goto out;
- }
- for (i = 0; i < entries_per_sec; i++) {
- ent = (struct gpt_ent *)(tbl + i * hdr->hdr_entsz);
- if (uuid_is_nil(&ent->ent_type, NULL) ||
- ent->ent_lba_start == 0 ||
- ent->ent_lba_end < ent->ent_lba_start)
- continue;
- od->od_partitions[part].gp_index = (lba - hdr->hdr_lba_table) *
- entries_per_sec + i + 1;
- od->od_partitions[part].gp_type = ent->ent_type;
- od->od_partitions[part].gp_start = ent->ent_lba_start;
- od->od_partitions[part].gp_end = ent->ent_lba_end;
- part++;
- }
- }
- }
- od->od_flags |= BD_GPTOK;
+ struct disk_devdesc *dev;
- /* Is this a request for the whole disk? */
- if (dev->d_kind.biosdisk.slice < 0) {
- od->od_boff = 0;
- return (0);
- }
-
- /*
- * If a partition number was supplied, then the user is trying to use
- * an MBR address rather than a GPT address, so fail.
- */
- if (dev->d_kind.biosdisk.partition != 0xff) {
- error = ENOENT;
- goto out;
- }
-
- /* If a slice number was supplied but not found, this is an error. */
- gp = NULL;
- if (dev->d_kind.biosdisk.slice > 0) {
- for (i = 0; i < od->od_nparts; i++) {
- if (od->od_partitions[i].gp_index == dev->d_kind.biosdisk.slice) {
- gp = &od->od_partitions[i];
+ dev = (struct disk_devdesc *)f->f_devdata;
+ switch (cmd) {
+ case DIOCGSECTORSIZE:
+ *(u_int *)data = BD(dev).bd_sectorsize;
break;
- }
- }
- if (gp == NULL) {
- DEBUG("partition %d not found", dev->d_kind.biosdisk.slice);
- error = ENOENT;
- goto out;
- }
- }
-
- /* Try to auto-detect the best partition. */
- if (dev->d_kind.biosdisk.slice == 0) {
- gp = bd_best_gptpart(od);
- if (gp == NULL) {
- error = ENOENT;
- goto out;
- }
- dev->d_kind.biosdisk.slice = gp->gp_index;
- }
- od->od_boff = gp->gp_start;
-
-out:
- if (error) {
- if (od->od_nparts > 0)
- free(od->od_partitions);
- od->od_flags &= ~BD_GPTOK;
- }
- return (error);
-}
-
-static struct gpt_part *
-bd_best_gptpart(struct open_disk *od)
-{
- struct gpt_part *gp, *prefpart;
- int i, pref, preflevel;
-
- prefpart = NULL;
- preflevel = PREF_NONE;
-
- gp = od->od_partitions;
- for (i = 0; i < od->od_nparts; i++, gp++) {
- /* Windows. XXX: Also Linux. */
- if (uuid_equal(&gp->gp_type, &ms_basic_data, NULL))
- pref = PREF_DOS;
- /* FreeBSD */
- else if (uuid_equal(&gp->gp_type, &freebsd_ufs, NULL) ||
- uuid_equal(&gp->gp_type, &freebsd_zfs, NULL))
- pref = PREF_FBSD;
- else
- pref = PREF_NONE;
- if (pref < preflevel) {
- preflevel = pref;
- prefpart = gp;
+ case DIOCGMEDIASIZE:
+ *(off_t *)data = BD(dev).bd_sectors * BD(dev).bd_sectorsize;
+ break;
+ default:
+ return (ENOTTY);
}
- }
- return (prefpart);
-}
-#endif
-
-static int
-bd_close(struct open_file *f)
-{
- struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)(f->f_devdata))->d_kind.biosdisk.data);
-
- bd_closedisk(od);
- return(0);
-}
-
-static void
-bd_closedisk(struct open_disk *od)
-{
- DEBUG("open_disk %p", od);
-#if 0
- /* XXX is this required? (especially if disk already open...) */
- if (od->od_flags & BD_FLOPPY)
- delay(3000000);
-#endif
-#ifdef LOADER_GPT_SUPPORT
- if (od->od_flags & BD_GPTOK && od->od_nparts > 0)
- free(od->od_partitions);
-#endif
- free(od);
+ return (0);
}
-static int
-bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize)
+static int
+bd_strategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf,
+ size_t *rsize)
{
- struct bcache_devdata bcd;
- struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data);
-
- bcd.dv_strategy = bd_realstrategy;
- bcd.dv_devdata = devdata;
- return(bcache_strategy(&bcd, od->od_unit, rw, dblk+od->od_boff, size, buf, rsize));
+ struct bcache_devdata bcd;
+ struct disk_devdesc *dev;
+
+ dev = (struct disk_devdesc *)devdata;
+ bcd.dv_strategy = bd_realstrategy;
+ bcd.dv_devdata = devdata;
+ return (bcache_strategy(&bcd, BD(dev).bd_unit, rw, dblk + dev->d_offset,
+ size, buf, rsize));
}
-static int
-bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, size_t *rsize)
+static int
+bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf,
+ size_t *rsize)
{
- struct open_disk *od = (struct open_disk *)(((struct i386_devdesc *)devdata)->d_kind.biosdisk.data);
+ struct disk_devdesc *dev = (struct disk_devdesc *)devdata;
int blks;
-#ifdef BD_SUPPORT_FRAGS
+#ifdef BD_SUPPORT_FRAGS /* XXX: sector size */
char fragbuf[BIOSDISK_SECSIZE];
size_t fragsize;
fragsize = size % BIOSDISK_SECSIZE;
#else
- if (size % BIOSDISK_SECSIZE)
+ if (size % BD(dev).bd_sectorsize)
panic("bd_strategy: %d bytes I/O not multiple of block size", size);
#endif
- DEBUG("open_disk %p", od);
- blks = size / BIOSDISK_SECSIZE;
+ DEBUG("open_disk %p", dev);
+ blks = size / BD(dev).bd_sectorsize;
if (rsize)
*rsize = 0;
@@ -1088,11 +366,11 @@ bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, siz
case F_READ:
DEBUG("read %d from %lld to %p", blks, dblk, buf);
- if (blks && bd_read(od, dblk, blks, buf)) {
+ if (blks && bd_read(dev, dblk, blks, buf)) {
DEBUG("read error");
return (EIO);
}
-#ifdef BD_SUPPORT_FRAGS
+#ifdef BD_SUPPORT_FRAGS /* XXX: sector size */
DEBUG("bd_strategy: frag read %d from %d+%d to %p",
fragsize, dblk, blks, buf + (blks * BIOSDISK_SECSIZE));
if (fragsize && bd_read(od, dblk + blks, 1, fragsize)) {
@@ -1105,7 +383,7 @@ bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, siz
case F_WRITE :
DEBUG("write %d from %d to %p", blks, dblk, buf);
- if (blks && bd_write(od, dblk, blks, buf)) {
+ if (blks && bd_write(dev, dblk, blks, buf)) {
DEBUG("write error");
return (EIO);
}
@@ -1130,7 +408,8 @@ bd_realstrategy(void *devdata, int rw, daddr_t dblk, size_t size, char *buf, siz
#define FLOPPY_BOUNCEBUF 18
static int
-bd_edd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
+bd_edd_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest,
+ int write)
{
static struct edd_packet packet;
@@ -1146,7 +425,7 @@ bd_edd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
v86.eax = 0x4300;
else
v86.eax = 0x4200;
- v86.edx = od->od_unit;
+ v86.edx = BD(dev).bd_unit;
v86.ds = VTOPSEG(&packet);
v86.esi = VTOPOFF(&packet);
v86int();
@@ -1154,16 +433,17 @@ bd_edd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
}
static int
-bd_chs_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
+bd_chs_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest,
+ int write)
{
u_int x, bpc, cyl, hd, sec;
- bpc = (od->od_sec * od->od_hds); /* blocks per cylinder */
+ bpc = BD(dev).bd_sec * BD(dev).bd_hds; /* blocks per cylinder */
x = dblk;
cyl = x / bpc; /* block # / blocks per cylinder */
x %= bpc; /* block offset into cylinder */
- hd = x / od->od_sec; /* offset / blocks per track */
- sec = x % od->od_sec; /* offset into track */
+ hd = x / BD(dev).bd_sec; /* offset / blocks per track */
+ sec = x % BD(dev).bd_sec; /* offset into track */
/* correct sector number for 1-based BIOS numbering */
sec++;
@@ -1179,7 +459,7 @@ bd_chs_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
else
v86.eax = 0x200 | blks;
v86.ecx = ((cyl & 0xff) << 8) | ((cyl & 0x300) >> 2) | sec;
- v86.edx = (hd << 8) | od->od_unit;
+ v86.edx = (hd << 8) | BD(dev).bd_unit;
v86.es = VTOPSEG(dest);
v86.ebx = VTOPOFF(dest);
v86int();
@@ -1187,7 +467,7 @@ bd_chs_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
}
static int
-bd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
+bd_io(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest, int write)
{
u_int x, sec, result, resid, retry, maxfer;
caddr_t p, xp, bbuf, breg;
@@ -1200,8 +480,9 @@ bd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
p = dest;
/* Decide whether we have to bounce */
- if (VTOP(dest) >> 20 != 0 || ((od->od_unit < 0x80) &&
- ((VTOP(dest) >> 16) != (VTOP(dest + blks * BIOSDISK_SECSIZE) >> 16)))) {
+ if (VTOP(dest) >> 20 != 0 || (BD(dev).bd_unit < 0x80 &&
+ (VTOP(dest) >> 16) != (VTOP(dest +
+ blks * BD(dev).bd_sectorsize) >> 16))) {
/*
* There is a 64k physical boundary somewhere in the
@@ -1212,12 +493,12 @@ bd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
* there, in which case we use the top half.
*/
x = min(FLOPPY_BOUNCEBUF, (unsigned)blks);
- bbuf = alloca(x * 2 * BIOSDISK_SECSIZE);
+ bbuf = alloca(x * 2 * BD(dev).bd_sectorsize);
if (((u_int32_t)VTOP(bbuf) & 0xffff0000) ==
- ((u_int32_t)VTOP(bbuf + x * BIOSDISK_SECSIZE) & 0xffff0000)) {
+ ((u_int32_t)VTOP(bbuf + x * BD(dev).bd_sectorsize) & 0xffff0000)) {
breg = bbuf;
} else {
- breg = bbuf + x * BIOSDISK_SECSIZE;
+ breg = bbuf + x * BD(dev).bd_sectorsize;
}
maxfer = x; /* limit transfers to bounce region size */
} else {
@@ -1230,8 +511,8 @@ bd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
* Play it safe and don't cross track boundaries.
* (XXX this is probably unnecessary)
*/
- sec = dblk % od->od_sec; /* offset into track */
- x = min(od->od_sec - sec, resid);
+ sec = dblk % BD(dev).bd_sec; /* offset into track */
+ x = min(BD(dev).bd_sec - sec, resid);
if (maxfer > 0)
x = min(x, maxfer); /* fit bounce buffer */
@@ -1243,7 +524,7 @@ bd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
* Put your Data In, and shake it all about
*/
if (write && bbuf != NULL)
- bcopy(p, breg, x * BIOSDISK_SECSIZE);
+ bcopy(p, breg, x * BD(dev).bd_sectorsize);
/*
* Loop retrying the operation a couple of times. The BIOS
@@ -1255,14 +536,14 @@ bd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
v86.ctl = V86_FLAGS;
v86.addr = 0x13;
v86.eax = 0;
- v86.edx = od->od_unit;
+ v86.edx = BD(dev).bd_unit;
v86int();
}
- if (od->od_flags & BD_MODEEDD1)
- result = bd_edd_io(od, dblk, x, xp, write);
+ if (BD(dev).bd_flags & BD_MODEEDD1)
+ result = bd_edd_io(dev, dblk, x, xp, write);
else
- result = bd_chs_io(od, dblk, x, xp, write);
+ result = bd_chs_io(dev, dblk, x, xp, write);
if (result == 0)
break;
}
@@ -1277,52 +558,28 @@ bd_io(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest, int write)
return(-1);
}
if (!write && bbuf != NULL)
- bcopy(breg, p, x * BIOSDISK_SECSIZE);
- p += (x * BIOSDISK_SECSIZE);
+ bcopy(breg, p, x * BD(dev).bd_sectorsize);
+ p += (x * BD(dev).bd_sectorsize);
dblk += x;
resid -= x;
}
-/* hexdump(dest, (blks * BIOSDISK_SECSIZE)); */
+/* hexdump(dest, (blks * BD(dev).bd_sectorsize)); */
return(0);
}
static int
-bd_read(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest)
-{
-
- return (bd_io(od, dblk, blks, dest, 0));
-}
-
-static int
-bd_write(struct open_disk *od, daddr_t dblk, int blks, caddr_t dest)
+bd_read(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest)
{
- return (bd_io(od, dblk, blks, dest, 1));
+ return (bd_io(dev, dblk, blks, dest, 0));
}
static int
-bd_getgeom(struct open_disk *od)
+bd_write(struct disk_devdesc *dev, daddr_t dblk, int blks, caddr_t dest)
{
- v86.ctl = V86_FLAGS;
- v86.addr = 0x13;
- v86.eax = 0x800;
- v86.edx = od->od_unit;
- v86int();
-
- if ((V86_CY(v86.efl)) || /* carry set */
- ((v86.edx & 0xff) <= (unsigned)(od->od_unit & 0x7f))) /* unit # bad */
- return(1);
-
- /* convert max cyl # -> # of cylinders */
- od->od_cyl = ((v86.ecx & 0xc0) << 2) + ((v86.ecx & 0xff00) >> 8) + 1;
- /* convert max head # -> # of heads */
- od->od_hds = ((v86.edx & 0xff00) >> 8) + 1;
- od->od_sec = v86.ecx & 0x3f;
-
- DEBUG("unit 0x%x geometry %d/%d/%d", od->od_unit, od->od_cyl, od->od_hds, od->od_sec);
- return(0);
+ return (bd_io(dev, dblk, blks, dest, 1));
}
/*
@@ -1361,21 +618,25 @@ bd_getbigeom(int bunit)
* IDE disks to be specified in $num_ide_disks. There should be a Better Way.
*/
int
-bd_getdev(struct i386_devdesc *dev)
+bd_getdev(struct i386_devdesc *d)
{
- struct open_disk *od;
+ struct disk_devdesc *dev;
int biosdev;
int major;
int rootdev;
char *nip, *cp;
- int unitofs = 0, i, unit;
+ int i, unit;
+ dev = (struct disk_devdesc *)d;
biosdev = bd_unit2bios(dev->d_unit);
DEBUG("unit %d BIOS device %d", dev->d_unit, biosdev);
if (biosdev == -1) /* not a BIOS device */
return(-1);
- if (bd_opendisk(&od, dev) != 0) /* oops, not a viable device */
- return(-1);
+ if (disk_open(dev, BD(dev).bd_sectors * BD(dev).bd_sectorsize,
+ BD(dev).bd_sectorsize) != 0) /* oops, not a viable device */
+ return (-1);
+ else
+ disk_close(dev);
if (biosdev < 0x80) {
/* floppy (or emulated floppy) or ATAPI device */
@@ -1387,24 +648,11 @@ bd_getdev(struct i386_devdesc *dev)
major = FDMAJOR;
}
} else {
- /* harddisk */
- if ((od->od_flags & BD_LABELOK) && (od->od_disklabel.d_type == DTYPE_SCSI)) {
- /* label OK, disk labelled as SCSI */
- major = DAMAJOR;
- /* check for unit number correction hint, now deprecated */
- if ((nip = getenv("num_ide_disks")) != NULL) {
- i = strtol(nip, &cp, 0);
- /* check for parse error */
- if ((cp != nip) && (*cp == 0))
- unitofs = i;
- }
- } else {
/* assume an IDE disk */
major = WDMAJOR;
- }
}
/* default root disk unit number */
- unit = (biosdev & 0x7f) - unitofs;
+ unit = biosdev & 0x7f;
/* XXX a better kludge to set the root disk unit number */
if ((nip = getenv("root_disk_unit")) != NULL) {
@@ -1414,8 +662,7 @@ bd_getdev(struct i386_devdesc *dev)
unit = i;
}
- rootdev = MAKEBOOTDEV(major, dev->d_kind.biosdisk.slice + 1, unit,
- dev->d_kind.biosdisk.partition);
+ rootdev = MAKEBOOTDEV(major, dev->d_slice + 1, unit, dev->d_partition);
DEBUG("dev is 0x%x\n", rootdev);
return(rootdev);
}
diff --git a/sys/boot/i386/libi386/devicename.c b/sys/boot/i386/libi386/devicename.c
index 534af4c..15889d3 100644
--- a/sys/boot/i386/libi386/devicename.c
+++ b/sys/boot/i386/libi386/devicename.c
@@ -29,8 +29,8 @@ __FBSDID("$FreeBSD$");
#include <stand.h>
#include <string.h>
-#include <sys/disklabel.h>
#include "bootstrap.h"
+#include "disk.h"
#include "libi386.h"
#include "../zfs/libzfs.h"
@@ -86,7 +86,7 @@ i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path)
{
struct i386_devdesc *idev;
struct devsw *dv;
- int i, unit, slice, partition, err;
+ int i, unit, err;
char *cp;
const char *np;
@@ -112,62 +112,9 @@ i386_parsedev(struct i386_devdesc **dev, const char *devspec, const char **path)
break;
case DEVT_DISK:
- unit = -1;
- slice = -1;
- partition = -1;
- if (*np && (*np != ':')) {
- unit = strtol(np, &cp, 10); /* next comes the unit number */
- if (cp == np) {
- err = EUNIT;
- goto fail;
- }
-#ifdef LOADER_GPT_SUPPORT
- if (*cp == 'p') { /* got a GPT partition */
- np = cp + 1;
- slice = strtol(np, &cp, 10);
- if (cp == np) {
- err = ESLICE;
- goto fail;
- }
- if (*cp && (*cp != ':')) {
- err = EINVAL;
- goto fail;
- }
- partition = 0xff;
- } else {
-#endif
- if (*cp == 's') { /* got a slice number */
- np = cp + 1;
- slice = strtol(np, &cp, 10);
- if (cp == np) {
- err = ESLICE;
- goto fail;
- }
- }
- if (*cp && (*cp != ':')) {
- partition = *cp - 'a'; /* got a partition number */
- if ((partition < 0) || (partition >= MAXPARTITIONS)) {
- err = EPART;
- goto fail;
- }
- cp++;
- }
-#ifdef LOADER_GPT_SUPPORT
- }
-#endif
- } else {
- cp = np;
- }
- if (*cp && (*cp != ':')) {
- err = EINVAL;
+ err = disk_parsedev((struct disk_devdesc *)idev, np, path);
+ if (err != 0)
goto fail;
- }
-
- idev->d_unit = unit;
- idev->d_kind.biosdisk.slice = slice;
- idev->d_kind.biosdisk.partition = partition;
- if (path != NULL)
- *path = (*cp == 0) ? cp : cp + 1;
break;
case DEVT_CD:
@@ -221,38 +168,20 @@ i386_fmtdev(void *vdev)
{
struct i386_devdesc *dev = (struct i386_devdesc *)vdev;
static char buf[128]; /* XXX device length constant? */
- char *cp;
-
+
switch(dev->d_type) {
case DEVT_NONE:
strcpy(buf, "(no device)");
break;
case DEVT_CD:
+ case DEVT_NET:
sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
break;
case DEVT_DISK:
- cp = buf;
- cp += sprintf(cp, "%s%d", dev->d_dev->dv_name, dev->d_unit);
-#ifdef LOADER_GPT_SUPPORT
- if (dev->d_kind.biosdisk.partition == 0xff) {
- cp += sprintf(cp, "p%d", dev->d_kind.biosdisk.slice);
- } else {
-#endif
- if (dev->d_kind.biosdisk.slice > 0)
- cp += sprintf(cp, "s%d", dev->d_kind.biosdisk.slice);
- if (dev->d_kind.biosdisk.partition >= 0)
- cp += sprintf(cp, "%c", dev->d_kind.biosdisk.partition + 'a');
-#ifdef LOADER_GPT_SUPPORT
- }
-#endif
- strcat(cp, ":");
- break;
+ return (disk_fmtdev(vdev));
- case DEVT_NET:
- sprintf(buf, "%s%d:", dev->d_dev->dv_name, dev->d_unit);
- break;
case DEVT_ZFS:
return(zfs_fmtdev(vdev));
}
diff --git a/sys/boot/i386/libi386/libi386.h b/sys/boot/i386/libi386/libi386.h
index 3edeb92..f7dc379 100644
--- a/sys/boot/i386/libi386/libi386.h
+++ b/sys/boot/i386/libi386/libi386.h
@@ -45,6 +45,7 @@ struct i386_devdesc
void *data;
int slice;
int partition;
+ off_t offset;
} biosdisk;
struct
{
OpenPOWER on IntegriCloud