diff options
author | Karel Zak | 2016-06-21 14:21:30 +0200 |
---|---|---|
committer | Karel Zak | 2016-06-21 14:21:30 +0200 |
commit | f88eeb25f2eb89fdbd35a9dfbaa26e234a3b0e14 (patch) | |
tree | ccf4de727a9038093e249124668e22e9677bf8a7 /libfdisk | |
parent | libfdisk: (gpt) be more careful with 64bit constants (diff) | |
download | kernel-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')
-rw-r--r-- | libfdisk/docs/libfdisk-sections.txt | 1 | ||||
-rw-r--r-- | libfdisk/src/gpt.c | 22 | ||||
-rw-r--r-- | libfdisk/src/libfdisk.h.in | 2 |
3 files changed, 19 insertions, 6 deletions
diff --git a/libfdisk/docs/libfdisk-sections.txt b/libfdisk/docs/libfdisk-sections.txt index 7ae7d9a96..72a7dca34 100644 --- a/libfdisk/docs/libfdisk-sections.txt +++ b/libfdisk/docs/libfdisk-sections.txt @@ -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 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; diff --git a/libfdisk/src/libfdisk.h.in b/libfdisk/src/libfdisk.h.in index 38c2f9cec..9154f5beb 100644 --- a/libfdisk/src/libfdisk.h.in +++ b/libfdisk/src/libfdisk.h.in @@ -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); |