]> git.ipfire.org Git - thirdparty/systemd.git/commit
Rework file system group lookups 38340/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 25 Jul 2025 15:08:56 +0000 (17:08 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 27 Jul 2025 11:14:05 +0000 (13:14 +0200)
commitaca4353ab2b928e669e1b649a9f6987df1efb084
treebbdfa16255610095b805537538d27938406b0864
parentb0123576f4d2603e721e77932e8ed9b9e37b4a2e
Rework file system group lookups

We want to check if the magic we got from statfs() is one of the magics listed
for one of the file systems in the given group. To do this, we'd iteratate over
the file system names, convert each name to an array of magics, and compare
those to the one we got. We were using gperf-generated lookup table for this,
so the string lookups were quick, but still this seems unnecessarily complex.
Let's just generate a simple lookup function, because we can:

$ src/basic/filesystem-sets.py fs-in-group
bool fs_in_group(const struct statfs *st, FilesystemGroups fs_group) {
        switch (fs_group) {
        case FILESYSTEM_SET_BASIC_API:
                return F_TYPE_EQUAL(st->f_type, CGROUP2_SUPER_MAGIC)
                    || F_TYPE_EQUAL(st->f_type, CGROUP_SUPER_MAGIC)
                    || F_TYPE_EQUAL(st->f_type, DEVPTS_SUPER_MAGIC)
                    || F_TYPE_EQUAL(st->f_type, MQUEUE_MAGIC)
                    || F_TYPE_EQUAL(st->f_type, PROC_SUPER_MAGIC)
                    || F_TYPE_EQUAL(st->f_type, SYSFS_MAGIC)
                    || F_TYPE_EQUAL(st->f_type, TMPFS_MAGIC);
        case FILESYSTEM_SET_ANONYMOUS:
                return F_TYPE_EQUAL(st->f_type, ANON_INODE_FS_MAGIC)
                    || F_TYPE_EQUAL(st->f_type, PIPEFS_MAGIC)
                    || F_TYPE_EQUAL(st->f_type, SOCKFS_MAGIC);
...

We flatten the nested lookup of group=>fs=>magic into a single level.
The compiler can work its magic here to make the lookup quick.
src/basic/filesystem-sets.py
src/basic/filesystems.c
src/basic/meson.build