From: Daan De Meyer Date: Sat, 12 Aug 2023 11:28:10 +0000 (+0200) Subject: mkfs-util: Set sector size environment variables when invoking mkfs.ext4 X-Git-Tag: v255-rc1~723^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=89dfac6b8fc467fc12ba899199feacba8dc24509;p=thirdparty%2Fsystemd.git mkfs-util: Set sector size environment variables when invoking mkfs.ext4 Let's inform mkfs.ext4 about the sector size we're using. --- diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index dd65d3ba7b3..423f0a3f18f 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -329,7 +329,7 @@ int make_filesystem( char * const *extra_mkfs_args) { _cleanup_free_ char *mkfs = NULL, *mangled_label = NULL; - _cleanup_strv_free_ char **argv = NULL; + _cleanup_strv_free_ char **argv = NULL, **env = NULL; _cleanup_(rm_rf_physical_and_freep) char *protofile_tmpdir = NULL; _cleanup_(unlink_and_freep) char *protofile = NULL; char vol_id[CONST_MAX(SD_ID128_UUID_STRING_MAX, 8U + 1U)] = {}; @@ -432,6 +432,15 @@ int make_filesystem( if (quiet && strv_extend(&argv, "-q") < 0) return log_oom(); + if (sector_size > 0) + FOREACH_STRING(s, "MKE2FS_DEVICE_SECTSIZE", "MKE2FS_DEVICE_PHYS_SECTSIZE") { + if (strv_extend(&env, s) < 0) + return log_oom(); + + if (strv_extendf(&env, "%"PRIu64, sector_size) < 0) + return log_oom(); + } + } else if (streq(fstype, "btrfs")) { argv = strv_new(mkfs, "-L", label, @@ -594,6 +603,12 @@ int make_filesystem( if (r == 0) { /* Child */ + STRV_FOREACH_PAIR(k, v, env) + if (setenv(*k, *v, /* replace = */ true) < 0) { + log_error_errno(r, "Failed to set %s=%s environment variable: %m", *k, *v); + _exit(EXIT_FAILURE); + } + /* mkfs.btrfs refuses to operate on block devices with mounted partitions, even if operating * on unformatted free space, so let's trick it and other mkfs tools into thinking no * partitions are mounted. See https://github.com/kdave/btrfs-progs/issues/640 for more