]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: move partition stuff to partition.c
authorKarel Zak <kzak@redhat.com>
Mon, 16 Dec 2013 12:59:48 +0000 (13:59 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:12 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/label.c
libfdisk/src/partition.c

index db9c402045b78f4abf8338961e4523fb1f2237b7..99571232cbbf4c7cf2c3ea476a06cc458f58c22a 100644 (file)
@@ -188,53 +188,7 @@ int fdisk_verify_disklabel(struct fdisk_context *cxt)
        return cxt->label->op->verify(cxt);
 }
 
-/**
- * fdisk_get_partition:
- * @cxt:
- * @partno:
- * @pa: pointer to partition struct
- *
- * Fills in @pa with data about partition @n.
- *
- * Returns: 0 on success, otherwise, a corresponding error.
- */
-int fdisk_get_partition(struct fdisk_context *cxt, size_t partno,
-                       struct fdisk_partition **pa)
-{
-       int rc;
-
-       if (!cxt || !cxt->label || !pa)
-               return -EINVAL;
-       if (!cxt->label->op->get_part)
-               return -ENOSYS;
-
-       if (!*pa) {
-               *pa = fdisk_new_partition();
-               if (!*pa)
-                       return -ENOMEM;
-       } else
-               fdisk_reset_partition(*pa);
-       (*pa)->cxt = cxt;
-       (*pa)->partno = partno;
-
-       rc = cxt->label->op->get_part(cxt, partno, *pa);
-       if (rc == 0 && fdisk_partition_is_used(*pa))
-               DBG(LABEL, dbgprint("get partition %zu", partno));
-       return rc;
-}
 
-/*
- * This is faster than fdisk_get_partition() + fdisk_partition_is_used()
- */
-int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n)
-{
-       if (!cxt || !cxt->label)
-               return -EINVAL;
-       if (!cxt->label->op->part_is_used)
-               return -ENOSYS;
-
-       return cxt->label->op->part_is_used(cxt, n);
-}
 
 /**
  * fdisk_list_disklabel:
@@ -416,56 +370,7 @@ done:
        return rc;
 }
 
-/**
- * fdisk_add_partition:
- * @cxt: fdisk context
- * @pa: template for the partition
- *
- * If @pa is not specified or any @pa item is missiong the libfdisk will ask by
- * fdisk_ask_ API.
- *
- * Creates a new partition.
- *
- * Returns 0.
- */
-int fdisk_add_partition(struct fdisk_context *cxt,
-                       struct fdisk_partition *pa)
-{
-       assert(cxt);
-       assert(cxt->label);
-
-       if (!cxt || !cxt->label)
-               return -EINVAL;
-       if (!cxt->label->op->add_part)
-               return -ENOSYS;
-       if (fdisk_missing_geometry(cxt))
-               return -EINVAL;
-
-       DBG(LABEL, dbgprint("adding new partition"));
-       cxt->label->op->add_part(cxt, pa);
-       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, size_t partnum)
-{
-       if (!cxt || !cxt->label)
-               return -EINVAL;
-       if (!cxt->label->op->part_delete)
-               return -ENOSYS;
-
-       DBG(LABEL, dbgprint("deleting %s partition number %zd",
-                               cxt->label->name, partnum));
-       return cxt->label->op->part_delete(cxt, partnum);
-}
 
 /**
  * fdisk_create_disklabel:
index 3cef46c20ba1271d1671b41ebe3e7d0d85664e5d..513af4f0a5c1fc26b2bc557f83d0bb8f082c9f98 100644 (file)
@@ -344,3 +344,101 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
                *data = p;
        return rc;
 }
+
+/**
+ * fdisk_get_partition:
+ * @cxt:
+ * @partno:
+ * @pa: pointer to partition struct
+ *
+ * Fills in @pa with data about partition @n.
+ *
+ * Returns: 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_get_partition(struct fdisk_context *cxt, size_t partno,
+                       struct fdisk_partition **pa)
+{
+       int rc;
+
+       if (!cxt || !cxt->label || !pa)
+               return -EINVAL;
+       if (!cxt->label->op->get_part)
+               return -ENOSYS;
+
+       if (!*pa) {
+               *pa = fdisk_new_partition();
+               if (!*pa)
+                       return -ENOMEM;
+       } else
+               fdisk_reset_partition(*pa);
+       (*pa)->cxt = cxt;
+       (*pa)->partno = partno;
+       rc = cxt->label->op->get_part(cxt, partno, *pa);
+       if (rc == 0 && fdisk_partition_is_used(*pa))
+               DBG(PART, dbgprint("get partition %zu", partno));
+       return rc;
+}
+
+/*
+ * This is faster than fdisk_get_partition() + fdisk_partition_is_used()
+ */
+int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n)
+{
+       if (!cxt || !cxt->label)
+               return -EINVAL;
+       if (!cxt->label->op->part_is_used)
+               return -ENOSYS;
+
+       return cxt->label->op->part_is_used(cxt, n);
+}
+
+/**
+ * fdisk_add_partition:
+ * @cxt: fdisk context
+ * @pa: template for the partition
+ *
+ * If @pa is not specified or any @pa item is missiong the libfdisk will ask by
+ * fdisk_ask_ API.
+ *
+ * Creates a new partition.
+ *
+ * Returns 0.
+ */
+int fdisk_add_partition(struct fdisk_context *cxt,
+                       struct fdisk_partition *pa)
+{
+       assert(cxt);
+       assert(cxt->label);
+
+       if (!cxt || !cxt->label)
+               return -EINVAL;
+       if (!cxt->label->op->add_part)
+               return -ENOSYS;
+       if (fdisk_missing_geometry(cxt))
+               return -EINVAL;
+
+       DBG(LABEL, dbgprint("adding new partition"));
+       cxt->label->op->add_part(cxt, pa);
+       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, size_t partnum)
+{
+       if (!cxt || !cxt->label)
+               return -EINVAL;
+       if (!cxt->label->op->part_delete)
+               return -ENOSYS;
+
+       DBG(LABEL, dbgprint("deleting %s partition number %zd",
+                               cxt->label->name, partnum));
+       return cxt->label->op->part_delete(cxt, partnum);
+}