1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-06 08:26:52 +03:00

Support negated fstab options

We would ignore options like "fail" and "auto", and for any option
which takes a value the first assignment would win. Repeated and
options equivalent to the default are rarely used, but they have been
documented forever, and people might use them. Especially on the
kernel command line it is easier to append a repeated or negated
option at the end.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2015-01-11 00:04:00 -05:00
parent a6dba97829
commit b9f111b93f
5 changed files with 35 additions and 15 deletions

View File

@ -67,8 +67,8 @@ static int create_disk(
assert(name);
assert(device);
noauto = fstab_test_option(options, "noauto\0");
nofail = fstab_test_option(options, "nofail\0");
noauto = fstab_test_yes_no_option(options, "noauto\0" "auto\0");
nofail = fstab_test_yes_no_option(options, "nofail\0" "fail\0");
tmp = fstab_test_option(options, "tmp\0");
swap = fstab_test_option(options, "swap\0");

View File

@ -69,7 +69,7 @@ static int parse_one_option(const char *option) {
assert(option);
/* Handled outside of this tool */
if (streq(option, "noauto") || streq(option, "nofail"))
if (STR_IN_SET(option, "noauto", "auto", "nofail", "fail"))
return 0;
if (startswith(option, "cipher=")) {

View File

@ -135,17 +135,15 @@ static int add_swap(
static bool mount_is_network(struct mntent *me) {
assert(me);
return
hasmntopt(me, "_netdev") ||
fstype_is_network(me->mnt_type);
return fstab_test_option(me->mnt_opts, "_netdev\0") ||
fstype_is_network(me->mnt_type);
}
static bool mount_in_initrd(struct mntent *me) {
assert(me);
return
hasmntopt(me, "x-initrd.mount") ||
streq(me->mnt_dir, "/usr");
return fstab_test_option(me->mnt_opts, "x-initrd.mount\0") ||
streq(me->mnt_dir, "/usr");
}
static int add_mount(
@ -344,8 +342,8 @@ static int parse_fstab(bool initrd) {
if (is_path(where))
path_kill_slashes(where);
noauto = !!hasmntopt(me, "noauto");
nofail = !!hasmntopt(me, "nofail");
noauto = fstab_test_yes_no_option(me->mnt_opts, "noauto\0" "auto\0");
nofail = fstab_test_yes_no_option(me->mnt_opts, "nofail\0" "fail\0");
log_debug("Found entry what=%s where=%s type=%s nofail=%s noauto=%s",
what, where, me->mnt_type,
yes_no(noauto), yes_no(nofail));
@ -356,10 +354,9 @@ static int parse_fstab(bool initrd) {
bool automount;
const char *post;
automount =
hasmntopt(me, "comment=systemd.automount") ||
hasmntopt(me, "x-systemd.automount");
automount = fstab_test_option(me->mnt_opts,
"comment=systemd.automount\0"
"x-systemd.automount\0");
if (initrd)
post = SPECIAL_INITRD_FS_TARGET;
else if (mount_in_initrd(me))

View File

@ -23,6 +23,7 @@
#include <stdbool.h>
#include <stddef.h>
#include "macro.h"
int fstab_filter_options(const char *opts, const char *names,
const char **namefound, char **value, char **filtered);
@ -32,3 +33,16 @@ static inline bool fstab_test_option(const char *opts, const char *names) {
}
int fstab_find_pri(const char *options, int *ret);
static inline bool fstab_test_yes_no_option(const char *opts, const char *yes_no) {
int r;
const char *opt;
/* If first name given is last, return 1.
* If second name given is last or neither is found, return 0. */
r = fstab_filter_options(opts, yes_no, &opt, NULL, NULL);
assert(r >= 0);
return opt == yes_no;
}

View File

@ -107,6 +107,15 @@ static void test_fstab_filter_options(void) {
do_fstab_filter_options("", "opt\0", 0, NULL, NULL, "");
}
static void test_fstab_yes_no_option(void) {
assert_se(fstab_test_yes_no_option("nofail,fail,nofail", "nofail\0fail\0") == true);
assert_se(fstab_test_yes_no_option("nofail,nofail,fail", "nofail\0fail\0") == false);
assert_se(fstab_test_yes_no_option("abc,cde,afail", "nofail\0fail\0") == false);
assert_se(fstab_test_yes_no_option("nofail,fail=0,nofail=0", "nofail\0fail\0") == true);
assert_se(fstab_test_yes_no_option("nofail,nofail=0,fail=0", "nofail\0fail\0") == false);
}
int main(void) {
test_fstab_filter_options();
test_fstab_yes_no_option();
}