gpt-auto-generator: be more defensive when checking the presence of ESP in fstab

Looking for the ESP node is useful to shortcut things but if we're told that
the node is not referenced in fstab that doesn't necessarily mean that ESP is
not mounted via fstab. Indeed the check is not reliable in all cases. Firstly
because it assumes that udev already set the symlinks up. This is not the case
for initrd-less boots. Secondly the devname of the ESP partition can be wrongly
constructed by the dissect code. For example, the approach which consists in
appending "p<partnum>" suffix to construct the partition devname from the disk
devname doesn't work for DM devices.

Hence this patch makes the logic more defensive and do not mount neither ESP
nor XBOOTLDR automatically if any path in paths that starts with /efi or /boot
exists.
This commit is contained in:
Franck Bui
2024-02-12 09:30:35 +01:00
parent de39202426
commit 8a1326581d
4 changed files with 55 additions and 52 deletions
+28
View File
@@ -105,6 +105,34 @@ static int fstab_is_same_node(const char *what_fstab, const char *path) {
return false;
}
int fstab_has_mount_point_prefix_strv(char **prefixes) {
_cleanup_endmntent_ FILE *f = NULL;
assert(prefixes);
/* This function returns true if at least one entry in fstab has a mount point that starts with one
* of the passed prefixes. */
if (!fstab_enabled())
return false;
f = setmntent(fstab_path(), "re");
if (!f)
return errno == ENOENT ? false : -errno;
for (;;) {
struct mntent *me;
errno = 0;
me = getmntent(f);
if (!me)
return errno != 0 ? -errno : false;
if (path_startswith_strv(me->mnt_dir, prefixes))
return true;
}
}
int fstab_is_mount_point_full(const char *where, const char *path) {
_cleanup_endmntent_ FILE *f = NULL;
int r;