Add a compat option to the EBR scheme that controls the

naming of the partitions (GEOM_PART_EBR_COMPAT).  When
compatibility is enabled, changes to the partitioning are
disallowed.

Remove the device name aliasing added previously to provide
backward compatibility, but which in practice doesn't give
us anything.

Enable compatibility on amd64 and i386.
This commit is contained in:
Marcel Moolenaar 2009-04-15 22:38:22 +00:00
parent 8b12a7c2a6
commit 6ad9a99f21
7 changed files with 69 additions and 44 deletions

View File

@ -18,4 +18,5 @@ device uart_ns8250
# Default partitioning schemes
options GEOM_PART_BSD
options GEOM_PART_EBR
options GEOM_PART_EBR_COMPAT
options GEOM_PART_MBR

View File

@ -148,6 +148,7 @@ options GEOM_NOP # Test class.
options GEOM_PART_APM # Apple partitioning
options GEOM_PART_BSD # BSD disklabel
options GEOM_PART_EBR # Extended Boot Records
options GEOM_PART_EBR_COMPAT # Backward compatible partition names
options GEOM_PART_GPT # GPT partitioning
options GEOM_PART_MBR # MBR partitioning
options GEOM_PART_PC98 # PC-9800 disk partitioning

View File

@ -93,6 +93,7 @@ GEOM_NOP opt_geom.h
GEOM_PART_APM opt_geom.h
GEOM_PART_BSD opt_geom.h
GEOM_PART_EBR opt_geom.h
GEOM_PART_EBR_COMPAT opt_geom.h
GEOM_PART_GPT opt_geom.h
GEOM_PART_MBR opt_geom.h
GEOM_PART_PC98 opt_geom.h

View File

