summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/gpt.c
diff options
context:
space:
mode:
authorKarel Zak2016-06-21 14:21:30 +0200
committerKarel Zak2016-06-21 14:21:30 +0200
commitf88eeb25f2eb89fdbd35a9dfbaa26e234a3b0e14 (patch)
treeccf4de727a9038093e249124668e22e9677bf8a7 /libfdisk/src/gpt.c
parentlibfdisk: (gpt) be more careful with 64bit constants (diff)
downloadkernel-qcow2-util-linux-f88eeb25f2eb89fdbd35a9dfbaa26e234a3b0e14.tar.gz
kernel-qcow2-util-linux-f88eeb25f2eb89fdbd35a9dfbaa26e234a3b0e14.tar.xz
kernel-qcow2-util-linux-f88eeb25f2eb89fdbd35a9dfbaa26e234a3b0e14.zip
libfdisk: cleanup fdisk_gpt_set_npartitions()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/gpt.c')
-rw-r--r--libfdisk/src/gpt.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index cf77a60be..e665dc10d 100644
--- a/libfdisk/src/gpt.c
+++ b/libfdisk/src/gpt.c
@@ -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;