diff options
author | Karel Zak | 2012-12-04 17:02:50 +0100 |
---|---|---|
committer | Karel Zak | 2012-12-04 17:02:50 +0100 |
commit | 602ebe7da99c2294b63a76140a1a2626d3dc7b63 (patch) | |
tree | 3efbe1639cf761198a6137a0f07429eb40b53eae /fdisks/gpt.c | |
parent | fdisk: cleanup partition start/end usage (diff) | |
download | kernel-qcow2-util-linux-602ebe7da99c2294b63a76140a1a2626d3dc7b63.tar.gz kernel-qcow2-util-linux-602ebe7da99c2294b63a76140a1a2626d3dc7b63.tar.xz kernel-qcow2-util-linux-602ebe7da99c2294b63a76140a1a2626d3dc7b63.zip |
fdisk: (gpt) fix {last,first}_usable_lba usage
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/gpt.c')
-rw-r--r-- | fdisks/gpt.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/fdisks/gpt.c b/fdisks/gpt.c index c01767ba8..2a6498361 100644 --- a/fdisks/gpt.c +++ b/fdisks/gpt.c @@ -832,14 +832,19 @@ static uint64_t find_first_available(struct gpt_header *header, uint64_t first; uint32_t i, first_moved = 0; + uint64_t fu, lu; + if (!header || !e) return 0; + fu = le64_to_cpu(header->first_usable_lba); + lu = le64_to_cpu(header->last_usable_lba); + /* * Begin from the specified starting point or from the first usable * LBA, whichever is greater... */ - first = start < header->first_usable_lba ? header->first_usable_lba : start; + first = start < fu ? fu : start; /* * Now search through all partitions; if first is within an @@ -862,7 +867,7 @@ static uint64_t find_first_available(struct gpt_header *header, } } while (first_moved == 1); - if (first > header->last_usable_lba) + if (first > lu) first = 0; return first; @@ -879,11 +884,13 @@ static uint64_t find_last_free(struct gpt_header *header, if (!header || !e) return 0; - nearest_start = header->last_usable_lba; + nearest_start = le64_to_cpu(header->last_usable_lba); + for (i = 0; i < le32_to_cpu(header->npartition_entries); i++) { - if (nearest_start > gpt_partition_start(&e[i]) && - gpt_partition_start(&e[i]) > start) - nearest_start = gpt_partition_start(&e[i]) - 1; + uint64_t ps = gpt_partition_start(&e[i]); + + if (nearest_start > ps && ps > start) + nearest_start = ps - 1; } return nearest_start; @@ -900,7 +907,7 @@ static uint64_t find_last_free_sector(struct gpt_header *header, goto done; /* start by assuming the last usable LBA is available */ - last = header->last_usable_lba; + last = le64_to_cpu(header->last_usable_lba); do { last_moved = 0; for (i = 0; i < le32_to_cpu(header->npartition_entries); i++) { |