diff --git a/src/basic/filesystem-sets.py b/src/basic/filesystem-sets.py index d374ac41ff..7cf73aaefb 100755 --- a/src/basic/filesystem-sets.py +++ b/src/basic/filesystem-sets.py @@ -297,6 +297,23 @@ const char* fs_type_to_string(statfs_f_type_t magic) { return NULL; }""") +def generate_fs_in_group(): + print('bool fs_in_group(const struct statfs *st, FilesystemGroups fs_group) {') + print(' switch (fs_group) {') + + for name, _, *filesystems in FILESYSTEM_SETS: + magics = sorted(set(sum((NAME_TO_MAGIC[fs] for fs in filesystems), + start=[]))) + enum = 'FILESYSTEM_SET_' + name[1:].upper().replace('-', '_') + print(f' case {enum}:') + opts = '\n || '.join(f'F_TYPE_EQUAL(st->f_type, {magic})' + for magic in magics) + print(f' return {opts};') + + print(' default: assert_not_reached();') + print(' }') + print('}') + def generate_filesystem_sets(): print('const FilesystemSet filesystem_sets[_FILESYSTEM_SET_MAX] = {') @@ -346,6 +363,8 @@ if __name__ == '__main__': generate_fs_type_to_string() elif arg == 'filesystem-sets': generate_filesystem_sets() + elif arg == 'fs-in-group': + generate_fs_in_group() elif arg == 'check': check() else: diff --git a/src/basic/filesystems.c b/src/basic/filesystems.c index 2bbab151bb..cd2789e329 100644 --- a/src/basic/filesystems.c +++ b/src/basic/filesystems.c @@ -19,26 +19,6 @@ int fs_type_from_string(const char *name, const statfs_f_type_t **ret) { return 0; } -bool fs_in_group(const struct statfs *s, FilesystemGroups fs_group) { - int r; - - NULSTR_FOREACH(fs, filesystem_sets[fs_group].value) { - const statfs_f_type_t *magic; - - r = fs_type_from_string(fs, &magic); - if (r >= 0) - for (size_t i = 0; i < FILESYSTEM_MAGIC_MAX; i++) { - if (magic[i] == 0) - break; - - if (is_fs_type(s, magic[i])) - return true; - } - } - - return false; -} - const FilesystemSet* filesystem_set_find(const char *name) { if (isempty(name) || name[0] != '@') return NULL; diff --git a/src/basic/meson.build b/src/basic/meson.build index 6589ce2995..79af468381 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -173,7 +173,8 @@ filesystem_sets_c = custom_target( output : 'filesystem-sets.c', command : [filesystem_sets_py, 'fs-type-to-string', - 'filesystem-sets'], + 'filesystem-sets', + 'fs-in-group'], capture : true) filesystems_gperf_gperf = custom_target(