summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/table.c
diff options
context:
space:
mode:
authorKarel Zak2015-09-17 12:27:58 +0200
committerKarel Zak2015-09-17 13:22:11 +0200
commit83677b99cb138426f94083c54092b1628d58a55b (patch)
tree9af3ea51930119df5a959d5d8353e16a6678291b /libfdisk/src/table.c
parentlibfdisk: add more debug message to resize code (diff)
downloadkernel-qcow2-util-linux-83677b99cb138426f94083c54092b1628d58a55b.tar.gz
kernel-qcow2-util-linux-83677b99cb138426f94083c54092b1628d58a55b.tar.xz
kernel-qcow2-util-linux-83677b99cb138426f94083c54092b1628d58a55b.zip
libfdisk: fix partition move/resize code
- verify that the new partition fits to the area if the size of the has not been modified - fix remaining space calculation (yes, brown-paper-bag bug..) - offer also space before first partition as free space Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/table.c')
-rw-r--r--libfdisk/src/table.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c
index 9921733d4..1a3d47a7c 100644
--- a/libfdisk/src/table.c
+++ b/libfdisk/src/table.c
@@ -597,7 +597,12 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
pa->partno,
(uintmax_t) fdisk_partition_get_start(pa),
(uintmax_t) fdisk_partition_get_end(pa)));
- if (last + grain <= pa->start) {
+
+ /* We ignore small free spaces (smaller than grain) to keep partitions
+ * aligned, the exception is space before the first partition where
+ * we assume that cxt->first_lba is aligned. */
+ if (last + grain <= pa->start
+ || (last < pa->start && last == cxt->first_lba)) {
rc = table_add_freespace(cxt, *tb,
last + (last > cxt->first_lba ? 1 : 0),
pa->start - 1, NULL);