]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add API to disable specified label
authorKarel Zak <kzak@redhat.com>
Wed, 9 Oct 2013 14:02:33 +0000 (16:02 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 9 Oct 2013 14:02:33 +0000 (16:02 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/context.c
libfdisk/src/fdiskP.h
libfdisk/src/label.c
libfdisk/src/libfdisk.h

index c5d2329cf637663a2873b34c561fbeed80a7abe7..9106e29b3ec088fe14be2980dcffd3bc34a18802 100644 (file)
@@ -102,11 +102,38 @@ struct fdisk_label *fdisk_context_get_label(struct fdisk_context *cxt, const cha
        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;
index b03586fae21d3a6aeacdf5df142723d1bdab0c73..feaab3d0aca5b20c585875c495eeb1c5c5f850a6 100644 (file)
@@ -202,7 +202,8 @@ struct fdisk_label {
 
        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;
 };
index aba2790cc870184902dbee64fa2802f20fb96bbd..7f9c7d0e33949261f3ac8a37afa7eef05dd9cb9f 100644 (file)
@@ -17,7 +17,10 @@ int fdisk_probe_labels(struct fdisk_context *cxt)
 
                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;
@@ -230,7 +233,7 @@ int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name)
        }
 
        lb = fdisk_context_get_label(cxt, name);
-       if (!lb)
+       if (!lb || lb->disabled)
                return -EINVAL;
        if (!lb->op->create)
                return -ENOSYS;
@@ -436,3 +439,19 @@ int fdisk_label_is_changed(struct fdisk_label *lb)
        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;
+}
index 7ad3560679cd5de85c047555a694dd42a313d0b1..cd856d70d792961c9acd13fca66bb9f6428d7cf5 100644 (file)
@@ -87,6 +87,7 @@ extern int fdisk_context_deassign_device(struct fdisk_context *cxt);
 
 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);
@@ -142,6 +143,9 @@ extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,
 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);