]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add probing function
authorKarel Zak <kzak@redhat.com>
Thu, 6 Dec 2012 14:13:23 +0000 (15:13 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Mar 2013 10:20:41 +0000 (11:20 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.h
fdisks/utils.c
libfdisk/src/fdiskP.h
libfdisk/src/label.c

index 91855a66aac4a486dd636bed25d4b0e5049d040c..c8d5aab91453ab8f9f8d6fdd4bf1b01123daf04f 100644 (file)
@@ -63,17 +63,8 @@ enum failure {
 /*
  * labels
  */
-extern const struct fdisk_label aix_label;
-extern const struct fdisk_label dos_label;
-extern const struct fdisk_label bsd_label;
-extern const struct fdisk_label mac_label;
-extern const struct fdisk_label sun_label;
-extern const struct fdisk_label sgi_label;
-extern const struct fdisk_label gpt_label;
-
 extern struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int readonly);
 extern void fdisk_free_context(struct fdisk_context *cxt);
-extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name);
 extern struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum);
 extern int fdisk_set_partition_type(struct fdisk_context *cxt, int partnum,
                             struct fdisk_parttype *t);
index 5f4aaccb3f601142117ff0ae1e8f7ef75e481282..3a6332f2ea1105943768bca5ff51c0947852dcb9 100644 (file)
 
 int fdisk_debug_mask;
 
-/*
- * Label probing functions.
- */
-static const struct fdisk_label *labels[] =
-{
-       &gpt_label,
-       &dos_label,
-       &sun_label,
-       &sgi_label,
-       &aix_label,
-       &bsd_label,
-       &mac_label,
-};
-
-
-static int __probe_labels(struct fdisk_context *cxt)
-{
-       size_t i;
-
-       cxt->disklabel = FDISK_DISKLABEL_ANY;
-
-       for (i = 0; i < ARRAY_SIZE(labels); i++) {
-               if (!labels[i]->probe || labels[i]->probe(cxt) != 1)
-                       continue;
-
-               cxt->label = labels[i];
-
-               DBG(LABEL, dbgprint("detected a %s label", cxt->label->name));
-               return 0;
-       }
-
-       return 1; /* not found */
-}
-
-/**
- * fdisk_create_disklabel:
- * @cxt: fdisk context
- * @name: label name
- *
- * Creates a new disk label of type @name. If @name is NULL, then it
- * will create a default system label type, either SUN or DOS.
- *
- * Returns 0 on success, otherwise, a corresponding error.
- */
-int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name)
-{
-       if (!cxt)
-               return -EINVAL;
-
-       cxt->label = NULL;
-
-       if (!name) { /* use default label creation */
-#ifdef __sparc__
-               cxt->label = &sun_label;
-#else
-               cxt->label = &dos_label;
-#endif
-       } else {
-               size_t i;
-
-               for (i = 0; i < ARRAY_SIZE(labels); i++) {
-                       if (strcmp(name, labels[i]->name) != 0)
-                               continue;
-
-                       cxt->label = labels[i];
-                       DBG(LABEL, dbgprint("changing to %s label\n", cxt->label->name));
-                       break;
-               }
-       }
-
-       if (!cxt->label)
-               return -EINVAL;
-       if (!cxt->label->create)
-               return -ENOSYS;
-
-       fdisk_reset_alignment(cxt);
-
-       return cxt->label->create(cxt);
-}
-
 /**
  * fdisk_new_context:
  * @fname: path to the device to be handled
@@ -156,7 +76,7 @@ struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int rea
 
        /* detect labels and apply labes specific stuff (e.g geomery)
         * to the context */
-       __probe_labels(cxt);
+       fdisk_probe_labels(cxt);
 
        fdisk_reset_alignment(cxt);
 
index e9c21ca898cbd8c12fea96a09655e18fab12a199..eac127ee6ce7693f2a5e1b28655488a538619cad 100644 (file)
@@ -204,4 +204,7 @@ extern int fdisk_discover_topology(struct fdisk_context *cxt);
 extern void fdisk_zeroize_firstsector(struct fdisk_context *cxt);
 extern int fdisk_read_firstsector(struct fdisk_context *cxt);
 
+/* label.c */
+extern int fdisk_probe_labels(struct fdisk_context *cxt);
+
 #endif /* _LIBFDISK_PRIVATE_H */
index 86c30990f192a4f7d18c7d013a7a489d3a4b9283..fa7218c0f8587f1026a6c434721a3c2248bf3273 100644 (file)
@@ -1,6 +1,51 @@
 
 #include "fdiskP.h"
 
+/*
+ * Label probing functions.
+ */
+extern const struct fdisk_label aix_label;
+extern const struct fdisk_label dos_label;
+extern const struct fdisk_label bsd_label;
+extern const struct fdisk_label mac_label;
+extern const struct fdisk_label sun_label;
+extern const struct fdisk_label sgi_label;
+extern const struct fdisk_label gpt_label;
+
+static const struct fdisk_label *labels[] =
+{
+       &gpt_label,
+       &dos_label,
+       &sun_label,
+       &sgi_label,
+       &aix_label,
+       &bsd_label,
+       &mac_label,
+};
+
+/*
+ * Don't use this function derectly, use fdisk_new_context_from_filename()
+ */
+int fdisk_probe_labels(struct fdisk_context *cxt)
+{
+       size_t i;
+
+       cxt->disklabel = FDISK_DISKLABEL_ANY;
+
+       for (i = 0; i < ARRAY_SIZE(labels); i++) {
+               if (!labels[i]->probe || labels[i]->probe(cxt) != 1)
+                       continue;
+
+               cxt->label = labels[i];
+
+               DBG(LABEL, dbgprint("detected a %s label", cxt->label->name));
+               return 0;
+       }
+
+       return 1; /* not found */
+}
+
+
 /**
  * fdisk_dev_has_disklabel:
  * @cxt: fdisk context
@@ -103,3 +148,49 @@ int fdisk_delete_partition(struct fdisk_context *cxt, int partnum)
                                cxt->label->name, partnum));
        return cxt->label->part_delete(cxt, partnum);
 }
+
+/**
+ * fdisk_create_disklabel:
+ * @cxt: fdisk context
+ * @name: label name
+ *
+ * Creates a new disk label of type @name. If @name is NULL, then it
+ * will create a default system label type, either SUN or DOS.
+ *
+ * Returns 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name)
+{
+       if (!cxt)
+               return -EINVAL;
+
+       cxt->label = NULL;
+
+       if (!name) { /* use default label creation */
+#ifdef __sparc__
+               cxt->label = &sun_label;
+#else
+               cxt->label = &dos_label;
+#endif
+       } else {
+               size_t i;
+
+               for (i = 0; i < ARRAY_SIZE(labels); i++) {
+                       if (strcmp(name, labels[i]->name) != 0)
+                               continue;
+
+                       cxt->label = labels[i];
+                       DBG(LABEL, dbgprint("changing to %s label\n", cxt->label->name));
+                       break;
+               }
+       }
+
+       if (!cxt->label)
+               return -EINVAL;
+       if (!cxt->label->create)
+               return -ENOSYS;
+
+       fdisk_reset_alignment(cxt);
+
+       return cxt->label->create(cxt);
+}