From 3cf4280261e4479a41062ad7f2038dafb3594041 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 16 Dec 2002 23:08:48 +0000 Subject: Get rid of g_slice_addslice() and use g_slice_config() instead. Tested with: i386 + src/tools/regression/geom --- sys/geom/geom_gpt.c | 15 ++--- sys/geom/geom_mbr.c | 153 +++++++++++++++++++++++++---------------------- sys/geom/geom_pc98.c | 15 ++--- sys/geom/geom_slice.c | 32 ---------- sys/geom/geom_slice.h | 1 - sys/geom/geom_sunlabel.c | 15 +++-- 6 files changed, 101 insertions(+), 130 deletions(-) (limited to 'sys') diff --git a/sys/geom/geom_gpt.c b/sys/geom/geom_gpt.c index 5d88f5e..14c8483 100644 --- a/sys/geom/geom_gpt.c +++ b/sys/geom/geom_gpt.c @@ -227,7 +227,7 @@ g_gpt_taste(struct g_class *mp, struct g_provider *pp, int insist) ps = (!memcmp(&ent->ent_type, &freebsd, sizeof(freebsd))) ? 's' : 'p'; g_topology_lock(); - (void)g_slice_addslice(gp, i, + (void)g_slice_config(gp, i, G_SLICE_CONFIG_SET, ent->ent_lba_start * secsz, (1 + ent->ent_lba_end - ent->ent_lba_start) * secsz, secsz, @@ -244,15 +244,12 @@ g_gpt_taste(struct g_class *mp, struct g_provider *pp, int insist) g_free(mbr); g_topology_lock(); - error = g_access_rel(cp, -1, 0, 0); - - if (npart > 0) { - LIST_FOREACH(pp, &gp->provider, provider) - g_error_provider(pp, 0); - return (gp); + g_access_rel(cp, -1, 0, 0); + if (LIST_EMPTY(&gp->provider)) { + g_std_spoiled(cp); + return (NULL); } - g_std_spoiled(cp); - return (NULL); + return (gp); } static struct g_class g_gpt_class = { diff --git a/sys/geom/geom_mbr.c b/sys/geom/geom_mbr.c index f18d0d8..8c21fa6 100644 --- a/sys/geom/geom_mbr.c +++ b/sys/geom/geom_mbr.c @@ -33,6 +33,7 @@ */ #include +#include #ifndef _KERNEL #include #include @@ -57,6 +58,18 @@ #define MBR_CLASS_NAME "MBR" #define MBREXT_CLASS_NAME "MBREXT" +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, }, +}; +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, }, +}; static void g_dec_dos_partition(u_char *ptr, struct dos_partition *d) { @@ -97,6 +110,62 @@ struct g_mbr_softc { }; static int +g_mbr_modify(struct g_geom *gp, struct g_mbr_softc *ms, struct dos_partition *dp) +{ + int i, error; + off_t l[NDOSPART]; + + g_topology_assert(); + + 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. + */ + if (dp[i].dp_typ == 0xee) + 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 + l[i] = (off_t)dp[i].dp_size << 9ULL; + error = g_slice_config(gp, i, G_SLICE_CONFIG_CHECK, + (off_t)dp[i].dp_start << 9ULL, l[i], 512, + "%ss%d", gp->name, 1 + i); + 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, + (off_t)dp[i].dp_start << 9ULL, l[i], 512, + "%ss%d", gp->name, 1 + i); + } + return (0); +} + +static int g_mbr_start(struct bio *bp) { struct g_provider *pp; @@ -139,18 +208,6 @@ g_mbr_dumpconf(struct sbuf *sb, const char *indent, struct g_geom *gp, struct g_ } -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, }, -}; -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, }, -}; static void g_mbr_print(int i, struct dos_partition *dp) @@ -168,8 +225,7 @@ g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist) { struct g_geom *gp; struct g_consumer *cp; - struct g_provider *pp2; - int error, i, npart; + int error, i; struct dos_partition dp[NDOSPART]; struct g_mbr_softc *ms; struct g_slicer *gsp; @@ -184,7 +240,6 @@ g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist) gsp = gp->softc; g_topology_unlock(); gp->dumpconf = g_mbr_dumpconf; - npart = 0; while (1) { /* a trick to allow us to use break */ if (gp->rank != 2 && insist == 0) break; @@ -219,55 +274,18 @@ g_mbr_taste(struct g_class *mp, struct g_provider *pp, int insist) printf("Ignoring known bogus MBR #1\n"); break; } - npart = 0; - 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. - */ - if (dp[i].dp_typ == 0xee) - continue; - if (dp[i].dp_flag != 0 && dp[i].dp_flag != 0x80) - continue; - if (dp[i].dp_typ == 0) - continue; - if (dp[i].dp_size == 0) - continue; - if (bootverbose) { - printf("MBR Slice %d on %s:\n", i + 1, gp->name); - g_mbr_print(i, dp + i); - } - npart++; - ms->type[i] = dp[i].dp_typ; - g_topology_lock(); - pp2 = g_slice_addslice(gp, i, - (off_t)dp[i].dp_start << 9ULL, - (off_t)dp[i].dp_size << 9ULL, - sectorsize, - "%ss%d", gp->name, i + 1); - g_topology_unlock(); - } + g_mbr_modify(gp, ms, dp); break; } g_topology_lock(); - error = g_access_rel(cp, -1, 0, 0); - if (npart > 0) { - LIST_FOREACH(pp, &gp->provider, provider) - g_error_provider(pp, 0); - return (gp); + g_access_rel(cp, -1, 0, 0); + if (LIST_EMPTY(&gp->provider)) { + g_std_spoiled(cp); + return (NULL); } - g_std_spoiled(cp); - return (NULL); + return (gp); } - static struct g_class g_mbr_class = { MBR_CLASS_NAME, g_mbr_taste, @@ -326,7 +344,6 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) { struct g_geom *gp; struct g_consumer *cp; - struct g_provider *pp2; int error, i, slice; struct g_mbrext_softc *ms; off_t off; @@ -374,8 +391,7 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) g_mbr_print(1, dp + 1); if ((dp[0].dp_flag & 0x7f) == 0 && dp[0].dp_size != 0 && dp[0].dp_typ != 0) { - g_topology_lock(); - pp2 = g_slice_addslice(gp, slice, + g_slice_config(gp, slice, G_SLICE_CONFIG_SET, (((off_t)dp[0].dp_start) << 9ULL) + off, ((off_t)dp[0].dp_size) << 9ULL, sectorsize, @@ -387,7 +403,6 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) g_topology_unlock(); ms->type[slice] = dp[0].dp_typ; slice++; - g_error_provider(pp2, 0); } if (dp[1].dp_flag != 0) break; @@ -400,16 +415,12 @@ g_mbrext_taste(struct g_class *mp, struct g_provider *pp, int insist __unused) break; } g_topology_lock(); - error = g_access_rel(cp, -1, 0, 0); - if (slice > 0) { - /* XXX: add magic spaces */ - return (gp); + g_access_rel(cp, -1, 0, 0); + if (LIST_EMPTY(&gp->provider)) { + g_std_spoiled(cp); + return (NULL); } - - g_topology_assert(); - g_std_spoiled(cp); - g_topology_assert(); - return (NULL); + return (gp); } diff --git a/sys/geom/geom_pc98.c b/sys/geom/geom_pc98.c index 8b3873f..f55b3a3 100644 --- a/sys/geom/geom_pc98.c +++ b/sys/geom/geom_pc98.c @@ -152,7 +152,6 @@ g_pc98_taste(struct g_class *mp, struct g_provider *pp, int flags) { struct g_geom *gp; struct g_consumer *cp; - struct g_provider *pp2; int error, i, npart; struct g_pc98_softc *ms; struct g_slicer *gsp; @@ -237,7 +236,7 @@ g_pc98_taste(struct g_class *mp, struct g_provider *pp, int flags) ms->type[i] = (ms->dp[i].dp_sid << 8) | ms->dp[i].dp_mid; g_topology_lock(); - pp2 = g_slice_addslice(gp, i, + g_slice_config(gp, i, G_SLICE_CONFIG_SET, ms->dp[i].dp_scyl * spercyl, (ms->dp[i].dp_ecyl - ms->dp[i].dp_scyl + 1) * spercyl, @@ -248,14 +247,12 @@ g_pc98_taste(struct g_class *mp, struct g_provider *pp, int flags) break; } g_topology_lock(); - error = g_access_rel(cp, -1, 0, 0); - if (npart > 0) { - LIST_FOREACH(pp, &gp->provider, provider) - g_error_provider(pp, 0); - return (gp); + g_access_rel(cp, -1, 0, 0); + if (LIST_EMPTY(&gp->provider)) { + g_std_spoiled(cp); + return (NULL); } - g_std_spoiled(cp); - return (NULL); + return (gp); } static struct g_class g_pc98_class = { diff --git a/sys/geom/geom_slice.c b/sys/geom/geom_slice.c index cbe3749..51d3ffa 100644 --- a/sys/geom/geom_slice.c +++ b/sys/geom/geom_slice.c @@ -384,38 +384,6 @@ g_slice_conf_hot(struct g_geom *gp, u_int idx, off_t offset, off_t length) return (0); } -struct g_provider * -g_slice_addslice(struct g_geom *gp, int idx, off_t offset, off_t length, u_int sectorsize, const char *fmt, ...) -{ - struct g_provider *pp; - struct g_slicer *gsp; - va_list ap; - struct sbuf *sb; - - g_trace(G_T_TOPOLOGY, "g_slice_addslice()"); - g_topology_assert(); - gsp = gp->softc; - va_start(ap, fmt); - sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); - sbuf_vprintf(sb, fmt, ap); - sbuf_finish(sb); - pp = g_new_providerf(gp, sbuf_data(sb)); - - pp->index = idx; - gsp->slices[idx].length = length; - gsp->slices[idx].offset = offset; - gsp->slices[idx].provider = pp; - gsp->slices[idx].sectorsize = sectorsize; - pp->mediasize = gsp->slices[idx].length; - pp->sectorsize = gsp->slices[idx].sectorsize; - sbuf_delete(sb); - if (bootverbose) - printf("GEOM: Add %s, start %jd length %jd end %jd\n", - pp->name, (intmax_t)offset, (intmax_t)length, - (intmax_t)(offset + length - 1)); - return(pp); -} - struct g_geom * g_slice_new(struct g_class *mp, u_int slices, struct g_provider *pp, struct g_consumer **cpp, void *extrap, int extra, g_slice_start_t *start) { diff --git a/sys/geom/geom_slice.h b/sys/geom/geom_slice.h index 6ca64a9..cc014d4 100644 --- a/sys/geom/geom_slice.h +++ b/sys/geom/geom_slice.h @@ -60,7 +60,6 @@ struct g_slicer { }; g_dumpconf_t g_slice_dumpconf; -struct g_provider * g_slice_addslice(struct g_geom *gp, int idx, off_t offset, off_t length, u_int sectorsize, const char *fmt, ...); int g_slice_config(struct g_geom *gp, u_int idx, int how, off_t offset, off_t length, u_int sectorsize, const char *fmt, ...); #define G_SLICE_CONFIG_CHECK 0 #define G_SLICE_CONFIG_SET 1 diff --git a/sys/geom/geom_sunlabel.c b/sys/geom/geom_sunlabel.c index 576a35b0..7d1ef3a 100644 --- a/sys/geom/geom_sunlabel.c +++ b/sys/geom/geom_sunlabel.c @@ -97,7 +97,6 @@ g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags) { struct g_geom *gp; struct g_consumer *cp; - struct g_provider *pp2; int error, i, npart; u_char *buf; struct g_sunlabel_softc *ms; @@ -174,22 +173,22 @@ g_sunlabel_taste(struct g_class *mp, struct g_provider *pp, int flags) continue; npart++; g_topology_lock(); - pp2 = g_slice_addslice(gp, i, + g_slice_config(gp, i, G_SLICE_CONFIG_SET, ((off_t)v * csize) << 9ULL, ((off_t)u) << 9ULL, sectorsize, "%s%c", pp->name, 'a' + i); g_topology_unlock(); - g_error_provider(pp2, 0); } break; } g_topology_lock(); - error = g_access_rel(cp, -1, 0, 0); - if (npart > 0) - return (gp); - g_std_spoiled(cp); - return (NULL); + g_access_rel(cp, -1, 0, 0); + if (LIST_EMPTY(&gp->provider)) { + g_std_spoiled(cp); + return (NULL); + } + return (gp); } static struct g_class g_sunlabel_class = { -- cgit v1.1