/*
* 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);
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
/* detect labels and apply labes specific stuff (e.g geomery)
* to the context */
- __probe_labels(cxt);
+ fdisk_probe_labels(cxt);
fdisk_reset_alignment(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 */
#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
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);
+}