2002-03-11 21:42:35 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Poul-Henning Kamp
|
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Poul-Henning Kamp
|
|
|
|
* and NAI Labs, the Security Research Division of Network Associates, Inc.
|
|
|
|
* under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
|
|
|
|
* DARPA CHATS research program.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-06-11 06:49:16 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
#include <sys/param.h>
|
2002-12-16 23:08:48 +00:00
|
|
|
#include <sys/errno.h>
|
2003-04-03 11:36:53 +00:00
|
|
|
#include <sys/endian.h>
|
2002-03-11 21:42:35 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
|
2002-10-01 14:05:06 +00:00
|
|
|
#include <sys/diskmbr.h>
|
2002-03-11 21:42:35 +00:00
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#include <geom/geom.h>
|
|
|
|
#include <geom/geom_slice.h>
|
|
|
|
|
2002-05-21 19:50:04 +00:00
|
|
|
#define MBR_CLASS_NAME "MBR"
|
|
|
|
#define MBREXT_CLASS_NAME "MBREXT"
|
2002-03-24 11:21:41 +00:00
|
|
|
|
2002-12-16 23:08:48 +00:00
|
|
|
static struct dos_partition historical_bogus_partition_table[NDOSPART] = {
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
|
|
|
{ 0x80, 0, 1, 0, DOSPTYP_386BSD, 255, 255, 255, 0, 50000, },
|
|
|
|
};
|
2003-04-09 09:21:33 +00:00
|
|
|
|
2002-12-16 23:08:48 +00:00
|
|
|
static struct dos_partition historical_bogus_partition_table_fixed[NDOSPART] = {
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
|
|
|
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
|
|
|
|
{ 0x80, 0, 1, 0, DOSPTYP_386BSD, 254, 255, 255, 0, 50000, },
|
|
|
|
};
|
2003-01-11 12:30:51 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
g_mbr_print(int i, struct dos_partition *dp)
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("[%d] f:%02x typ:%d", i, dp->dp_flag, dp->dp_typ);
|
2003-04-09 09:21:33 +00:00
|
|
|
printf(" s(CHS):%d/%d/%d", DPCYL(dp->dp_scyl, dp->dp_ssect),
|
|
|
|
dp->dp_shd, DPSECT(dp->dp_ssect));
|
|
|
|
printf(" e(CHS):%d/%d/%d", DPCYL(dp->dp_ecyl, dp->dp_esect),
|
|
|
|
dp->dp_ehd, DPSECT(dp->dp_esect));
|
2003-01-11 12:30:51 +00:00
|
|
|
printf(" s:%d l:%d\n", dp->dp_start, dp->dp_size);
|
|
|
|
}
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
struct g_mbr_softc {
|
|
|
|
int type [NDOSPART];
|
2003-01-11 12:30:51 +00:00
|
|
|
u_int sectorsize;
|
2002-12-29 14:59:24 +00:00
|
|
|
u_char sec0[512];
|
2002-03-11 21:42:35 +00:00
|
|
|
};
|
|
|
|
|
2002-12-16 23:08:48 +00:00
|
|
|
static int
|
2002-12-29 14:59:24 +00:00
|
|
|
g_mbr_modify(struct g_geom *gp, struct g_mbr_softc *ms, u_char *sec0)
|
2002-12-16 23:08:48 +00:00
|
|
|
{
|
|
|
|
int i, error;
|
|
|
|
off_t l[NDOSPART];
|
2002-12-29 14:59:24 +00:00
|
|
|
struct dos_partition ndp[NDOSPART], *dp;
|
2002-12-16 23:08:48 +00:00
|
|
|
|
|
|
|
g_topology_assert();
|
|
|
|
|
2002-12-29 14:59:24 +00:00
|
|
|
if (sec0[0x1fe] != 0x55 && sec0[0x1ff] != 0xaa)
|
|
|
|
return (EBUSY);
|
|
|
|
|
|
|
|
dp = ndp;
|
2003-01-11 12:30:51 +00:00
|
|
|
for (i = 0; i < NDOSPART; i++) {
|
2003-04-12 08:34:40 +00:00
|
|
|
dos_partition_dec(
|
2002-12-29 14:59:24 +00:00
|
|
|
sec0 + DOSPARTOFF + i * sizeof(struct dos_partition),
|
|
|
|
dp + i);
|
2003-01-11 12:30:51 +00:00
|
|
|
if (bootverbose)
|
|
|
|
g_mbr_print(i, dp + i);
|
|
|
|
}
|
2002-12-16 23:08:48 +00:00
|
|
|
if ((!bcmp(dp, historical_bogus_partition_table,
|
|
|
|
sizeof historical_bogus_partition_table)) ||
|
|
|
|
(!bcmp(dp, historical_bogus_partition_table_fixed,
|
|
|
|
sizeof historical_bogus_partition_table_fixed))) {
|
|
|
|
/*
|
|
|
|
* We will not allow people to write these from "the inside",
|
|
|
|
* Since properly selfdestructing takes too much code. If
|
|
|
|
* people really want to do this, they cannot have any
|
|
|
|
* providers of this geom open, and in that case they can just
|
|
|
|
* as easily overwrite the MBR in the parent device.
|
|
|
|
*/
|
|
|
|
return(EBUSY);
|
|
|
|
}
|
|
|
|
for (i = 0; i < NDOSPART; i++) {
|
|
|
|
/*
|
|
|
|
* A Protective MBR (PMBR) has a single partition of
|
|
|
|
* type 0xEE spanning the whole disk. Such a MBR
|
|
|
|
* protects a GPT on the disk from MBR tools that
|
|
|
|
* don't know anything about GPT. We're interpreting
|
|
|
|
* it a bit more loosely: any partition of type 0xEE
|
|
|
|
* is to be skipped as it doesn't contain any data
|
|
|
|
* that we should care about. We still allow other
|
|
|
|
* partitions to be present in the MBR. A PMBR will
|
|
|
|
* be handled correctly anyway.
|
|
|
|
*/
|
2003-04-03 18:55:16 +00:00
|
|
|
if (dp[i].dp_typ == DOSPTYP_PMBR)
|
2002-12-16 23:08:48 +00:00
|
|
|
l[i] = 0;
|
|
|
|
else if (dp[i].dp_flag != 0 && dp[i].dp_flag != 0x80)
|
|
|
|
l[i] = 0;
|
|
|
|
else if (dp[i].dp_typ == 0)
|
|
|
|
l[i] = 0;
|
|
|
|
else
|
2003-01-11 12:30:51 +00:00
|
|
|
l[i] = (off_t)dp[i].dp_size * ms->sectorsize;
|
2002-12-16 23:08:48 +00:00
|
|
|
error = g_slice_config(gp, i, G_SLICE_CONFIG_CHECK,
|
2003-01-11 12:30:51 +00:00
|
|
|
(off_t)dp[i].dp_start * ms->sectorsize, l[i],
|
|
|
|
ms->sectorsize, "%ss%d", gp->name, 1 + i);
|
2002-12-16 23:08:48 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
for (i = 0; i < NDOSPART; i++) {
|
|
|
|
ms->type[i] = dp[i].dp_typ;
|
|
|
|
g_slice_config(gp, i, G_SLICE_CONFIG_SET,
|
2003-01-11 12:30:51 +00:00
|
|
|
(off_t)dp[i].dp_start * ms->sectorsize, l[i],
|
|
|
|
ms->sectorsize, "%ss%d", gp->name, 1 + i);
|
2002-12-16 23:08:48 +00:00
|
|
|
}
|
2002-12-29 14:59:24 +00:00
|
|
|
bcopy(sec0, ms->sec0, 512);
|
2002-12-16 23:08:48 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-12-29 14:59:24 +00:00
|
|
|
static void
|
2003-04-02 21:10:04 +00:00
|
|
|
g_mbr_ioctl(void *arg, int flag)
|
2002-12-29 14:59:24 +00:00
|
|
|
{
|
|
|
|
struct bio *bp;
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
struct g_mbr_softc *ms;
|
|
|
|
struct g_ioctl *gio;
|
|
|
|
struct g_consumer *cp;
|
|
|
|
u_char *sec0;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
bp = arg;
|
2003-04-02 21:10:04 +00:00
|
|
|
if (flag == EV_CANCEL) {
|
|
|
|
g_io_deliver(bp, ENXIO);
|
|
|
|
return;
|
|
|
|
}
|
2002-12-29 14:59:24 +00:00
|
|
|
gp = bp->bio_to->geom;
|
|
|
|
gsp = gp->softc;
|
|
|
|
ms = gsp->softc;
|
|
|
|
gio = (struct g_ioctl *)bp->bio_data;
|
|
|
|
|
|
|
|
/* The disklabel to set is the ioctl argument. */
|
|
|
|
sec0 = gio->data;
|
|
|
|
|
|
|
|
error = g_mbr_modify(gp, ms, sec0);
|
|
|
|
if (error) {
|
|
|
|
g_io_deliver(bp, error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cp = LIST_FIRST(&gp->consumer);
|
|
|
|
error = g_write_data(cp, 0, sec0, 512);
|
|
|
|
g_io_deliver(bp, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-11 21:42:35 +00:00
|
|
|
static int
|
|
|
|
g_mbr_start(struct bio *bp)
|
|
|
|
{
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_mbr_softc *mp;
|
|
|
|
struct g_slicer *gsp;
|
2002-12-29 14:59:24 +00:00
|
|
|
struct g_ioctl *gio;
|
|
|
|
int idx, error;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
|
|
|
pp = bp->bio_to;
|
2002-12-16 22:33:27 +00:00
|
|
|
idx = pp->index;
|
2002-03-11 21:42:35 +00:00
|
|
|
gp = pp->geom;
|
|
|
|
gsp = gp->softc;
|
|
|
|
mp = gsp->softc;
|
|
|
|
if (bp->bio_cmd == BIO_GETATTR) {
|
2002-12-16 22:33:27 +00:00
|
|
|
if (g_handleattr_int(bp, "MBR::type", mp->type[idx]))
|
2002-03-11 21:42:35 +00:00
|
|
|
return (1);
|
2002-10-28 07:50:47 +00:00
|
|
|
if (g_handleattr_off_t(bp, "MBR::offset",
|
2002-12-16 22:33:27 +00:00
|
|
|
gsp->slices[idx].offset))
|
2002-10-28 07:50:47 +00:00
|
|
|
return (1);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
2002-12-29 14:59:24 +00:00
|
|
|
|
|
|
|
/* We only handle ioctl(2) requests of the right format. */
|
|
|
|
if (strcmp(bp->bio_attribute, "GEOM::ioctl"))
|
|
|
|
return (0);
|
|
|
|
else if (bp->bio_length != sizeof(*gio))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Get hold of the ioctl parameters. */
|
|
|
|
gio = (struct g_ioctl *)bp->bio_data;
|
|
|
|
|
|
|
|
switch (gio->cmd) {
|
|
|
|
case DIOCSMBR:
|
|
|
|
/*
|
|
|
|
* These we cannot do without the topology lock and some
|
|
|
|
* some I/O requests. Ask the event-handler to schedule
|
|
|
|
* us in a less restricted environment.
|
|
|
|
*/
|
2003-04-23 20:46:12 +00:00
|
|
|
error = g_post_event(g_mbr_ioctl, bp, M_NOWAIT, gp, NULL);
|
2002-12-29 14:59:24 +00:00
|
|
|
if (error)
|
|
|
|
g_io_deliver(bp, error);
|
|
|
|
/*
|
|
|
|
* We must return non-zero to indicate that we will deal
|
|
|
|
* with this bio, even though we have not done so yet.
|
|
|
|
*/
|
|
|
|
return (1);
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-16 22:33:27 +00:00
|
|
|
g_mbr_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_mbr_softc *mp;
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
|
|
|
|
gsp = gp->softc;
|
|
|
|
mp = gsp->softc;
|
2002-10-28 07:50:47 +00:00
|
|
|
g_slice_dumpconf(sb, indent, gp, cp, pp);
|
2002-03-11 21:42:35 +00:00
|
|
|
if (pp != NULL) {
|
2002-11-02 12:01:12 +00:00
|
|
|
if (indent == NULL)
|
|
|
|
sbuf_printf(sb, " ty %d", mp->type[pp->index]);
|
|
|
|
else
|
|
|
|
sbuf_printf(sb, "%s<type>%d</type>\n", indent,
|
|
|
|
mp->type[pp->index]);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct g_geom *
|
2002-03-26 22:07:38 +00:00
|
|
|
g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_consumer *cp;
|
2002-12-29 14:59:24 +00:00
|
|
|
int error;
|
2002-03-11 21:42:35 +00:00
|
|
|
struct g_mbr_softc *ms;
|
2002-04-09 15:43:32 +00:00
|
|
|
u_int fwsectors, sectorsize;
|
2002-03-11 21:42:35 +00:00
|
|
|
u_char *buf;
|
|
|
|
|
|
|
|
g_trace(G_T_TOPOLOGY, "mbr_taste(%s,%s)", mp->name, pp->name);
|
|
|
|
g_topology_assert();
|
|
|
|
gp = g_slice_new(mp, NDOSPART, pp, &cp, &ms, sizeof *ms, g_mbr_start);
|
|
|
|
if (gp == NULL)
|
|
|
|
return (NULL);
|
|
|
|
g_topology_unlock();
|
|
|
|
gp->dumpconf = g_mbr_dumpconf;
|
2003-04-09 08:56:26 +00:00
|
|
|
do {
|
2002-03-11 21:42:35 +00:00
|
|
|
if (gp->rank != 2 && insist == 0)
|
|
|
|
break;
|
2002-04-09 15:43:32 +00:00
|
|
|
error = g_getattr("GEOM::fwsectors", cp, &fwsectors);
|
|
|
|
if (error)
|
|
|
|
fwsectors = 17;
|
2002-10-20 20:28:24 +00:00
|
|
|
sectorsize = cp->provider->sectorsize;
|
2003-01-11 12:30:51 +00:00
|
|
|
if (sectorsize < 512)
|
2002-03-11 21:42:35 +00:00
|
|
|
break;
|
2003-01-11 12:30:51 +00:00
|
|
|
ms->sectorsize = sectorsize;
|
2002-04-09 15:43:32 +00:00
|
|
|
buf = g_read_data(cp, 0, sectorsize, &error);
|
2002-03-11 21:42:35 +00:00
|
|
|
if (buf == NULL || error != 0)
|
|
|
|
break;
|
2002-12-17 09:44:10 +00:00
|
|
|
g_topology_lock();
|
2002-12-29 14:59:24 +00:00
|
|
|
g_mbr_modify(gp, ms, buf);
|
2002-12-17 09:44:10 +00:00
|
|
|
g_topology_unlock();
|
2002-12-29 14:59:24 +00:00
|
|
|
g_free(buf);
|
2002-03-11 21:42:35 +00:00
|
|
|
break;
|
2003-04-09 08:56:26 +00:00
|
|
|
} while (0);
|
2002-03-11 21:42:35 +00:00
|
|
|
g_topology_lock();
|
2002-12-16 23:08:48 +00:00
|
|
|
g_access_rel(cp, -1, 0, 0);
|
|
|
|
if (LIST_EMPTY(&gp->provider)) {
|
2003-05-02 08:13:03 +00:00
|
|
|
g_slice_spoiled(cp);
|
2002-12-16 23:08:48 +00:00
|
|
|
return (NULL);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
2002-12-16 23:08:48 +00:00
|
|
|
return (gp);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
2002-03-26 21:40:06 +00:00
|
|
|
static struct g_class g_mbr_class = {
|
2003-03-24 19:30:15 +00:00
|
|
|
.name = MBR_CLASS_NAME,
|
|
|
|
.taste = g_mbr_taste,
|
2002-03-11 21:42:35 +00:00
|
|
|
};
|
|
|
|
|
2002-03-26 21:40:06 +00:00
|
|
|
DECLARE_GEOM_CLASS(g_mbr_class, g_mbr);
|
2002-03-24 11:21:41 +00:00
|
|
|
|
|
|
|
#define NDOSEXTPART 32
|
|
|
|
struct g_mbrext_softc {
|
|
|
|
int type [NDOSEXTPART];
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
g_mbrext_start(struct bio *bp)
|
|
|
|
{
|
|
|
|
struct g_provider *pp;
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_mbrext_softc *mp;
|
|
|
|
struct g_slicer *gsp;
|
2002-12-16 22:33:27 +00:00
|
|
|
int idx;
|
2002-03-24 11:21:41 +00:00
|
|
|
|
|
|
|
pp = bp->bio_to;
|
2002-12-16 22:33:27 +00:00
|
|
|
idx = pp->index;
|
2002-03-24 11:21:41 +00:00
|
|
|
gp = pp->geom;
|
|
|
|
gsp = gp->softc;
|
|
|
|
mp = gsp->softc;
|
|
|
|
if (bp->bio_cmd == BIO_GETATTR) {
|
2002-12-16 22:33:27 +00:00
|
|
|
if (g_handleattr_int(bp, "MBR::type", mp->type[idx]))
|
2002-03-24 11:21:41 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-12-16 22:33:27 +00:00
|
|
|
g_mbrext_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_consumer *cp __unused, struct g_provider *pp)
|
2002-03-24 11:21:41 +00:00
|
|
|
{
|
|
|
|
struct g_mbrext_softc *mp;
|
|
|
|
struct g_slicer *gsp;
|
|
|
|
|
|
|
|
g_slice_dumpconf(sb, indent, gp, cp, pp);
|
|
|
|
gsp = gp->softc;
|
|
|
|
mp = gsp->softc;
|
|
|
|
if (pp != NULL) {
|
2002-11-02 12:01:12 +00:00
|
|
|
if (indent == NULL)
|
|
|
|
sbuf_printf(sb, " ty %d", mp->type[pp->index]);
|
|
|
|
else
|
|
|
|
sbuf_printf(sb, "%s<type>%d</type>\n", indent,
|
|
|
|
mp->type[pp->index]);
|
2002-03-24 11:21:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct g_geom *
|
2002-03-26 22:07:38 +00:00
|
|
|
g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
|
2002-03-24 11:21:41 +00:00
|
|
|
{
|
|
|
|
struct g_geom *gp;
|
|
|
|
struct g_consumer *cp;
|
2002-04-09 15:43:32 +00:00
|
|
|
int error, i, slice;
|
2002-03-24 11:21:41 +00:00
|
|
|
struct g_mbrext_softc *ms;
|
|
|
|
off_t off;
|
|
|
|
u_char *buf;
|
|
|
|
struct dos_partition dp[4];
|
2002-04-09 15:43:32 +00:00
|
|
|
u_int fwsectors, sectorsize;
|
2002-03-24 11:21:41 +00:00
|
|
|
|
|
|
|
g_trace(G_T_TOPOLOGY, "g_mbrext_taste(%s,%s)", mp->name, pp->name);
|
|
|
|
g_topology_assert();
|
2002-03-26 21:40:06 +00:00
|
|
|
if (strcmp(pp->geom->class->name, MBR_CLASS_NAME))
|
2002-03-24 11:21:41 +00:00
|
|
|
return (NULL);
|
2003-02-11 14:09:48 +00:00
|
|
|
gp = g_slice_new(mp, NDOSEXTPART, pp, &cp, &ms, sizeof *ms,
|
|
|
|
g_mbrext_start);
|
2002-03-24 11:21:41 +00:00
|
|
|
if (gp == NULL)
|
|
|
|
return (NULL);
|
|
|
|
g_topology_unlock();
|
|
|
|
gp->dumpconf = g_mbrext_dumpconf;
|
|
|
|
off = 0;
|
|
|
|
slice = 0;
|
2003-04-09 08:56:26 +00:00
|
|
|
do {
|
2002-04-09 15:43:32 +00:00
|
|
|
error = g_getattr("MBR::type", cp, &i);
|
2002-09-08 15:13:33 +00:00
|
|
|
if (error || (i != DOSPTYP_EXT && i != DOSPTYP_EXTLBA))
|
2002-03-24 11:21:41 +00:00
|
|
|
break;
|
2002-04-09 15:43:32 +00:00
|
|
|
error = g_getattr("GEOM::fwsectors", cp, &fwsectors);
|
|
|
|
if (error)
|
|
|
|
fwsectors = 17;
|
2002-10-20 20:28:24 +00:00
|
|
|
sectorsize = cp->provider->sectorsize;
|
2002-09-28 11:57:20 +00:00
|
|
|
if (sectorsize != 512)
|
2002-04-09 15:43:32 +00:00
|
|
|
break;
|
2002-03-24 11:21:41 +00:00
|
|
|
for (;;) {
|
2002-04-09 15:43:32 +00:00
|
|
|
buf = g_read_data(cp, off, sectorsize, &error);
|
2002-03-24 11:21:41 +00:00
|
|
|
if (buf == NULL || error != 0)
|
|
|
|
break;
|
2003-05-02 08:13:03 +00:00
|
|
|
if (buf[0x1fe] != 0x55 && buf[0x1ff] != 0xaa) {
|
|
|
|
g_free(buf);
|
2002-03-24 11:21:41 +00:00
|
|
|
break;
|
2003-05-02 08:13:03 +00:00
|
|
|
}
|
2002-03-24 11:21:41 +00:00
|
|
|
for (i = 0; i < NDOSPART; i++)
|
2003-04-12 08:34:40 +00:00
|
|
|
dos_partition_dec(
|
2002-10-31 22:18:49 +00:00
|
|
|
buf + DOSPARTOFF +
|
|
|
|
i * sizeof(struct dos_partition), dp + i);
|
2002-03-24 11:21:41 +00:00
|
|
|
g_free(buf);
|
2003-04-09 13:52:40 +00:00
|
|
|
if (bootverbose) {
|
|
|
|
printf("MBREXT Slice %d on %s:\n",
|
|
|
|
slice + 5, gp->name);
|
|
|
|
g_mbr_print(0, dp);
|
|
|
|
g_mbr_print(1, dp + 1);
|
|
|
|
}
|
2002-11-04 06:29:05 +00:00
|
|
|
if ((dp[0].dp_flag & 0x7f) == 0 &&
|
|
|
|
dp[0].dp_size != 0 && dp[0].dp_typ != 0) {
|
2002-12-19 12:01:19 +00:00
|
|
|
g_topology_lock();
|
2002-12-16 23:08:48 +00:00
|
|
|
g_slice_config(gp, slice, G_SLICE_CONFIG_SET,
|
2002-03-24 11:21:41 +00:00
|
|
|
(((off_t)dp[0].dp_start) << 9ULL) + off,
|
|
|
|
((off_t)dp[0].dp_size) << 9ULL,
|
2002-10-20 19:18:07 +00:00
|
|
|
sectorsize,
|
2002-03-24 11:21:41 +00:00
|
|
|
"%*.*s%d",
|
|
|
|
strlen(gp->name) - 1,
|
|
|
|
strlen(gp->name) - 1,
|
|
|
|
gp->name,
|
|
|
|
slice + 5);
|
2002-09-27 21:37:11 +00:00
|
|
|
g_topology_unlock();
|
2002-03-24 11:21:41 +00:00
|
|
|
ms->type[slice] = dp[0].dp_typ;
|
|
|
|
slice++;
|
|
|
|
}
|
|
|
|
if (dp[1].dp_flag != 0)
|
|
|
|
break;
|
|
|
|
if (dp[1].dp_typ != DOSPTYP_EXT)
|
|
|
|
break;
|
|
|
|
if (dp[1].dp_size == 0)
|
|
|
|
break;
|
|
|
|
off = ((off_t)dp[1].dp_start) << 9ULL;
|
|
|
|
}
|
|
|
|
break;
|
2003-04-09 08:56:26 +00:00
|
|
|
} while (0);
|
2002-03-24 11:21:41 +00:00
|
|
|
g_topology_lock();
|
2002-12-16 23:08:48 +00:00
|
|
|
g_access_rel(cp, -1, 0, 0);
|
|
|
|
if (LIST_EMPTY(&gp->provider)) {
|
2003-05-02 08:13:03 +00:00
|
|
|
g_slice_spoiled(cp);
|
2002-12-16 23:08:48 +00:00
|
|
|
return (NULL);
|
2002-05-21 20:33:49 +00:00
|
|
|
}
|
2002-12-16 23:08:48 +00:00
|
|
|
return (gp);
|
2002-03-24 11:21:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-03-26 21:40:06 +00:00
|
|
|
static struct g_class g_mbrext_class = {
|
2003-04-03 19:05:03 +00:00
|
|
|
.name = MBREXT_CLASS_NAME,
|
|
|
|
.taste = g_mbrext_taste,
|
2002-03-24 11:21:41 +00:00
|
|
|
};
|
|
|
|
|
2002-03-26 21:40:06 +00:00
|
|
|
DECLARE_GEOM_CLASS(g_mbrext_class, g_mbrext);
|