From 264668a817e60318eac355f63f1b25d252b79785 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Jul 2023 14:37:07 +0900 Subject: [PATCH 1/4] repart: fix comment --- src/partition/repart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/partition/repart.c b/src/partition/repart.c index c7791178b4..a65a1aa962 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -2108,7 +2108,7 @@ static int context_load_partition_table(Context *context) { return log_error_errno(errno, "Failed to stat block device '%s': %m", context->node); if (S_ISREG(st.st_mode) && st.st_size == 0) { - /* User the fallback values if we have no better idea */ + /* Use the fallback values if we have no better idea */ context->sector_size = arg_sector_size ?: 512; context->grain_size = 4096; return /* from_scratch = */ true; From beba8f2e1e5f08041d2a9955398a64d92dcc75a0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Jul 2023 12:11:50 +0900 Subject: [PATCH 2/4] test: add reproducer for issue #28225 --- test/units/testsuite-58.sh | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/test/units/testsuite-58.sh b/test/units/testsuite-58.sh index 6ddb96d26e..a170128de9 100755 --- a/test/units/testsuite-58.sh +++ b/test/units/testsuite-58.sh @@ -1021,6 +1021,86 @@ EOF systemd-dissect -U "$imgs/mnt" } +testcase_free_area_calculation() { + local defs imgs output + + if ! command -v mksquashfs >/dev/null; then + echo "Skipping free area calculation test without squashfs." + return + fi + + defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")" + imgs="$(mktemp --directory "/var/tmp/test-repart.imgs.XXXXXXXXXX")" + # shellcheck disable=SC2064 + trap "rm -rf '$defs' '$imgs'" RETURN + chmod a+rx "$defs" + + # https://github.com/systemd/systemd/issues/28225 + echo "*** free area calculation ***" + + tee "$defs/00-ESP.conf" < Date: Mon, 3 Jul 2023 15:14:14 +0900 Subject: [PATCH 3/4] repart: fix free area calculation Like fdisk_get_last_lba(), fdisk_partition_get_end() return the last sector in the partition. Fixes #28225. --- src/partition/repart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/partition/repart.c b/src/partition/repart.c index a65a1aa962..fc33a3eb62 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -1922,6 +1922,8 @@ static int determine_current_padding( return log_error_errno(SYNTHETIC_ERRNO(EIO), "Partition has no end!"); offset = fdisk_partition_get_end(p); + assert(offset < UINT64_MAX); + offset++; /* The end is one sector before the next partition or padding. */ assert(offset < UINT64_MAX / secsz); offset *= secsz; From 937625c7c72e503d03b406de3e1859d7f00dbdcf Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Jul 2023 15:15:27 +0900 Subject: [PATCH 4/4] test: update test for free area calculation in repart --- test/units/testsuite-58.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/units/testsuite-58.sh b/test/units/testsuite-58.sh index a170128de9..c7510dd3fc 100755 --- a/test/units/testsuite-58.sh +++ b/test/units/testsuite-58.sh @@ -1088,7 +1088,7 @@ EOF --json=pretty \ "$imgs/zzz") - # FIXME: the second invocation fails. + # The second invocation output2=$(SYSTEMD_REPART_MKFS_OPTIONS_VFAT="-S 512" systemd-repart \ --definitions="$defs" \ --seed="$seed" \ @@ -1098,7 +1098,9 @@ EOF --sector-size=4096 \ --defer-partitions=esp \ --json=pretty \ - "$imgs/zzz") || : + "$imgs/zzz") + + diff -u <(echo "$output1" | grep -E "(offset|raw_size|raw_padding)") <(echo "$output2" | grep -E "(offset|raw_size|raw_padding)") } test_sector() {