]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add generic label code
authorKarel Zak <kzak@redhat.com>
Wed, 5 Dec 2012 14:07:19 +0000 (15:07 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Mar 2013 10:20:40 +0000 (11:20 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk.h
fdisks/utils.c
libfdisk/src/Makemodule.am
libfdisk/src/fdiskP.h
libfdisk/src/label.c [new file with mode: 0644]
libfdisk/src/libfdisk.h

index 4ea9b3b9c25643bc8d05a958097dbdfc265986bf..8afa7e9d19bb68843c8ecdb3696c16505336da11 100644 (file)
@@ -73,8 +73,6 @@ extern const struct fdisk_label gpt_label;
 
 extern struct fdisk_context *fdisk_new_context_from_filename(const char *fname, int readonly);
 extern int fdisk_dev_has_topology(struct fdisk_context *cxt);
-extern int fdisk_dev_has_disklabel(struct fdisk_context *cxt);
-extern int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l);
 extern int fdisk_dev_sectsz_is_default(struct fdisk_context *cxt);
 extern void fdisk_free_context(struct fdisk_context *cxt);
 extern void fdisk_zeroize_firstsector(struct fdisk_context *cxt);
@@ -82,10 +80,6 @@ extern int fdisk_context_force_sector_size(struct fdisk_context *cxt, sector_t s
 extern int fdisk_context_set_user_geometry(struct fdisk_context *cxt,
                            unsigned int cylinders, unsigned int heads,
                            unsigned int sectors);
-extern int fdisk_delete_partition(struct fdisk_context *cxt, int partnum);
-extern int fdisk_add_partition(struct fdisk_context *cxt, int partnum, struct fdisk_parttype *t);
-extern int fdisk_write_disklabel(struct fdisk_context *cxt);
-extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
 extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name);
 extern int fdisk_reset_alignment(struct fdisk_context *cxt);
 extern struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum);
index 9588311fc992dc30cda1522a532ca755a5bf903f..db36290f50f01f8533c30e1bedafc522cca7da1a 100644 (file)
@@ -49,85 +49,6 @@ static const struct fdisk_label *labels[] =
        &mac_label,
 };
 
-/**
- * fdisk_write_disklabel:
- * @cxt: fdisk context
- *
- * Write in-memory changes to disk
- *
- * Returns 0 on success, otherwise, a corresponding error.
- */
-int fdisk_write_disklabel(struct fdisk_context *cxt)
-{
-       if (!cxt || !cxt->label)
-               return -EINVAL;
-       if (!cxt->label->write)
-               return -ENOSYS;
-
-       return cxt->label->write(cxt);
-}
-
-/**
- * fdisk_verify_disklabel:
- * @cxt: fdisk context
- *
- * Verifies the partition table.
- *
- * Returns 0.
- */
-int fdisk_verify_disklabel(struct fdisk_context *cxt)
-{
-       if (!cxt || !cxt->label)
-               return -EINVAL;
-       if (!cxt->label->verify)
-               return -ENOSYS;
-
-       return cxt->label->verify(cxt);
-}
-
-/**
- * fdisk_add_partition:
- * @cxt: fdisk context
- * @partnum: partition number to create
- * @t: partition type to create or NULL for label-specific default
- *
- * Creates a new partition, with number @partnum and type @parttype.
- *
- * Returns 0.
- */
-int fdisk_add_partition(struct fdisk_context *cxt, int partnum,
-                       struct fdisk_parttype *t)
-{
-       if (!cxt || !cxt->label)
-               return -EINVAL;
-       if (!cxt->label->part_add)
-               return -ENOSYS;
-
-       DBG(LABEL, dbgprint("adding new partition number %d", partnum));
-       cxt->label->part_add(cxt, partnum, t);
-       return 0;
-}
-
-/**
- * fdisk_delete_partition:
- * @cxt: fdisk context
- * @partnum: partition number to delete
- *
- * Deletes a @partnum partition.
- *
- * Returns 0 on success, otherwise, a corresponding error.
- */
-int fdisk_delete_partition(struct fdisk_context *cxt, int partnum)
-{
-       if (!cxt || !cxt->label)
-               return -EINVAL;
-       if (!cxt->label->part_delete)
-               return -ENOSYS;
-
-       DBG(LABEL, dbgprint("deleting %s partition number %d",
-                               cxt->label->name, partnum));
-       return cxt->label->part_delete(cxt, partnum);
-}
 
 static int __probe_labels(struct fdisk_context *cxt)
 {
@@ -474,28 +395,6 @@ int fdisk_reset_alignment(struct fdisk_context *cxt)
        return rc;
 }
 
