1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-08 09:57:41 +03:00

repart: don't try to determine sector size from a disk image we should consider empty

If we are told to start from scratch we shouldn't look into the old
image to determine sector size. Looking there is confusing at best, but
plain wrong in many other cases.
This commit is contained in:
Lennart Poettering 2024-01-23 16:05:37 +01:00 committed by Luca Boccassi
parent ab36d7c975
commit a575f2148f

View File

@ -2326,7 +2326,9 @@ static int context_load_partition_table(Context *context) {
uint32_t ssz;
struct stat st;
r = context_open_and_lock_backing_fd(context->node, arg_dry_run ? LOCK_SH : LOCK_EX,
r = context_open_and_lock_backing_fd(
context->node,
arg_dry_run ? LOCK_SH : LOCK_EX,
&context->backing_fd);
if (r < 0)
return r;
@ -2334,6 +2336,10 @@ static int context_load_partition_table(Context *context) {
if (fstat(context->backing_fd, &st) < 0)
return log_error_errno(errno, "Failed to stat %s: %m", context->node);
if (IN_SET(arg_empty, EMPTY_REQUIRE, EMPTY_FORCE, EMPTY_CREATE) && S_ISREG(st.st_mode))
/* Don't probe sector size from partition table if we are supposed to strat from an empty disk */
fs_secsz = ssz = 512;
else {
/* Auto-detect sector size if not specified. */
r = probe_sector_size_prefer_ioctl(context->backing_fd, &ssz);
if (r < 0)
@ -2344,6 +2350,7 @@ static int context_load_partition_table(Context *context) {
* not just the offset at which we found the GPT header. */
if (r > 0 && S_ISBLK(st.st_mode))
fs_secsz = ssz;
}
r = fdisk_save_user_sector_size(c, /* phy= */ 0, ssz);
}