fstab-util: introduce fstab_enabled() helper function

And refuse to parse fstab when 'fstab=no' is specified in the kernel
command line.

When 'fstab=no' is specified in the kernel command line, fstab-generator
does not parse fstab and will not create e.g. /boot or /efi mount entry
even if fstab contains entries for the mount points. However, gpt-auto
generator may parse fstab file, and adjust or ignore mounts for EFI or
XBOOTLDR partitions based on the fstab file.

This makes gpt-auto also ignore fstab entries if 'fstab=no' is set in
the kernel command line.
This commit is contained in:
Yu Watanabe
2023-08-09 17:53:46 +09:00
parent 3787934b54
commit 1177373b6a
2 changed files with 35 additions and 0 deletions
+27
View File
@@ -13,15 +13,39 @@
#include "nulstr-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "proc-cmdline.h"
#include "string-util.h"
#include "strv.h"
bool fstab_enabled_full(int enabled) {
static int cached = -1;
bool val;
int r;
/* If 'enabled' is non-negative, then update the cache with it. */
if (enabled >= 0)
cached = enabled;
if (cached >= 0)
return cached;
r = proc_cmdline_get_bool("fstab", PROC_CMDLINE_STRIP_RD_PREFIX, &val);
if (r < 0)
log_debug_errno(r, "Failed to parse kernel command line, ignoring: %m");
/* If nothing specified, then defaults to true. */
return (cached = r > 0 ? val : true);
}
int fstab_has_fstype(const char *fstype) {
_cleanup_endmntent_ FILE *f = NULL;
struct mntent *m;
assert(fstype);
if (!fstab_enabled())
return false;
f = setmntent(fstab_path(), "re");
if (!f)
return errno == ENOENT ? false : -errno;
@@ -88,6 +112,9 @@ int fstab_is_mount_point_full(const char *where, const char *path) {
assert(where || path);
if (!fstab_enabled())
return false;
f = setmntent(fstab_path(), "re");
if (!f)
return errno == ENOENT ? false : -errno;
+8
View File
@@ -6,6 +6,14 @@
#include "macro.h"
bool fstab_enabled_full(int enabled);
static inline bool fstab_enabled(void) {
return fstab_enabled_full(-1);
}
static inline bool fstab_set_enabled(bool enabled) {
return fstab_enabled_full(enabled);
}
bool fstab_is_extrinsic(const char *mount, const char *opts);
int fstab_has_fstype(const char *fstype);