Merge pull request #28228 from yuwata/repart-free-area
repart: fix free area calculation
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -2108,7 +2110,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;
|
||||
|
||||
@@ -1021,6 +1021,88 @@ 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" <<EOF
|
||||
[Partition]
|
||||
Type = esp
|
||||
Label = ESP
|
||||
Format = vfat
|
||||
|
||||
SizeMinBytes = 128M
|
||||
SizeMaxBytes = 128M
|
||||
|
||||
# Sufficient for testing
|
||||
CopyFiles = /etc:/
|
||||
EOF
|
||||
|
||||
tee "$defs/10-os.conf" <<EOF
|
||||
[Partition]
|
||||
Type = root-${architecture}
|
||||
Label = test
|
||||
Format = squashfs
|
||||
|
||||
Minimize = best
|
||||
# Sufficient for testing
|
||||
CopyFiles = /etc/:/
|
||||
|
||||
VerityMatchKey = os
|
||||
Verity = data
|
||||
EOF
|
||||
|
||||
tee "$defs/11-os-verity.conf" <<EOF
|
||||
[Partition]
|
||||
Type = root-${architecture}-verity
|
||||
Label = test
|
||||
|
||||
Minimize = best
|
||||
|
||||
VerityMatchKey = os
|
||||
Verity = hash
|
||||
EOF
|
||||
|
||||
# Set sector size for VFAT to 512 bytes because there will not be enough FAT clusters otherwise
|
||||
output1=$(SYSTEMD_REPART_MKFS_OPTIONS_VFAT="-S 512" systemd-repart \
|
||||
--definitions="$defs" \
|
||||
--seed="$seed" \
|
||||
--dry-run=no \
|
||||
--empty=create \
|
||||
--size=auto \
|
||||
--sector-size=4096 \
|
||||
--defer-partitions=esp \
|
||||
--json=pretty \
|
||||
"$imgs/zzz")
|
||||
|
||||
# The second invocation
|
||||
output2=$(SYSTEMD_REPART_MKFS_OPTIONS_VFAT="-S 512" systemd-repart \
|
||||
--definitions="$defs" \
|
||||
--seed="$seed" \
|
||||
--dry-run=no \
|
||||
--empty=allow \
|
||||
--size=auto \
|
||||
--sector-size=4096 \
|
||||
--defer-partitions=esp \
|
||||
--json=pretty \
|
||||
"$imgs/zzz")
|
||||
|
||||
diff -u <(echo "$output1" | grep -E "(offset|raw_size|raw_padding)") <(echo "$output2" | grep -E "(offset|raw_size|raw_padding)")
|
||||
}
|
||||
|
||||
test_sector() {
|
||||
local defs imgs output loop
|
||||
local start size ratio
|
||||
|
||||
Reference in New Issue
Block a user