]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/fstab-util.c
20fb0f5a065256ba2c2b9ec391da52491f26ab58
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2015 Zbigniew Jędrzejewski-Szmek
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 #include "fstab-util.h"
23 #include "parse-util.h"
24 #include "path-util.h"
25 #include "string-util.h"
29 bool fstab_is_mount_point(const char *mount
) {
30 _cleanup_endmntent_
FILE *f
= NULL
;
33 f
= setmntent("/etc/fstab", "r");
37 while ((m
= getmntent(f
)))
38 if (path_equal(m
->mnt_dir
, mount
))
44 int fstab_filter_options(const char *opts
, const char *names
,
45 const char **namefound
, char **value
, char **filtered
) {
46 const char *name
, *n
= NULL
, *x
;
47 _cleanup_strv_free_
char **stor
= NULL
;
48 _cleanup_free_
char *v
= NULL
, **strv
= NULL
;
50 assert(names
&& *names
);
55 /* If !value and !filtered, this function is not allowed to fail. */
58 const char *word
, *state
;
61 FOREACH_WORD_SEPARATOR(word
, l
, opts
, ",", state
)
62 NULSTR_FOREACH(name
, names
) {
65 if (!strneq(word
, name
, strlen(name
)))
68 /* we know that the string is NUL
69 * terminated, so *x is valid */
70 x
= word
+ strlen(name
);
71 if (IN_SET(*x
, '\0', '=', ',')) {
75 if (IN_SET(*x
, '\0', ','))
80 v
= strndup(x
, l
- strlen(name
) - 1);
90 stor
= strv_split(opts
, ",");
93 strv
= memdup(stor
, sizeof(char*) * (strv_length(stor
) + 1));
97 for (s
= t
= strv
; *s
; s
++) {
98 NULSTR_FOREACH(name
, names
) {
99 x
= startswith(*s
, name
);
100 if (x
&& IN_SET(*x
, '\0', '='))
108 /* Keep the last occurence found */
132 f
= strv_join(strv
, ",");
146 int fstab_extract_values(const char *opts
, const char *name
, char ***values
) {
147 _cleanup_strv_free_
char **optsv
= NULL
, **res
= NULL
;
154 optsv
= strv_split(opts
, ",");
158 STRV_FOREACH(s
, optsv
) {
162 arg
= startswith(*s
, name
);
163 if (!arg
|| *arg
!= '=')
165 r
= strv_extend(&res
, arg
+ 1);
176 int fstab_find_pri(const char *options
, int *ret
) {
177 _cleanup_free_
char *opt
= NULL
;
183 r
= fstab_filter_options(options
, "pri\0", NULL
, &opt
, NULL
);
189 r
= safe_atou(opt
, &pri
);