@ -245,9 +245,9 @@ static void
g_part_new_provider(struct g_geom *gp, struct g_part_table *table,
struct g_part_entry *entry)
{
char buf[32];
struct g_consumer *cp;
struct g_provider *pp;
struct sbuf *sb;
off_t offset;
cp = LIST_FIRST(&gp->consumer);
@ -258,8 +258,11 @@ g_part_new_provider(struct g_geom *gp, struct g_part_table *table,
entry->gpe_offset = offset;
if (entry->gpe_pp == NULL) {
entry->gpe_pp = g_new_providerf(gp, "%s%s", gp->name,
G_PART_NAME(table, entry, buf, sizeof(buf)));
sb = sbuf_new_auto();
G_PART_FULLNAME(table, entry, sb, gp->name);
sbuf_finish(sb);
entry->gpe_pp = g_new_providerf(gp, "%s", sbuf_data(sb));
sbuf_delete(sb);
entry->gpe_pp->private = entry; /* Close the circle. */
}
entry->gpe_pp->index = entry->gpe_index - 1; /* index is 1-based. */
@ -413,7 +416,6 @@ g_part_probe(struct g_geom *gp, struct g_consumer *cp, int depth)
static int
g_part_ctl_add(struct gctl_req *req, struct g_part_parms *gpp)
{
char buf[32];
struct g_geom *gp;
struct g_provider *pp;
struct g_part_entry *delent, *last, *entry;
@ -509,8 +511,8 @@ g_part_ctl_add(struct gctl_req *req, struct g_part_parms *gpp)
/* Provide feedback if so requested. */
if (gpp->gpp_parms & G_PART_PARM_OUTPUT) {
sb = sbuf_new_auto();
sbuf_printf(sb, "%s%s added\n", gp->name,
G_PART_NAME(table, entry, buf, sizeof(buf)));
G_PART_FULLNAME(table, entry, sb, gp->name);
sbuf_cat(sb, " added\n");
sbuf_finish(sb);
gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1);
sbuf_delete(sb);
@ -773,7 +775,6 @@ g_part_ctl_create(struct gctl_req *req, struct g_part_parms *gpp)
static int
g_part_ctl_delete(struct gctl_req *req, struct g_part_parms *gpp)
{
char buf[32];
struct g_geom *gp;
struct g_provider *pp;
struct g_part_entry *entry;
@ -822,8 +823,8 @@ g_part_ctl_delete(struct gctl_req *req, struct g_part_parms *gpp)
/* Provide feedback if so requested. */
if (gpp->gpp_parms & G_PART_PARM_OUTPUT) {
sb = sbuf_new_auto();
sbuf_printf(sb, "%s%s deleted\n", gp->name,
G_PART_NAME(table, entry, buf, sizeof(buf)));
G_PART_FULLNAME(table, entry, sb, gp->name);
sbuf_cat(sb, " deleted\n");
sbuf_finish(sb);
gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1);
sbuf_delete(sb);
@ -889,7 +890,6 @@ g_part_ctl_destroy(struct gctl_req *req, struct g_part_parms *gpp)
static int
g_part_ctl_modify(struct gctl_req *req, struct g_part_parms *gpp)
{
char buf[32];
struct g_geom *gp;
struct g_part_entry *entry;
struct g_part_table *table;
@ -925,8 +925,8 @@ g_part_ctl_modify(struct gctl_req *req, struct g_part_parms *gpp)
/* Provide feedback if so requested. */
if (gpp->gpp_parms & G_PART_PARM_OUTPUT) {
sb = sbuf_new_auto();
sbuf_printf(sb, "%s%s modified\n", gp->name,
G_PART_NAME(table, entry, buf, sizeof(buf)));
G_PART_FULLNAME(table, entry, sb, gp->name);
sbuf_cat(sb, " modified\n");
sbuf_finish(sb);
gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1);
sbuf_delete(sb);
@ -959,7 +959,6 @@ static int
g_part_ctl_setunset(struct gctl_req *req, struct g_part_parms *gpp,
unsigned int set)
{
char buf[32];
struct g_geom *gp;
struct g_part_entry *entry;
struct g_part_table *table;
@ -992,9 +991,9 @@ g_part_ctl_setunset(struct gctl_req *req, struct g_part_parms *gpp,
/* Provide feedback if so requested. */
if (gpp->gpp_parms & G_PART_PARM_OUTPUT) {
sb = sbuf_new_auto();
sbuf_printf(sb, "%s%s has %s %sset\n", gp->name,
G_PART_NAME(table, entry, buf, sizeof(buf)),
gpp->gpp_attrib, (set) ? "" : "un");
G_PART_FULLNAME(table, entry, sb, gp->name);
sbuf_printf(sb, " has %s %sset\n", gpp->gpp_attrib,
(set) ? "" : "un");
sbuf_finish(sb);
gctl_set_param(req, "output", sbuf_data(sb), sbuf_len(sb) + 1);
sbuf_delete(sb);

View File

@ -24,6 +24,8 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "opt_geom.h"
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
@ -54,18 +56,19 @@ struct g_part_ebr_table {
struct g_part_ebr_entry {
struct g_part_entry base;
struct dos_partition ent;
int alias;
};
static int g_part_ebr_add(struct g_part_table *, struct g_part_entry *,
struct g_part_parms *);
static int g_part_ebr_create(struct g_part_table *, struct g_part_parms *);
static int g_part_ebr_destroy(struct g_part_table *, struct g_part_parms *);
static int g_part_ebr_devalias(struct g_part_table *, struct g_part_entry *,
char *, size_t);
static void g_part_ebr_dumpconf(struct g_part_table *, struct g_part_entry *,
struct sbuf *, const char *);
static int g_part_ebr_dumpto(struct g_part_table *, struct g_part_entry *);
#if defined(GEOM_PART_EBR_COMPAT)
static void g_part_ebr_fullname(struct g_part_table *, struct g_part_entry *,
struct sbuf *, const char *);
#endif
static int g_part_ebr_modify(struct g_part_table *, struct g_part_entry *,
struct g_part_parms *);
static const char *g_part_ebr_name(struct g_part_table *, struct g_part_entry *,
@ -84,9 +87,11 @@ static kobj_method_t g_part_ebr_methods[] = {
KOBJMETHOD(g_part_add, g_part_ebr_add),
KOBJMETHOD(g_part_create, g_part_ebr_create),
KOBJMETHOD(g_part_destroy, g_part_ebr_destroy),
KOBJMETHOD(g_part_devalias, g_part_ebr_devalias),
KOBJMETHOD(g_part_dumpconf, g_part_ebr_dumpconf),
KOBJMETHOD(g_part_dumpto, g_part_ebr_dumpto),
#if defined(GEOM_PART_EBR_COMPAT)
KOBJMETHOD(g_part_fullname, g_part_ebr_fullname),
#endif
KOBJMETHOD(g_part_modify, g_part_ebr_modify),
KOBJMETHOD(g_part_name, g_part_ebr_name),
KOBJMETHOD(g_part_precheck, g_part_ebr_precheck),
@ -274,25 +279,6 @@ g_part_ebr_destroy(struct g_part_table *basetable, struct g_part_parms *gpp)
return (0);
}
static int
g_part_ebr_devalias(struct g_part_table *table, struct g_part_entry *baseentry,
char *buf, size_t bufsz)
{
struct g_part_ebr_entry *entry;
size_t len;
entry = (struct g_part_ebr_entry *)baseentry;
if (entry->alias == 0)
return (ENOENT);
len = strlcpy(buf, table->gpt_gp->name, bufsz);
if (len == 0)
return (EINVAL);
snprintf(buf + len - 1, bufsz - len, "%d", entry->alias);
return (0);
}
static void
g_part_ebr_dumpconf(struct g_part_table *table, struct g_part_entry *baseentry,
struct sbuf *sb, const char *indent)
@ -324,6 +310,24 @@ g_part_ebr_dumpto(struct g_part_table *table, struct g_part_entry *baseentry)
return ((entry->ent.dp_typ == DOSPTYP_386BSD) ? 1 : 0);
}
#if defined(GEOM_PART_EBR_COMPAT)
static void
g_part_ebr_fullname(struct g_part_table *table, struct g_part_entry *entry,
struct sbuf *sb, const char *pfx)
{
struct g_part_entry *iter;
u_int idx;
idx = 5;
LIST_FOREACH(iter, &table->gpt_entry, gpe_entry) {
if (iter == entry)
break;
idx++;
}
sbuf_printf(sb, "%.*s%u", strlen(pfx) - 1, pfx, idx);
}
#endif
static int
g_part_ebr_modify(struct g_part_table *basetable,
struct g_part_entry *baseentry, struct g_part_parms *gpp)
@ -352,7 +356,9 @@ static int
g_part_ebr_precheck(struct g_part_table *table, enum g_part_ctl req,
struct g_part_parms *gpp)
{
#if defined(GEOM_PART_EBR_COMPAT)
return (ECANCELED);
#else
/*
* The index is a function of the start of the partition.
* This is not something the user can override, nor is it
@ -361,8 +367,8 @@ g_part_ebr_precheck(struct g_part_table *table, enum g_part_ctl req,
*/
if (req == G_PART_CTL_ADD)
gpp->gpp_index = (gpp->gpp_start / table->gpt_sectors) + 1;
return (0);
#endif
}
static int
@ -444,13 +450,12 @@ g_part_ebr_read(struct g_part_table *basetable, struct g_consumer *cp)
u_char *buf;
off_t ofs, msize;
u_int lba;
int alias, error, index;
int error, index;
pp = cp->provider;
table = (struct g_part_ebr_table *)basetable;
msize = pp->mediasize / pp->sectorsize;
alias = 5;
lba = 0;
while (1) {
ofs = (off_t)lba * pp->sectorsize;
@ -477,7 +482,6 @@ g_part_ebr_read(struct g_part_table *basetable, struct g_consumer *cp)
pp->sectorsize;
entry = (struct g_part_ebr_entry *)baseentry;
entry->ent = ent[0];
entry->alias = alias++;
if (ent[1].dp_typ == 0)
break;

View File

@ -42,6 +42,16 @@ INTERFACE g_part;
# Default implementations of methods.
CODE {
static void
default_fullname(struct g_part_table *table,
struct g_part_entry *entry, struct sbuf *sb, const char *pfx)
{
char buf[32];
sbuf_printf(sb, "%s%s", pfx,
G_PART_NAME(table, entry, buf, sizeof(buf)));
}
static int
default_precheck(struct g_part_table *t __unused,
enum g_part_ctl r __unused, struct g_part_parms *p __unused)
@ -98,6 +108,14 @@ METHOD int dumpto {
struct g_part_entry *entry;
};
# fullname() - write the name of the given partition entry to the sbuf.
METHOD void fullname {
struct g_part_table *table;
struct g_part_entry *entry;
struct sbuf *sb;
const char *pfx;
} DEFAULT default_fullname;
# modify() - scheme specific processing for the modify verb.
METHOD int modify {
struct g_part_table *table;

View File

@ -22,6 +22,7 @@ device uart_ns8250
# Default partitioning schemes
options GEOM_PART_BSD
options GEOM_PART_EBR
options GEOM_PART_EBR_COMPAT
options GEOM_PART_MBR
# enable support for native hardware