return NULL;
}
+int fdisk_context_next_label(struct fdisk_context *cxt, struct fdisk_label **lb)
+{
+ size_t i;
+ struct fdisk_label *res = NULL;
+
+ if (!lb || !cxt)
+ return -EINVAL;
+
+ if (!*lb)
+ res = cxt->labels[0];
+ else {
+ for (i = 1; i < cxt->nlabels; i++) {
+ if (*lb == cxt->labels[i - 1]) {
+ res = cxt->labels[i];
+ break;
+ }
+ }
+ }
+
+ *lb = res;
+ return res ? 0 : 1;
+}
+
int __fdisk_context_switch_label(struct fdisk_context *cxt,
struct fdisk_label *lb)
{
- if (!lb)
+ if (!lb || !cxt)
+ return -EINVAL;
+ if (lb->disabled) {
+ DBG(LABEL, dbgprint("*** attempt to switch to disabled label %s -- ignore!", lb->name));
return -EINVAL;
+ }
cxt->label = lb;
DBG(LABEL, dbgprint("--> switching context to %s!", lb->name));
return 0;
int flags; /* FDISK_LABEL_FL_* flags */
- unsigned int changed:1; /* label has been modified */
+ unsigned int changed:1, /* label has been modified */
+ disabled:1; /* this driver is disabled at all */
const struct fdisk_label_operations *op;
};
if (!lb->op->probe)
continue;
-
+ if (lb->disabled) {
+ DBG(LABEL, dbgprint("%s disabled -- ignore", lb->name));
+ continue;
+ }
DBG(LABEL, dbgprint("probing for %s", lb->name));
cxt->label = lb;
}
lb = fdisk_context_get_label(cxt, name);
- if (!lb)
+ if (!lb || lb->disabled)
return -EINVAL;
if (!lb->op->create)
return -ENOSYS;
assert(lb);
return lb ? lb->changed : 0;
}
+
+void fdisk_label_set_disabled(struct fdisk_label *lb, int disabled)
+{
+ assert(lb);
+
+ DBG(LABEL, dbgprint("%s label %s",
+ lb->name,
+ disabled ? "DISABLED" : "ENABLED"));
+ lb->disabled = disabled ? 1 : 0;
+}
+
+int fdisk_label_is_disabled(struct fdisk_label *lb)
+{
+ assert(lb);
+ return lb ? lb->disabled : 0;
+}
extern struct fdisk_label *fdisk_context_get_label(struct fdisk_context *cxt,
const char *name);
+extern int fdisk_context_next_label(struct fdisk_context *cxt, struct fdisk_label **lb);
extern int fdisk_context_switch_label(struct fdisk_context *cxt,
const char *name);
extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed);
extern int fdisk_label_is_changed(struct fdisk_label *lb);
+extern void fdisk_label_set_disabled(struct fdisk_label *lb, int disabled);
+extern int fdisk_label_is_disabled(struct fdisk_label *lb);
+
extern int fdisk_partition_get_status(struct fdisk_context *cxt, size_t partnum, int *status);
extern int fdisk_partition_is_used(struct fdisk_context *cxt, size_t partnum);
extern int fdisk_partition_toggle_flag(struct fdisk_context *cxt, size_t partnum, unsigned long flag);