1#!/usr/bin/env python3
2# SPDX-License-Identifier: LGPL-2.1-or-later
3
4import sys
5
6
7def filter_fsname(name):
8    # File system magics are sometimes not unique, because file systems got new
9    # revisions or got renamed. Let's prefer newer over older here, and thus
10    # ignore the old names.
11
12    return name in {
13        "cpuset",    # magic taken over by cgroupfs
14        "devtmpfs",  # not a file system of its own, but just a "named superblock" of tmpfs
15        "ext2",      # ext4 is the newest revision of ext2 + ext3
16        "ext3",
17        "fuseblk",   # closely related to fuse; they share a single magic, but the latter is more common
18        "gfs",       # magic taken over by gfs2
19        "msdos",     # vfat is the newest revision of msdos
20        "ncp",       # ncpfs (not ncp) was the last name of the netware `file_system_type`
21                     # name before it was removed in 2018
22        "nfs",       # nfs4 is the newest revision of nfs
23        "pvfs2",     # orangefs is the new name of pvfs2
24        "smb3",      # smb3 is an alias for cifs
25    }
26
27
28gperf_file = sys.argv[1]
29keywords_section = False
30
31for line in open(gperf_file):
32    if line[0] == "#":
33        continue
34
35    if keywords_section:
36        name, ids = line.split(",", 1)
37
38        name = name.strip()
39        if filter_fsname(name):
40            continue
41
42        ids = ids.strip()
43        assert ids[0] == "{"
44        assert ids[-1] == "}"
45        ids = ids[1:-1]
46
47        for id in ids.split(","):
48            print(f"case (statfs_f_type_t) {id.strip()}:")
49
50        print(f'        return "{name}";')
51
52    if line.startswith("%%"):
53        keywords_section = True
54