summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2014-11-20 13:28:41 +0100
committerKarel Zak2014-11-20 13:28:41 +0100
commit9146a00823925f318fb7b71f0db0feb0d71d06ba (patch)
treef7ef0bdda722db321b343be9629197adc7d6c5f0
parentlibfdisk: (dos) allow to maximize partition (diff)
downloadkernel-qcow2-util-linux-9146a00823925f318fb7b71f0db0feb0d71d06ba.tar.gz
kernel-qcow2-util-linux-9146a00823925f318fb7b71f0db0feb0d71d06ba.tar.xz
kernel-qcow2-util-linux-9146a00823925f318fb7b71f0db0feb0d71d06ba.zip
ibfdisk: (gpt) allow to maximize partition
enlarge second partition: # echo ',+' | ./sfdisk -N2 /dev/sdb ... Disk /dev/sdb: 100 MiB, 104857600 bytes, 204800 sectors Old situation: Device Start End Sectors Size Type /dev/sdb1 2048 22527 20480 10M Linux filesystem /dev/sdb2 22528 43007 20480 10M Linux filesystem New situation: Device Start End Sectors Size Type /dev/sdb1 2048 22527 20480 10M Linux filesystem /dev/sdb2 22528 204766 182239 89M Linux filesystem Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--libfdisk/src/gpt.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c
index ecf62d2d4..d3bc4ae00 100644
--- a/libfdisk/src/gpt.c
+++ b/libfdisk/src/gpt.c
@@ -1499,6 +1499,7 @@ static int gpt_set_partition(struct fdisk_context *cxt, size_t n,
struct fdisk_gpt_label *gpt;
struct gpt_entry *e;
int rc = 0;
+ uint64_t start, end;
assert(cxt);
assert(cxt->label);
@@ -1509,6 +1510,9 @@ static int gpt_set_partition(struct fdisk_context *cxt, size_t n,
if ((uint32_t) n >= le32_to_cpu(gpt->pheader->npartition_entries))
return -EINVAL;
+ FDISK_INIT_UNDEF(start);
+ FDISK_INIT_UNDEF(end);
+
gpt = self_label(cxt);
e = &gpt->ents[n];
@@ -1550,9 +1554,23 @@ static int gpt_set_partition(struct fdisk_context *cxt, size_t n,
}
if (fdisk_partition_has_start(pa))
- e->lba_start = cpu_to_le64(pa->start);
+ start = pa->start;
if (fdisk_partition_has_size(pa))
- e->lba_end = cpu_to_le64(gpt_partition_start(e) + pa->size - 1ULL);
+ end = gpt_partition_start(e) + pa->size - 1ULL;
+
+ if (pa->end_follow_default) {
+ /* enlarge */
+ if (!FDISK_IS_UNDEF(start))
+ start = gpt_partition_start(e);
+ end = find_last_free(gpt->bheader, gpt->ents, start);
+ if (!end)
+ FDISK_INIT_UNDEF(end);
+ }
+
+ if (!FDISK_IS_UNDEF(start))
+ e->lba_start = cpu_to_le64(start);
+ if (!FDISK_IS_UNDEF(end))
+ e->lba_end = cpu_to_le64(end);
gpt_recompute_crc(gpt->pheader, gpt->ents);
gpt_recompute_crc(gpt->bheader, gpt->ents);