meson: rework generation of file system lookup helpers

Previously, the gperf table was the main "source of truth", and additional
information (e.g. which file system names are obsolete) was scattered in
various files. We would then parse the gperf file, using python, awk, grep, and
bash, and use the results in various ways. This is hard to understand and
maintain. Let's replace all of this with a single python script that generates
the requested outputs as appropriate.

$ diff -u <(git show @{u}:src/basic/filesystems-gperf.gperf) \
          <(src/basic/filesystem-sets.py gperf)
shows that the outputs are the same except for comments.

Similarly, 'src/basic/filesystem-sets.py fs-type-to-string' and
'src/basic/filesystem-sets.py filesystem-sets' can be used to view
the generated code.

The check that the kernel doesn't define any new file system magics is
converted into a normal test. It doesn't seem necessary to fail the build
when that happens.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-07-27 13:13:54 +02:00
parent c136be3f04
commit b0123576f4
7 changed files with 373 additions and 389 deletions
+1 -126
View File
@@ -5,15 +5,6 @@
#include "stat-util.h"
#include "string-util.h"
const char* fs_type_to_string(statfs_f_type_t magic) {
switch (magic) {
#include "filesystem-switch-case.inc"
}
return NULL;
}
int fs_type_from_string(const char *name, const statfs_f_type_t **ret) {
const struct FilesystemMagic *fs_magic;
@@ -48,123 +39,7 @@ bool fs_in_group(const struct statfs *s, FilesystemGroups fs_group) {
return false;
}
const FilesystemSet filesystem_sets[_FILESYSTEM_SET_MAX] = {
[FILESYSTEM_SET_BASIC_API] = {
.name = "@basic-api",
.help = "Basic filesystem API",
.value =
"cgroup\0"
"cgroup2\0"
"devpts\0"
"devtmpfs\0"
"mqueue\0"
"proc\0"
"sysfs\0"
},
[FILESYSTEM_SET_ANONYMOUS] = {
.name = "@anonymous",
.help = "Anonymous inodes",
.value =
"anon_inodefs\0"
"pipefs\0"
"sockfs\0"
},
[FILESYSTEM_SET_APPLICATION] = {
.name = "@application",
.help = "Application virtual filesystems",
.value =
"autofs\0"
"fuse\0"
"overlay\0"
},
[FILESYSTEM_SET_AUXILIARY_API] = {
.name = "@auxiliary-api",
.help = "Auxiliary filesystem API",
.value =
"binfmt_misc\0"
"configfs\0"
"efivarfs\0"
"fusectl\0"
"hugetlbfs\0"
"rpc_pipefs\0"
"securityfs\0"
},
[FILESYSTEM_SET_COMMON_BLOCK] = {
.name = "@common-block",
.help = "Common block device filesystems",
.value =
"btrfs\0"
"erofs\0"
"exfat\0"
"ext4\0"
"f2fs\0"
"iso9660\0"
"ntfs3\0"
"squashfs\0"
"udf\0"
"vfat\0"
"xfs\0"
},
[FILESYSTEM_SET_HISTORICAL_BLOCK] = {
.name = "@historical-block",
.help = "Historical block device filesystems",
.value =
"ext2\0"
"ext3\0"
"minix\0"
},
[FILESYSTEM_SET_NETWORK] = {
.name = "@network",
.help = "Well-known network filesystems",
.value =
"afs\0"
"ceph\0"
"cifs\0"
"gfs\0"
"gfs2\0"
"ncp\0"
"ncpfs\0"
"nfs\0"
"nfs4\0"
"ocfs2\0"
"orangefs\0"
"pvfs2\0"
"smb3\0"
"smbfs\0"
},
[FILESYSTEM_SET_PRIVILEGED_API] = {
.name = "@privileged-api",
.help = "Privileged filesystem API",
.value =
"bpf\0"
"debugfs\0"
"pstore\0"
"tracefs\0"
},
[FILESYSTEM_SET_SECURITY] = {
.name = "@security",
.help = "Security/MAC API VFS",
.value =
"apparmorfs\0"
"selinuxfs\0"
"smackfs\0"
},
[FILESYSTEM_SET_TEMPORARY] = {
.name = "@temporary",
.help = "Temporary filesystems",
.value =
"ramfs\0"
"tmpfs\0"
},
[FILESYSTEM_SET_KNOWN] = {
.name = "@known",
.help = "All known filesystems declared in the kernel",
.value =
#include "filesystem-list.inc"
},
};
const FilesystemSet *filesystem_set_find(const char *name) {
const FilesystemSet* filesystem_set_find(const char *name) {
if (isempty(name) || name[0] != '@')
return NULL;