diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-11-09 16:31:48 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-11-09 16:31:48 +0100 |
commit | 1052a1142d8328a77bdc5011e749619f8e73ed54 (patch) | |
tree | 90fd63fdd4145c58b84992b0fcc7fbcfa3485c65 | |
parent | 0b7f574f72c72afb9384d7ea11b324ead067c8d1 (diff) | |
download | systemd-1052a1142d8328a77bdc5011e749619f8e73ed54.tar.gz |
repart: fix free area calculations for unaligned partitions
To properly detect how much space we have to distribute we need to take
into account that both the partition offset and the partition size
aren't aligned.
-rw-r--r-- | src/partition/repart.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c index 3ff9752005..5e6e88df94 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -505,18 +505,21 @@ static uint64_t free_area_available_for_new_partitions(const FreeArea *a) { avail = free_area_available(a); if (a->after) { - uint64_t need, space; + uint64_t need, space_end, new_end; need = partition_min_size_with_padding(a->after); assert(a->after->offset != UINT64_MAX); assert(a->after->current_size != UINT64_MAX); - space = round_up_size(a->after->offset + a->after->current_size, 4096) - a->after->offset + avail; - if (need >= space) - return 0; + /* Calculate where the free area ends, based on the offset of the partition preceding it */ + space_end = round_up_size(a->after->offset + a->after->current_size, 4096) + avail; + + /* Calculate where the partition would end when we give it as much as it needs */ + new_end = round_up_size(a->after->offset + need, 4096); - return space - need; + /* Calculate saturated difference of the two: that's how much we have free for other partitions */ + return LESS_BY(space_end, new_end); } return avail; |