]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fstab-generator: honor x-systemd.validatefs from kernel cmdline too 37109/head
authorMike Yuan <me@yhndnzj.com>
Sat, 12 Apr 2025 13:22:05 +0000 (15:22 +0200)
committerMike Yuan <me@yhndnzj.com>
Sat, 12 Apr 2025 14:33:22 +0000 (16:33 +0200)
src/fstab-generator/fstab-generator.c

index 3b3bc9db67009d5cbd83f1fde4f5c819f4aa5386..6f8028988164e995458b806facff493a92c67960 100644 (file)
@@ -1167,7 +1167,7 @@ static bool validate_root_or_usr_mount_source(const char *what, const char *swit
 static int add_sysroot_mount(void) {
         _cleanup_free_ char *what = NULL;
         const char *extra_opts = NULL, *fstype = NULL;
-        bool default_rw = true, makefs = false;
+        bool default_rw = true;
         MountPointFlags flags;
 
         if (!validate_root_or_usr_mount_source(arg_root_what, "root="))
@@ -1218,8 +1218,9 @@ static int add_sysroot_mount(void) {
 
         log_debug("Found entry what=%s where=/sysroot type=%s opts=%s", what, strna(arg_root_fstype), strempty(combined_options));
 
-        makefs = fstab_test_option(combined_options, "x-systemd.makefs\0");
-        flags = makefs * MOUNT_MAKEFS;
+        /* Only honor x-systemd.makefs and .validatefs here, others are not relevant in initrd/not used
+         * at all (also see mandatory_mount_drop_unapplicable_options()) */
+        flags = fstab_options_to_flags(combined_options, /* is_swap = */ false) & (MOUNT_MAKEFS|MOUNT_VALIDATEFS);
 
         return add_mount("/proc/cmdline",
                          arg_dest,
@@ -1237,8 +1238,7 @@ static int add_sysroot_mount(void) {
 static int add_sysroot_usr_mount(void) {
         _cleanup_free_ char *what = NULL;
         const char *extra_opts = NULL;
-        MountPointFlags flags;
-        bool makefs;
+        bool makefs, validatefs;
         int r;
 
         /* Returns 0 if we didn't do anything, > 0 if we either generated a unit for the /usr/ mount, or we
@@ -1308,8 +1308,10 @@ static int add_sysroot_usr_mount(void) {
 
         log_debug("Found entry what=%s where=/sysusr/usr type=%s opts=%s", what, strna(arg_usr_fstype), strempty(combined_options));
 
+        /* Only honor x-systemd.makefs and .validatefs here, others are not relevant in initrd/not used
+         * at all (also see mandatory_mount_drop_unapplicable_options()) */
         makefs = fstab_test_option(combined_options, "x-systemd.makefs\0");
-        flags = makefs * MOUNT_MAKEFS;
+        validatefs = fstab_test_option(combined_options, "x-systemd.validatefs\0");
 
         r = add_mount("/proc/cmdline",
                       arg_dest,
@@ -1319,13 +1321,13 @@ static int add_sysroot_usr_mount(void) {
                       arg_usr_fstype,
                       combined_options,
                       /* passno= */ is_device_path(what) ? 1 : 0,
-                      flags,
+                      makefs ? MOUNT_MAKEFS : 0,
                       SPECIAL_INITRD_USR_FS_TARGET,
                       "imports.target");
         if (r < 0)
                 return r;
 
-        r = add_sysusr_sysroot_usr_bind_mount("/proc/cmdline", /* validatefs = */ false);
+        r = add_sysusr_sysroot_usr_bind_mount("/proc/cmdline", validatefs);
         if (r < 0)
                 return r;