filesystems: add internal APIs to convert fs magic to name
We previously had tooling for the opposite direction, let's complete the work.
This commit is contained in:
+11
-1
@@ -1,6 +1,17 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include "filesystems-gperf.h"
|
||||
#include "stat-util.h"
|
||||
|
||||
const char *fs_type_to_string(statfs_f_type_t magic) {
|
||||
|
||||
switch (magic) {
|
||||
#include "filesystem-switch-case.h"
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int fs_type_from_string(const char *name, const statfs_f_type_t **ret) {
|
||||
const struct FilesystemMagic *fs_magic;
|
||||
@@ -13,7 +24,6 @@ int fs_type_from_string(const char *name, const statfs_f_type_t **ret) {
|
||||
return -EINVAL;
|
||||
|
||||
*ret = fs_magic->magic;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ extern const FilesystemSet filesystem_sets[];
|
||||
|
||||
const FilesystemSet *filesystem_set_find(const char *name);
|
||||
|
||||
const char *fs_type_to_string(statfs_f_type_t magic);
|
||||
int fs_type_from_string(const char *name, const statfs_f_type_t **ret);
|
||||
int fs_in_group(const struct statfs *s, enum FilesystemGroups fs_group);
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@ import sys
|
||||
keywords_section = False
|
||||
|
||||
for line in open(sys.argv[1]):
|
||||
if line[0] == '#':
|
||||
continue
|
||||
|
||||
if keywords_section:
|
||||
print('"{}\\0"'.format(line.split(',')[0].strip()))
|
||||
elif line.startswith('%%'):
|
||||
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def filter_fsname(name):
|
||||
# File system magics are sometimes not unique, because file systems got new
|
||||
# revisions or got renamed. Let's prefer newer over older here, and thus
|
||||
# ignore the old names. Specifically:
|
||||
#
|
||||
# → cgroupfs took over the magic of cpuset
|
||||
# → devtmpfs is not a file system of its own, but just a "named superblock" of tmpfs
|
||||
# → ext4 is the newest revision of ext2 + ext3
|
||||
# → fuseblk is closely related to fuse, so close that they share a single magic, but the latter is more common
|
||||
# → gfs2 is the newest revision of gfs
|
||||
# → vfat is the newest revision of msdos
|
||||
# → ncpfs (not ncp) was the last name of the netware `file_system_type` name before it was removed in 2018
|
||||
# → nfs4 is the newest revision of nfs
|
||||
# → orangefs is the new name of pvfs2
|
||||
# → smb3 is an alias for cifs
|
||||
|
||||
return name in (
|
||||
"cpuset",
|
||||
"devtmpfs",
|
||||
"ext2",
|
||||
"ext3",
|
||||
"fuseblk",
|
||||
"gfs",
|
||||
"msdos",
|
||||
"ncp",
|
||||
"nfs",
|
||||
"pvfs2",
|
||||
"smb3",
|
||||
)
|
||||
|
||||
|
||||
gperf_file = sys.argv[1]
|
||||
keywords_section = False
|
||||
|
||||
for line in open(gperf_file):
|
||||
if line[0] == "#":
|
||||
continue
|
||||
|
||||
if keywords_section:
|
||||
name, ids = line.split(",", 1)
|
||||
|
||||
name = name.strip()
|
||||
if filter_fsname(name):
|
||||
continue
|
||||
|
||||
ids = ids.strip()
|
||||
assert ids[0] == "{"
|
||||
assert ids[-1] == "}"
|
||||
ids = ids[1:-1]
|
||||
|
||||
for id in ids.split(","):
|
||||
print(f"case (statfs_f_type_t) {id.strip()}:")
|
||||
|
||||
print(f' return "{name}";')
|
||||
|
||||
if line.startswith("%%"):
|
||||
keywords_section = True
|
||||
+13
-3
@@ -383,8 +383,8 @@ filesystem_includes = ['linux/magic.h',
|
||||
check_filesystems = find_program('check-filesystems.sh')
|
||||
r = run_command([check_filesystems, cpp, 'filesystems-gperf.gperf'] + filesystem_includes)
|
||||
if r.returncode() != 0
|
||||
error('found unknown filesystem(s) defined in kernel headers:\n\n' + r.stdout())
|
||||
r.stdout()
|
||||
error('found unknown filesystem(s) defined in kernel headers:\n\n' + r.stdout())
|
||||
r.stdout()
|
||||
endif
|
||||
|
||||
filesystems_gperf_h = custom_target(
|
||||
@@ -403,7 +403,17 @@ filesystem_list_h = custom_target(
|
||||
'@INPUT@'],
|
||||
capture : true)
|
||||
|
||||
basic_sources += [filesystem_list_h, filesystems_gperf_h]
|
||||
generate_filesystem_switch_case_h = find_program('generate-filesystem-switch-case.py')
|
||||
fname = 'filesystem-switch-case.h'
|
||||
filesystem_switch_case_h = custom_target(
|
||||
fname,
|
||||
input : 'filesystems-gperf.gperf',
|
||||
output : 'filesystem-switch-case.h',
|
||||
command : [generate_filesystem_switch_case_h,
|
||||
'@INPUT@'],
|
||||
capture : true)
|
||||
|
||||
basic_sources += [filesystem_list_h, filesystem_switch_case_h, filesystems_gperf_h]
|
||||
|
||||
libbasic = static_library(
|
||||
'basic',
|
||||
|
||||
Reference in New Issue
Block a user