From: Yu Watanabe Date: Mon, 5 Sep 2022 12:56:49 +0000 (+0900) Subject: repart: split out free_area_{current,min}_end() from free_area_available_for_new_part... X-Git-Tag: v252-rc1~222^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58b06ac1ab8d6a9dbb9d51b09cad203aef4e5fc5;p=thirdparty%2Fsystemd.git repart: split out free_area_{current,min}_end() from free_area_available_for_new_partitions() No actual code changes, just preparation for later commits. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 5b999d5ba92..004022f6dab 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -571,35 +571,42 @@ static uint64_t free_area_available(const FreeArea *a) { return a->size - a->allocated; } -static uint64_t free_area_available_for_new_partitions(Context *context, const FreeArea *a) { - uint64_t avail; - +static uint64_t free_area_current_end(Context *context, const FreeArea *a) { assert(context); assert(a); - /* Similar to free_area_available(), but takes into account that the required size and padding of the - * preceding partition is honoured. */ + if (!a->after) + return free_area_available(a); - avail = free_area_available(a); - if (a->after) { - uint64_t need, space_end, new_end; + assert(a->after->offset != UINT64_MAX); + assert(a->after->current_size != UINT64_MAX); - need = partition_min_size_with_padding(context, a->after); + /* Calculate where the free area ends, based on the offset of the partition preceding it. */ + return round_up_size(a->after->offset + a->after->current_size, context->grain_size) + free_area_available(a); +} - assert(a->after->offset != UINT64_MAX); - assert(a->after->current_size != UINT64_MAX); +static uint64_t free_area_min_end(Context *context, const FreeArea *a) { + assert(context); + assert(a); - /* 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, context->grain_size) + avail; + if (!a->after) + return 0; - /* Calculate where the partition would end when we give it as much as it needs */ - new_end = round_up_size(a->after->offset + need, context->grain_size); + assert(a->after->offset != UINT64_MAX); + assert(a->after->current_size != UINT64_MAX); - /* Calculate saturated difference of the two: that's how much we have free for other partitions */ - return LESS_BY(space_end, new_end); - } + /* Calculate where the partition would end when we give it as much as it needs. */ + return round_up_size(a->after->offset + partition_min_size_with_padding(context, a->after), context->grain_size); +} + +static uint64_t free_area_available_for_new_partitions(Context *context, const FreeArea *a) { + assert(context); + assert(a); + + /* Similar to free_area_available(), but takes into account that the required size and padding of the + * preceding partition is honoured. */ - return avail; + return LESS_BY(free_area_current_end(context, a), free_area_min_end(context, a)); } static int free_area_compare(FreeArea *const *a, FreeArea *const*b, Context *context) {