]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: cleanup fdisk_gpt_set_npartitions()
authorKarel Zak <kzak@redhat.com>
Tue, 21 Jun 2016 12:21:30 +0000 (14:21 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 21 Jun 2016 12:21:30 +0000 (14:21 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/docs/libfdisk-sections.txt
libfdisk/src/gpt.c
libfdisk/src/libfdisk.h.in

index 7ae7d9a96df7af6e1b7e214c83195729057d1ff6..72a7dca34ff70d88e16fe007904122157ad4d956 100644 (file)
@@ -224,6 +224,7 @@ fdisk_sgi_set_bootfile
 fdisk_gpt_is_hybrid
 fdisk_gpt_get_partition_attrs
 fdisk_gpt_set_partition_attrs
+fdisk_gpt_set_npartitions
 GPT_FLAG_REQUIRED
 GPT_FLAG_NOBLOCK
 GPT_FLAG_LEGACYBOOT
index cf77a60be940af7245ef31ca7fb946cfbdecfbdb..e665dc10dce5ab9532fd47cb0b361d1e71a88ceb 100644 (file)
@@ -2490,11 +2490,23 @@ static int gpt_check_table_overlap(struct fdisk_context *cxt,
        return rc;
 }
 
-int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, unsigned long new)
+/**
+ * fdisk_gpt_set_npartitions:
+ * @cxt: context
+ * @new: new size
+ *
+ * Elarge GPT entries array if possible. The function check if an existing
+ * partition does not overlap the entries array area. If yes, then it report
+ * warning and returns -EINVAL.
+ *
+ * Returns: 0 on success, < 0 on error.
+ * Since: v2.29
+ */
+int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, uint32_t new)
 {
        struct fdisk_gpt_label *gpt;
        size_t old_size, new_size;
-       unsigned long old;
+       uint32_t old;
        struct gpt_entry *ents;
        uint64_t first_usable, last_usable;
        int rc;
@@ -2514,8 +2526,8 @@ int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, unsigned long new)
        old_size = old * le32_to_cpu(gpt->pheader->sizeof_partition_entry);
 
        /* calculate new range of usable LBAs */
-       first_usable = (new_size / cxt->sector_size) + 2;
-       last_usable = cxt->total_sectors - 2ULL - (new_size / cxt->sector_size);
+       first_usable = (uint64_t) (new_size / cxt->sector_size) + 2ULL;
+       last_usable = cxt->total_sectors - 2ULL - (uint64_t) (new_size / cxt->sector_size);
 
        /* if expanding the table, first check that everything fits,
         * then allocate more memory and zero. */
@@ -2552,7 +2564,7 @@ int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, unsigned long new)
        gpt_recompute_crc(gpt->pheader, gpt->ents);
        gpt_recompute_crc(gpt->bheader, gpt->ents);
 
-       fdisk_info(cxt, _("Partition table length changed from %lu to %lu."), old, new);
+       fdisk_info(cxt, _("Partition table length changed from %"PRIu32" to %"PRIu64"."), old, new);
 
        fdisk_label_set_changed(cxt->label, 1);
        return 0;
index 38c2f9cec86e3eee8150ee87bb8c986fa4fa8418..9154f5bebe0f1bdfaf0a2f00924610cdcb3d42a2 100644 (file)
@@ -616,7 +616,7 @@ enum fdisk_labelitem_sgi {
 #define GPT_FLAG_GUIDSPECIFIC  4
 
 extern int fdisk_gpt_is_hybrid(struct fdisk_context *cxt);
-extern int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, unsigned long entries);
+extern int fdisk_gpt_set_npartitions(struct fdisk_context *cxt, uint32_t entries);
 extern int fdisk_gpt_get_partition_attrs(struct fdisk_context *cxt, size_t partnum, uint64_t *attrs);
 extern int fdisk_gpt_set_partition_attrs(struct fdisk_context *cxt, size_t partnum, uint64_t attrs);