void print_menu(struct fdisk_context *cxt, enum menutype menu)
{
size_t i;
+ int id;
puts(_("Command action"));
+ id = cxt && cxt->label ? cxt->label->id : FDISK_DISKLABEL_ANY;
+
for (i = 0; i < ARRAY_SIZE(menulist); i++)
- if (menulist[i].label[menu] & cxt->disklabel)
+ if (menulist[i].label[menu] & id)
printf(" %c %s\n", menulist[i].command, menulist[i].description);
}
"disklabel mode.\n"),
cxt->dev_path);
bsd_command_prompt(cxt);
+
/* If we return we may want to make an empty DOS label? */
- cxt->disklabel = FDISK_DISKLABEL_DOS;
+ fdisk_context_switch_label(cxt, "dos");
}
while (1) {
unknown_command(c);
break;
case 'b':
+ /*
+ * TODO: create child context for nexted partition tables
+ */
if (fdisk_is_disklabel(cxt, SGI))
sgi_set_bootfile(cxt);
else if (fdisk_is_disklabel(cxt, DOS)) {
- cxt->disklabel = FDISK_DISKLABEL_OSF;
+ fdisk_context_switch_label(cxt, "bsd");
bsd_command_prompt(cxt);
- cxt->disklabel = FDISK_DISKLABEL_DOS;
+ fdisk_context_switch_label(cxt, "dos");
} else
unknown_command(c);
break;
return 0;
}
other_endian = (aixlabel->magic == AIX_LABEL_MAGIC_SWAPPED);
- cxt->disklabel = FDISK_DISKLABEL_AIX;
partitions= 1016;
volumes = 15;
aix_info();
/* initialize generic part of the driver */
lb = (struct fdisk_label *) aix;
lb->name = "aix";
+ lb->id = FDISK_DISKLABEL_AIX;
lb->op = &aix_operations;
return lb;
/* initialize generic part of the driver */
lb = (struct fdisk_label *) bsd;
lb->name = "bsd";
+ lb->id = FDISK_DISKLABEL_OSF;
lb->op = &bsd_operations;
lb->parttypes = xbsd_fstypes;
lb->nparttypes = ARRAY_SIZE(xbsd_fstypes);
{
int i;
- cxt->disklabel = FDISK_DISKLABEL_DOS;
partitions = 4;
ext_index = 0;
extended_offset = 0;
/* initialize generic part of the driver */
lb = (struct fdisk_label *) dos;
lb->name = "dos";
+ lb->id = FDISK_DISKLABEL_DOS;
lb->op = &dos_operations;
lb->parttypes = dos_parttypes;
lb->nparttypes = ARRAY_SIZE(dos_parttypes);
IS_MAC:
other_endian = (maclabel->magic == MAC_LABEL_MAGIC_SWAPPED); // =?
- cxt->disklabel = FDISK_DISKLABEL_MAC;
partitions= 1016; // =?
volumes = 15; // =?
mac_info();
/* initialize generic part of the driver */
lb = (struct fdisk_label *) mac;
lb->name = "mac";
+ lb->id = FDISK_DISKLABEL_MAC;
lb->op = &mac_operations;
return lb;
fprintf(stderr,
_("Detected sgi disklabel with wrong checksum.\n"));
}
- cxt->disklabel = FDISK_DISKLABEL_SGI;
partitions= 16;
volumes = 15;
return 1;
sgilabel->devparam.xylogics_writecont = SSWAP16(0);
memset(&(sgilabel->directory), 0, sizeof(struct volume_directory)*15);
memset(&(sgilabel->partitions), 0, sizeof(struct sgi_partition)*16);
- cxt->disklabel = FDISK_DISKLABEL_SGI;
partitions = 16;
volumes = 15;
sgi_set_entire(cxt);
/* initialize generic part of the driver */
lb = (struct fdisk_label *) sgi;
lb->name = "sgi";
+ lb->id = FDISK_DISKLABEL_SGI;
lb->op = &sgi_operations;
lb->parttypes = sgi_parttypes;
lb->nparttypes = ARRAY_SIZE(sgi_parttypes);
print_partition_size(cxt, i + 1, start, stop, sysid);
}
-static void init(struct fdisk_context *cxt)
+static void init(struct fdisk_context *cxt __attribute__((__unused__)))
{
- cxt->disklabel = FDISK_DISKLABEL_SUN;
partitions = SUN_NUM_PARTITIONS;
}
/* initialize generic part of the driver */
lb = (struct fdisk_label *) sun;
lb->name = "sun";
+ lb->id = FDISK_DISKLABEL_SUN;
lb->op = &sun_operations;
lb->parttypes = sun_parttypes;
lb->nparttypes = ARRAY_SIZE(sun_parttypes);
/*
* Initialize fdisk-specific variables - call once probing passes!
*/
-static void gpt_init(struct fdisk_context *cxt)
+static void gpt_init(struct fdisk_context *cxt __attribute__((__unused__)))
{
- cxt->disklabel = FDISK_DISKLABEL_GPT;
partitions = le32_to_cpu(pheader->npartition_entries);
}
/* initialize generic part of the driver */
lb = (struct fdisk_label *) gpt;
lb->name = "gpt";
+ lb->id = FDISK_DISKLABEL_GPT;
lb->op = &gpt_operations;
lb->parttypes = gpt_parttypes;
lb->nparttypes = ARRAY_SIZE(gpt_parttypes);
return NULL;
}
+int __fdisk_context_switch_label(struct fdisk_context *cxt,
+ struct fdisk_label *lb)
+{
+ if (!lb)
+ return -EINVAL;
+ cxt->label = lb;
+ DBG(LABEL, dbgprint("--> switching context to %s!", lb->name));
+ return 0;
+}
+
+int fdisk_context_switch_label(struct fdisk_context *cxt, const char *name)
+{
+ return __fdisk_context_switch_label(cxt,
+ fdisk_context_get_label(cxt, name));
+}
+
+
static void reset_context(struct fdisk_context *cxt)
{
size_t nlbs, i;
struct fdisk_label {
/* persistent information */
const char *name;
+ enum fdisk_labeltype id; /* FDISK_DISKLABEL_* */
struct fdisk_parttype *parttypes;
size_t nparttypes; /* number of items in parttypes[] */
unsigned long sector_size; /* logical size */
unsigned long alignment_offset;
- enum fdisk_labeltype disklabel; /* current disklabel */
-
/* alignment */
unsigned long grain; /* alignment unit */
sector_t first_lba; /* recommended begin of the first partition */
* FIXME: use any enum rather than hardcoded number */
};
-
+/* context.c */
+extern int __fdisk_context_switch_label(struct fdisk_context *cxt,
+ struct fdisk_label *lb);
/* alignment.c */
extern sector_t fdisk_topology_get_first_lba(struct fdisk_context *cxt);
{
size_t i;
- cxt->disklabel = FDISK_DISKLABEL_ANY;
cxt->label = NULL;
for (i = 0; i < cxt->nlabels; i++) {
continue;
}
- cxt->label = lb;
- DBG(LABEL, dbgprint("detected a %s label", lb->name));
+ __fdisk_context_switch_label(cxt, lb);
return 0;
}
*/
int fdisk_dev_has_disklabel(struct fdisk_context *cxt)
{
- return cxt && cxt->disklabel != FDISK_DISKLABEL_ANY;
+ return cxt && cxt->label;
}
/**
*/
int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l)
{
- return cxt && cxt->disklabel == l;
+ return cxt && cxt->label && cxt->label->id == l;
}
/**
extern struct fdisk_label *fdisk_context_get_label(struct fdisk_context *cxt,
const char *name);
+extern int fdisk_context_switch_label(struct fdisk_context *cxt,
+ const char *name);
+
/* parttype.c */
extern struct fdisk_parttype *fdisk_get_parttype_from_code(struct fdisk_context *cxt,
unsigned int code);