1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

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.
This commit is contained in:
Daan De Meyer 2022-10-14 12:40:28 +02:00
parent 22e932f4d1
commit 00428745e3

View File

@ -1025,21 +1025,30 @@ static int context_grow_partitions(Context *context) {
return 0; return 0;
} }
static void context_place_partitions(Context *context) { static uint64_t find_first_unused_partno(Context *context) {
uint64_t partno = 0; uint64_t partno = 0;
assert(context); assert(context);
/* Determine next partition number to assign */ for (bool changed = true; changed;) {
LIST_FOREACH(partitions, p, context->partitions) { changed = false;
if (!PARTITION_EXISTS(p))
continue;
assert(p->partno != UINT64_MAX); LIST_FOREACH(partitions, p, context->partitions) {
if (p->partno >= partno) if (p->partno != UINT64_MAX && p->partno == partno) {
partno = p->partno + 1; 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++) { for (size_t i = 0; i < context->n_free_areas; i++) {
FreeArea *a = context->free_areas[i]; FreeArea *a = context->free_areas[i];
_unused_ uint64_t left; _unused_ uint64_t left;
@ -1062,7 +1071,7 @@ static void context_place_partitions(Context *context) {
continue; continue;
p->offset = start; p->offset = start;
p->partno = partno++; p->partno = find_first_unused_partno(context);
assert(left >= p->new_size); assert(left >= p->new_size);
start += p->new_size; start += p->new_size;