]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/libmount-util.c
cryptenroll: allow to use a public key on a token
[thirdparty/systemd.git] / src / shared / libmount-util.c
CommitLineData
08221c57
ZJS
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3#include <stdio.h>
4
5#include "libmount-util.h"
6
7int libmount_parse(
8 const char *path,
9 FILE *source,
10 struct libmnt_table **ret_table,
11 struct libmnt_iter **ret_iter) {
12
13 _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL;
14 _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL;
15 int r;
16
17 /* Older libmount seems to require this. */
18 assert(!source || path);
19
20 table = mnt_new_table();
21 iter = mnt_new_iter(MNT_ITER_FORWARD);
22 if (!table || !iter)
23 return -ENOMEM;
24
25 /* If source or path are specified, we use on the functions which ignore utab.
26 * Only if both are empty, we use mnt_table_parse_mtab(). */
27
28 if (source)
29 r = mnt_table_parse_stream(table, source, path);
30 else if (path)
31 r = mnt_table_parse_file(table, path);
32 else
33 r = mnt_table_parse_mtab(table, NULL);
34 if (r < 0)
35 return r;
36
37 *ret_table = TAKE_PTR(table);
38 *ret_iter = TAKE_PTR(iter);
39 return 0;
40}
6dc68a00
VD
41
42int libmount_is_leaf(
43 struct libmnt_table *table,
44 struct libmnt_fs *fs) {
45 int r;
46
47 _cleanup_(mnt_free_iterp) struct libmnt_iter *iter_children = NULL;
48 iter_children = mnt_new_iter(MNT_ITER_FORWARD);
49 if (!iter_children)
50 return log_oom();
51
52 /* We care only whether it exists, it is unused */
53 _unused_ struct libmnt_fs *child;
54 r = mnt_table_next_child_fs(table, iter_children, fs, &child);
55 if (r < 0)
56 return r;
57
58 return r == 1;
59}