diff options
author | Tobias Stoeckmann | 2016-08-27 19:28:48 +0200 |
---|---|---|
committer | Karel Zak | 2016-08-29 13:22:24 +0200 |
commit | 1037269fec43e8055c530c13d4fd58819e86b233 (patch) | |
tree | a2c35d1f38fc75b4a16badfb859fd3f80da44f95 /libfdisk | |
parent | libfdisk: Fix assert error in free space handling (diff) | |
download | kernel-qcow2-util-linux-1037269fec43e8055c530c13d4fd58819e86b233.tar.gz kernel-qcow2-util-linux-1037269fec43e8055c530c13d4fd58819e86b233.tar.xz kernel-qcow2-util-linux-1037269fec43e8055c530c13d4fd58819e86b233.zip |
libfdisk: Distinguish between first LBA sector and partition
An insufficient check leads to an invalid free space output, as seen here:
$ dd if=/dev/zero of=cfdisk.iso bs=1M count=1
$ losetup -f cfdisk.iso
$ echo w | fdisk /dev/loop0
$ echo '1,1' | sfdisk /dev/loop0 --append
$ echo '3,' | sfdisk /dev/loop0 --append
$ sfdisk --list-free /dev/loop0
Start End Sectors Size
1 2 2 1K
$ _
In this case, libfdisk fails to notice that it tries to calculate space
between two partitions, not between start of disk and first partition.
Currently, the code tries to achieve that by checking the address of the
last "partition", which is the first_lba block. Now if the first
partition is merely 1 block in size, the "last" address is still equal
to the first_lba block, which renders the check in libfdisk for the next
partition invalid.
I chose to use "nparts == 0" for this check, because the partitions are
properly sorted before iterating over them.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Diffstat (limited to 'libfdisk')
-rw-r--r-- | libfdisk/src/table.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c index bf30d1b19..f9751686b 100644 --- a/libfdisk/src/table.c +++ b/libfdisk/src/table.c @@ -617,9 +617,9 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb) * 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)) { + || (last < pa->start && nparts == 0)) { rc = table_add_freespace(cxt, *tb, - last + (last > cxt->first_lba ? 1 : 0), + last + (nparts == 0 ? 0 : 1), pa->start - 1, NULL); } /* add gaps between logical partitions */ |