-/**
- * fdisk_dev_has_disklabel:
- * @cxt: fdisk context
- *
- * Returns: return 1 if there is label on the device.
- */
-int fdisk_dev_has_disklabel(struct fdisk_context *cxt)
-{
-       return cxt && cxt->disklabel != FDISK_DISKLABEL_ANY;
-}
-
-/**
- * fdisk_dev_is_disklabel:
- * @cxt: fdisk context
- * @l: disklabel type
- *
- * Returns: return 1 if there is @l disklabel on the device.
- */
-int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l)
-{
-       return cxt && cxt->disklabel == l;
-}
 
 /**
  * fdisk_create_disklabel:
index 3159432f5182042005cfa05ef9641357bef972ce..f14e1541d44075d43b1d9ab3ea53d546cb34a012 100644 (file)
@@ -10,6 +10,7 @@ libfdisk_la_SOURCES = \
        \
        libfdisk/src/init.c \
        libfdisk/src/alignment.c \
+       libfdisk/src/label.c \
        libfdisk/src/parttype.c
 
 
index 9ae258e13df51d88c2eceddf201650d306941144..6d2fef1cf720d65c9e895232de91875b2b927410 100644 (file)
@@ -88,20 +88,6 @@ extern int fdisk_debug_mask;
 
 typedef unsigned long long sector_t;
 
-/*
- * Supported partition table types (labels)
- */
-enum fdisk_labeltype {
-       FDISK_DISKLABEL_DOS = 1,
-       FDISK_DISKLABEL_SUN = 2,
-       FDISK_DISKLABEL_SGI = 4,
-       FDISK_DISKLABEL_AIX = 8,
-       FDISK_DISKLABEL_OSF = 16,
-       FDISK_DISKLABEL_MAC = 32,
-       FDISK_DISKLABEL_GPT = 64,
-       FDISK_DISKLABEL_ANY = -1
-};
-
 /*
  * Partition types
  */
@@ -159,8 +145,6 @@ struct fdisk_context {
        const struct fdisk_label *label;
 };
 
-#define fdisk_is_disklabel(c, x) fdisk_dev_is_disklabel(c, FDISK_DISKLABEL_ ## x)
-
 /*
  * Label specific operations
  */
diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c
new file mode 100644 (file)
index 0000000..86c3099
--- /dev/null
@@ -0,0 +1,105 @@
+
+#include "fdiskP.h"
+
+/**
+ * fdisk_dev_has_disklabel:
+ * @cxt: fdisk context
+ *
+ * Returns: return 1 if there is label on the device.
+ */
+int fdisk_dev_has_disklabel(struct fdisk_context *cxt)
+{
+       return cxt && cxt->disklabel != FDISK_DISKLABEL_ANY;
+}
+
+/**
+ * fdisk_dev_is_disklabel:
+ * @cxt: fdisk context
+ * @l: disklabel type
+ *
+ * Returns: return 1 if there is @l disklabel on the device.
+ */
+int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l)
+{
+       return cxt && cxt->disklabel == l;
+}
+
+/**
+ * fdisk_write_disklabel:
+ * @cxt: fdisk context
+ *
+ * Write in-memory changes to disk
+ *
+ * Returns 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_write_disklabel(struct fdisk_context *cxt)
+{
+       if (!cxt || !cxt->label)
+               return -EINVAL;
+       if (!cxt->label->write)
+               return -ENOSYS;
+
+       return cxt->label->write(cxt);
+}
+
+/**
+ * fdisk_verify_disklabel:
+ * @cxt: fdisk context
+ *
+ * Verifies the partition table.
+ *
+ * Returns 0.
+ */
+int fdisk_verify_disklabel(struct fdisk_context *cxt)
+{
+       if (!cxt || !cxt->label)
+               return -EINVAL;
+       if (!cxt->label->verify)
+               return -ENOSYS;
+
+       return cxt->label->verify(cxt);
+}
+
+/**
+ * fdisk_add_partition:
+ * @cxt: fdisk context
+ * @partnum: partition number to create
+ * @t: partition type to create or NULL for label-specific default
+ *
+ * Creates a new partition, with number @partnum and type @parttype.
+ *
+ * Returns 0.
+ */
+int fdisk_add_partition(struct fdisk_context *cxt, int partnum,
+                       struct fdisk_parttype *t)
+{
+       if (!cxt || !cxt->label)
+               return -EINVAL;
+       if (!cxt->label->part_add)
+               return -ENOSYS;
+
+       DBG(LABEL, dbgprint("adding new partition number %d", partnum));
+       cxt->label->part_add(cxt, partnum, t);
+       return 0;
+}
+
+/**
+ * fdisk_delete_partition:
+ * @cxt: fdisk context
+ * @partnum: partition number to delete
+ *
+ * Deletes a @partnum partition.
+ *
+ * Returns 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_delete_partition(struct fdisk_context *cxt, int partnum)
+{
+       if (!cxt || !cxt->label)
+               return -EINVAL;
+       if (!cxt->label->part_delete)
+               return -ENOSYS;
+
+       DBG(LABEL, dbgprint("deleting %s partition number %d",
+                               cxt->label->name, partnum));
+       return cxt->label->part_delete(cxt, partnum);
+}
index 33187fe5a2bc2f512a9f58b2ec03b006edf8ebed..6ea08bdb0da4ddb374a0426be6fa338ae0bbb5a4 100644 (file)
@@ -28,6 +28,20 @@ extern "C" {
 struct fdisk_context;
 struct fdisk_parttype;
 
+/*
+ * Supported partition table types (labels)
+ */
+enum fdisk_labeltype {
+       FDISK_DISKLABEL_DOS = 1,
+       FDISK_DISKLABEL_SUN = 2,
+       FDISK_DISKLABEL_SGI = 4,
+       FDISK_DISKLABEL_AIX = 8,
+       FDISK_DISKLABEL_OSF = 16,
+       FDISK_DISKLABEL_MAC = 32,
+       FDISK_DISKLABEL_GPT = 64,
+       FDISK_DISKLABEL_ANY = -1
+};
+
 /* init.c */
 extern void fdisk_init_debug(int mask);
 
@@ -42,6 +56,18 @@ extern struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int type, cons
 extern void fdisk_free_parttype(struct fdisk_parttype *type);
 extern size_t fdisk_get_nparttypes(struct fdisk_context *cxt);
 
+/* label.c */
+extern int fdisk_dev_has_disklabel(struct fdisk_context *cxt);
+
+extern int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltype l);
+#define fdisk_is_disklabel(c, x) fdisk_dev_is_disklabel(c, FDISK_DISKLABEL_ ## x)
+
+extern int fdisk_write_disklabel(struct fdisk_context *cxt);
+extern int fdisk_verify_disklabel(struct fdisk_context *cxt);
+
+extern int fdisk_add_partition(struct fdisk_context *cxt, int partnum, struct fdisk_parttype *t);
+extern int fdisk_delete_partition(struct fdisk_context *cxt, int partnum);
+
 #ifdef __cplusplus
 }
 #endif