From: Daan De Meyer Date: Fri, 14 Oct 2022 10:40:28 +0000 (+0200) Subject: repart: Use first unused partition number for new partitions X-Git-Tag: v253-rc1~525^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00428745e3d1e42fe4481fc8a5c50d6316d4282a;p=thirdparty%2Fsystemd.git repart: Use first unused partition number for new partitions If we skip some partition types in a first run of systemd-repart, we don't want their partition numbers to be different than usual, so let's change the allocation of partition numbers to account for that. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 20f764ee1ca..c2051de6596 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -1025,21 +1025,30 @@ static int context_grow_partitions(Context *context) { return 0; } -static void context_place_partitions(Context *context) { +static uint64_t find_first_unused_partno(Context *context) { uint64_t partno = 0; assert(context); - /* Determine next partition number to assign */ - LIST_FOREACH(partitions, p, context->partitions) { - if (!PARTITION_EXISTS(p)) - continue; + for (bool changed = true; changed;) { + changed = false; - assert(p->partno != UINT64_MAX); - if (p->partno >= partno) - partno = p->partno + 1; + LIST_FOREACH(partitions, p, context->partitions) { + if (p->partno != UINT64_MAX && p->partno == partno) { + partno++; + changed = true; + break; + } + } } + return partno; +} + +static void context_place_partitions(Context *context) { + + assert(context); + for (size_t i = 0; i < context->n_free_areas; i++) { FreeArea *a = context->free_areas[i]; _unused_ uint64_t left; @@ -1062,7 +1071,7 @@ static void context_place_partitions(Context *context) { continue; p->offset = start; - p->partno = partno++; + p->partno = find_first_unused_partno(context); assert(left >= p->new_size); start += p->new_size;