]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/filesystems.c
nulstr-util: Declare NULSTR_FOREACH() iterator inline
[thirdparty/systemd.git] / src / basic / filesystems.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "filesystems-gperf.h"
4 #include "stat-util.h"
5
6 const char *fs_type_to_string(statfs_f_type_t magic) {
7
8 switch (magic) {
9 #include "filesystem-switch-case.h"
10 }
11
12 return NULL;
13 }
14
15
16 int fs_type_from_string(const char *name, const statfs_f_type_t **ret) {
17 const struct FilesystemMagic *fs_magic;
18
19 assert(name);
20 assert(ret);
21
22 fs_magic = filesystems_gperf_lookup(name, strlen(name));
23 if (!fs_magic)
24 return -EINVAL;
25
26 *ret = fs_magic->magic;
27 return 0;
28 }
29
30 bool fs_in_group(const struct statfs *s, FilesystemGroups fs_group) {
31 int r;
32
33 NULSTR_FOREACH(fs, filesystem_sets[fs_group].value) {
34 const statfs_f_type_t *magic;
35
36 r = fs_type_from_string(fs, &magic);
37 if (r >= 0)
38 for (size_t i = 0; i < FILESYSTEM_MAGIC_MAX; i++) {
39 if (magic[i] == 0)
40 break;
41
42 if (is_fs_type(s, magic[i]))
43 return true;
44 }
45 }
46
47 return false;
48 }
49
50 const FilesystemSet filesystem_sets[_FILESYSTEM_SET_MAX] = {
51 [FILESYSTEM_SET_BASIC_API] = {
52 .name = "@basic-api",
53 .help = "Basic filesystem API",
54 .value =
55 "cgroup\0"
56 "cgroup2\0"
57 "devpts\0"
58 "devtmpfs\0"
59 "mqueue\0"
60 "proc\0"
61 "sysfs\0"
62 },
63 [FILESYSTEM_SET_ANONYMOUS] = {
64 .name = "@anonymous",
65 .help = "Anonymous inodes",
66 .value =
67 "anon_inodefs\0"
68 "pipefs\0"
69 "sockfs\0"
70 },
71 [FILESYSTEM_SET_APPLICATION] = {
72 .name = "@application",
73 .help = "Application virtual filesystems",
74 .value =
75 "autofs\0"
76 "fuse\0"
77 "overlay\0"
78 },
79 [FILESYSTEM_SET_AUXILIARY_API] = {
80 .name = "@auxiliary-api",
81 .help = "Auxiliary filesystem API",
82 .value =
83 "binfmt_misc\0"
84 "configfs\0"
85 "efivarfs\0"
86 "fusectl\0"
87 "hugetlbfs\0"
88 "rpc_pipefs\0"
89 "securityfs\0"
90 },
91 [FILESYSTEM_SET_COMMON_BLOCK] = {
92 .name = "@common-block",
93 .help = "Common block device filesystems",
94 .value =
95 "btrfs\0"
96 "erofs\0"
97 "exfat\0"
98 "ext4\0"
99 "f2fs\0"
100 "iso9660\0"
101 "ntfs3\0"
102 "squashfs\0"
103 "udf\0"
104 "vfat\0"
105 "xfs\0"
106 },
107 [FILESYSTEM_SET_HISTORICAL_BLOCK] = {
108 .name = "@historical-block",
109 .help = "Historical block device filesystems",
110 .value =
111 "ext2\0"
112 "ext3\0"
113 "minix\0"
114 },
115 [FILESYSTEM_SET_NETWORK] = {
116 .name = "@network",
117 .help = "Well-known network filesystems",
118 .value =
119 "afs\0"
120 "ceph\0"
121 "cifs\0"
122 "gfs\0"
123 "gfs2\0"
124 "ncp\0"
125 "ncpfs\0"
126 "nfs\0"
127 "nfs4\0"
128 "ocfs2\0"
129 "orangefs\0"
130 "pvfs2\0"
131 "smb3\0"
132 "smbfs\0"
133 },
134 [FILESYSTEM_SET_PRIVILEGED_API] = {
135 .name = "@privileged-api",
136 .help = "Privileged filesystem API",
137 .value =
138 "bpf\0"
139 "debugfs\0"
140 "pstore\0"
141 "tracefs\0"
142 },
143 [FILESYSTEM_SET_SECURITY] = {
144 .name = "@security",
145 .help = "Security/MAC API VFS",
146 .value =
147 "apparmorfs\0"
148 "selinuxfs\0"
149 "smackfs\0"
150 },
151 [FILESYSTEM_SET_TEMPORARY] = {
152 .name = "@temporary",
153 .help = "Temporary filesystems",
154 .value =
155 "ramfs\0"
156 "tmpfs\0"
157 },
158 [FILESYSTEM_SET_KNOWN] = {
159 .name = "@known",
160 .help = "All known filesystems declared in the kernel",
161 .value =
162 #include "filesystem-list.h"
163 },
164 };
165
166 const FilesystemSet *filesystem_set_find(const char *name) {
167 if (isempty(name) || name[0] != '@')
168 return NULL;
169
170 for (FilesystemGroups i = 0; i < _FILESYSTEM_SET_MAX; i++)
171 if (streq(filesystem_sets[i].name, name))
172 return filesystem_sets + i;
173
174 return NULL;
175 }