summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/mount.c24
-rw-r--r--src/core/swap.c71
2 files changed, 12 insertions, 83 deletions
diff --git a/src/core/mount.c b/src/core/mount.c
index 13c634807b..a551235f13 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -44,6 +44,7 @@
#include "bus-common-errors.h"
#include "exit-status.h"
#include "def.h"
+#include "fstab-util.h"
#define RETRY_UMOUNT_MAX 32
@@ -70,7 +71,7 @@ static int mount_dispatch_timer(sd_event_source *source, usec_t usec, void *user
static int mount_dispatch_io(sd_event_source *source, int fd, uint32_t revents, void *userdata);
static bool mount_needs_network(const char *options, const char *fstype) {
- if (mount_test_option(options, "_netdev"))
+ if (fstab_test_option(options, "_netdev\0"))
return true;
if (fstype && fstype_is_network(fstype))
@@ -88,16 +89,10 @@ static bool mount_is_network(const MountParameters *p) {
static bool mount_is_bind(const MountParameters *p) {
assert(p);
- if (mount_test_option(p->options, "bind"))
+ if (fstab_test_option(p->options, "bind\0" "rbind\0"))
return true;
- if (p->fstype && streq(p->fstype, "bind"))
- return true;
-
- if (mount_test_option(p->options, "rbind"))
- return true;
-
- if (p->fstype && streq(p->fstype, "rbind"))
+ if (p->fstype && STR_IN_SET(p->fstype, "bind", "rbind"))
return true;
return false;
@@ -106,7 +101,7 @@ static bool mount_is_bind(const MountParameters *p) {
static bool mount_is_auto(const MountParameters *p) {
assert(p);
- return !mount_test_option(p->options, "noauto");
+ return !fstab_test_option(p->options, "noauto\0");
}
static bool needs_quota(const MountParameters *p) {
@@ -118,11 +113,8 @@ static bool needs_quota(const MountParameters *p) {
if (mount_is_bind(p))
return false;
- return mount_test_option(p->options, "usrquota") ||
- mount_test_option(p->options, "grpquota") ||
- mount_test_option(p->options, "quota") ||
- mount_test_option(p->options, "usrjquota") ||
- mount_test_option(p->options, "grpjquota");
+ return fstab_test_option(p->options,
+ "usrquota\0" "grpquota\0" "quota\0" "usrjquota\0" "grpjquota\0");
}
static void mount_init(Unit *u) {
@@ -369,7 +361,7 @@ static bool should_umount(Mount *m) {
return false;
p = get_mount_parameters(m);
- if (p && mount_test_option(p->options, "x-initrd.mount") &&
+ if (p && fstab_test_option(p->options, "x-initrd.mount\0") &&
!in_initrd())
return false;
diff --git a/src/core/swap.c b/src/core/swap.c
index cb19d0f123..b2ebed4b72 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -41,6 +41,7 @@
#include "path-util.h"
#include "virt.h"
#include "udev-util.h"
+#include "fstab-util.h"
static const UnitActiveState state_translation_table[_SWAP_STATE_MAX] = {
[SWAP_DEAD] = UNIT_INACTIVE,
@@ -704,71 +705,6 @@ fail:
swap_enter_dead(s, SWAP_FAILURE_RESOURCES);
}
-static int mount_find_pri(const char *options, int *ret) {
- const char *opt;
- char *end;
- unsigned long r;
-
- assert(ret);
-
- if (!options)
- return 0;
-
- opt = mount_test_option(options, "pri");
- if (!opt)
- return 0;
-
- opt += strlen("pri");
- if (*opt != '=')
- return -EINVAL;
-
- errno = 0;
- r = strtoul(opt + 1, &end, 10);
- if (errno > 0)
- return -errno;
-
- if (end == opt + 1 || (*end != ',' && *end != 0))
- return -EINVAL;
-
- *ret = (int) r;
- return 1;
-}
-
-static int mount_find_discard(const char *options, char **ret) {
- const char *opt;
- char *ans;
- size_t len;
-
- assert(ret);
-
- if (!options)
- return 0;
-
- opt = mount_test_option(options, "discard");
- if (!opt)
- return 0;
-
- opt += strlen("discard");
- if (*opt == ',' || *opt == '\0')
- ans = strdup("all");
- else {
- if (*opt != '=')
- return -EINVAL;
-
- len = strcspn(opt + 1, ",");
- if (len == 0)
- return -EINVAL;
-
- ans = strndup(opt + 1, len);
- }
-
- if (!ans)
- return -ENOMEM;
-
- *ret = ans;
- return 1;
-}
-
static void swap_enter_activating(Swap *s) {
_cleanup_free_ char *discard = NULL;
int r, priority = -1;
@@ -779,11 +715,12 @@ static void swap_enter_activating(Swap *s) {
s->control_command = s->exec_command + SWAP_EXEC_ACTIVATE;
if (s->from_fragment) {
- mount_find_discard(s->parameters_fragment.options, &discard);
+ fstab_filter_options(s->parameters_fragment.options, "discard\0",
+ NULL, &discard, NULL);
priority = s->parameters_fragment.priority;
if (priority < 0)
- mount_find_pri(s->parameters_fragment.options, &priority);
+ fstab_find_pri(s->parameters_fragment.options, &priority);
}
r = exec_command_set(s->control_command, "/sbin/swapon", NULL);