]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: allow to specify partition size by explicit number of sectors
authorKarel Zak <kzak@redhat.com>
Thu, 9 Oct 2014 10:02:17 +0000 (12:02 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 9 Oct 2014 10:02:17 +0000 (12:02 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/fdiskP.h
libfdisk/src/libfdisk.h
libfdisk/src/partition.c

index 6dff06b9744ac407744667f8ca7790509db3ca0f..e1b4636213eb2a4f7c56a43232b2c66a88de2626 100644 (file)
@@ -142,6 +142,7 @@ struct fdisk_partition {
        unsigned int    partno_follow_default : 1,      /* use default partno */
                        start_follow_default : 1,       /* use default start */
                        end_follow_default : 1,         /* use default end */
+                       size_explicit : 1,              /* don't align the size */
                        freespace : 1,          /* this is free space */
                        container : 1,          /* container partition (e.g. extended partition) */
                        wholedisk : 1,          /* special system partition */
index 96c6bfaef0e5d30e9e8a77ea093cc3c33ed94d68..a01481f21f372d59333b0c8f8fa37bf7ca58976f 100644 (file)
@@ -250,6 +250,7 @@ extern int fdisk_partition_cmp_start(struct fdisk_partition *a,
 extern int fdisk_partition_set_end(struct fdisk_partition *pa, uint64_t off);
 extern uint64_t fdisk_partition_get_end(struct fdisk_partition *pa);
 extern int fdisk_partition_set_size(struct fdisk_partition *pa, uint64_t size);
+extern int fdisk_partition_size_explicit(struct fdisk_partition *pa, int enable);
 extern uint64_t fdisk_partition_get_size(struct fdisk_partition *pa);
 
 extern int fdisk_partition_set_partno(struct fdisk_partition *pa, size_t n);
index c9b596b6bb1bb461d3a8d6369519d92c65272961..c6142900e8fc5c546740d15e8100da9ad4c1dc32 100644 (file)
@@ -337,6 +337,25 @@ int fdisk_partition_end_is_default(struct fdisk_partition *pa)
        return pa->end_follow_default;
 }
 
+/**
+ * fdisk_partition_size_explicit:
+ * @pa: partition
+ * @enable: 0|1
+ *
+ * By default libfdisk aligns the size when add the new partition (by
+ * fdisk_add_partrition()). If you want to disable this functionality use
+ * @enable = 1.
+ *
+ * Returns: 0 on success, <0 on error.
+ */
+int fdisk_partition_size_explicit(struct fdisk_partition *pa, int enable)
+{
+       if (!pa)
+               return -EINVAL;
+       pa->size_explicit = enable ? 1 : 0;
+       return 0;
+}
+
 const char *fdisk_partition_get_uuid(struct fdisk_partition *pa)
 {
        return pa ? pa->uuid : NULL;
@@ -601,7 +620,8 @@ int fdisk_get_partition(struct fdisk_context *cxt, size_t partno,
                        *pa = NULL;
                } else
                        fdisk_reset_partition(*pa);
-       }
+       } else
+               (*pa)->size_explicit = 1;
        return rc;
 }