Merge pull request #21373 from poettering/filesystems-more-groups

some file system tables/magic love
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-11-16 10:27:21 +01:00
committed by GitHub
11 changed files with 229 additions and 36 deletions
+20 -1
View File
@@ -34,8 +34,11 @@ binfmt_misc, {BINFMTFS_MAGIC}
bpf, {BPF_FS_MAGIC}
btrfs, {BTRFS_SUPER_MAGIC}
btrfs_test_fs, {BTRFS_TEST_MAGIC}
# cpuset's magic got reassigned to cgroupfs
cpuset, {CGROUP_SUPER_MAGIC}
ceph, {CEPH_SUPER_MAGIC}
cgroup2, {CGROUP2_SUPER_MAGIC}
# note that the cgroupfs magic got reassigned from cpuset
cgroup, {CGROUP_SUPER_MAGIC}
cifs, {CIFS_MAGIC_NUMBER}
coda, {CODA_SUPER_MAGIC}
@@ -45,19 +48,24 @@ dax, {DAXFS_MAGIC}
debugfs, {DEBUGFS_MAGIC}
devmem, {DEVMEM_MAGIC}
devpts, {DEVPTS_SUPER_MAGIC}
# devtmpfs is just a special instance of tmpfs, hence it reports its magic
devtmpfs, {TMPFS_MAGIC}
dmabuf, {DMA_BUF_MAGIC}
ecryptfs, {ECRYPTFS_SUPER_MAGIC}
efivarfs, {EFIVARFS_MAGIC}
efs, {EFS_SUPER_MAGIC}
erofs, {EROFS_SUPER_MAGIC_V1}
# ext2 + ext3 + ext4 use the same magic
ext2, {EXT2_SUPER_MAGIC}
ext3, {EXT3_SUPER_MAGIC}
ext4, {EXT4_SUPER_MAGIC}
exfat, {EXFAT_SUPER_MAGIC}
f2fs, {F2FS_SUPER_MAGIC}
# fuseblk is so closely related to fuse that it shares the same magic
fuseblk, {FUSE_SUPER_MAGIC}
fuse, {FUSE_SUPER_MAGIC}
fusectl, {FUSE_CTL_SUPER_MAGIC}
# gfs is an old version of gfs2 and reuses the magic
gfs, {GFS2_MAGIC}
gfs2, {GFS2_MAGIC}
hostfs, {HOSTFS_SUPER_MAGIC}
@@ -67,13 +75,18 @@ iso9660, {ISOFS_SUPER_MAGIC}
jffs2, {JFFS2_SUPER_MAGIC}
minix, {MINIX_SUPER_MAGIC, MINIX_SUPER_MAGIC2, MINIX2_SUPER_MAGIC, MINIX2_SUPER_MAGIC2, MINIX3_SUPER_MAGIC}
mqueue, {MQUEUE_MAGIC}
# msdos is an older legacy version of vfat, shares the magic
msdos, {MSDOS_SUPER_MAGIC}
# ncp/ncpfs have been removed from the kernel, but ncpfs was the offical name
ncp, {NCP_SUPER_MAGIC}
ncpfs, {NCP_SUPER_MAGIC}
# nfs is the old version of nfs4, and they share the same magic
nfs, {NFS_SUPER_MAGIC}
nfs4, {NFS_SUPER_MAGIC}
nilfs2, {NILFS_SUPER_MAGIC}
nsfs, {NSFS_MAGIC}
ntfs, {NTFS_SB_MAGIC}
ntfs3, {NTFS3_SUPER_MAGIC}
ocfs2, {OCFS2_SUPER_MAGIC}
openpromfs, {OPENPROM_SUPER_MAGIC}
orangefs, {ORANGEFS_DEVREQ_MAGIC}
@@ -82,27 +95,33 @@ pipefs, {PIPEFS_MAGIC}
ppc-cmm, {PPC_CMM_MAGIC}
proc, {PROC_SUPER_MAGIC}
pstore, {PSTOREFS_MAGIC}
# pvfs2 is the old version of orangefs
pvfs2, {ORANGEFS_DEVREQ_MAGIC}
qnx4, {QNX4_SUPER_MAGIC}
qnx6, {QNX6_SUPER_MAGIC}
ramfs, {RAMFS_MAGIC}
resctrl, {RDTGROUP_SUPER_MAGIC}
reiserfs, {REISERFS_SUPER_MAGIC}
rpc_pipefs, {RPC_PIPEFS_SUPER_MAGIC}
secretmem, {SECRETMEM_MAGIC}
securityfs, {SECURITYFS_MAGIC}
selinuxfs, {SELINUX_MAGIC}
shiftfs, {SHIFTFS_MAGIC}
smackfs, {SMACK_MAGIC}
smb3, {SMB_SUPER_MAGIC}
# smb3 is an alias for cifs
smb3, {CIFS_MAGIC_NUMBER}
# smbfs was removed from the kernel in 2010, the magic remains
smbfs, {SMB_SUPER_MAGIC}
sockfs, {SOCKFS_MAGIC}
squashfs, {SQUASHFS_MAGIC}
sysfs, {SYSFS_MAGIC}
# note that devtmpfs shares the same magic with tmpfs, given it is just a special named instance of it.
tmpfs, {TMPFS_MAGIC}
tracefs, {TRACEFS_MAGIC}
udf, {UDF_SUPER_MAGIC}
usbdevfs, {USBDEVICE_SUPER_MAGIC}
vboxsf, {VBOXSF_SUPER_MAGIC}
# note that msdos shares the same magic (and is the older version)
vfat, {MSDOS_SUPER_MAGIC}
v9fs, {V9FS_MAGIC}
xenfs, {XENFS_SUPER_MAGIC}
+48 -2
View File
@@ -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;
}
@@ -47,18 +57,37 @@ const FilesystemSet filesystem_sets[_FILESYSTEM_SET_MAX] = {
"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] = {
@@ -66,7 +95,14 @@ const FilesystemSet filesystem_sets[_FILESYSTEM_SET_MAX] = {
.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"
},
@@ -83,14 +119,16 @@ const FilesystemSet filesystem_sets[_FILESYSTEM_SET_MAX] = {
.help = "Well-known network filesystems",
.value =
"afs\0"
"ceph\0"
"cifs\0"
"gfs\0"
"gfs2\0"
"ncpfs\0"
"ncp\0"
"ncpfs\0"
"nfs\0"
"nfs4\0"
"ocfs2\0"
"orangefs\0"
"pvfs2\0"
"smb3\0"
"smbfs\0"
@@ -104,6 +142,14 @@ const FilesystemSet filesystem_sets[_FILESYSTEM_SET_MAX] = {
"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",
+4
View File
@@ -10,11 +10,14 @@
typedef enum FilesystemGroups {
/* Please leave BASIC_API first and KNOWN last, but sort the rest alphabetically */
FILESYSTEM_SET_BASIC_API,
FILESYSTEM_SET_ANONYMOUS,
FILESYSTEM_SET_APPLICATION,
FILESYSTEM_SET_AUXILIARY_API,
FILESYSTEM_SET_COMMON_BLOCK,
FILESYSTEM_SET_HISTORICAL_BLOCK,
FILESYSTEM_SET_NETWORK,
FILESYSTEM_SET_PRIVILEGED_API,
FILESYSTEM_SET_SECURITY,
FILESYSTEM_SET_TEMPORARY,
FILESYSTEM_SET_KNOWN,
_FILESYSTEM_SET_MAX,
@@ -31,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);
+3
View File
@@ -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('%%'):
+63
View File
@@ -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
View File
@@ -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',
+15
View File
@@ -172,3 +172,18 @@
#ifndef EXFAT_SUPER_MAGIC
#define EXFAT_SUPER_MAGIC 0x2011BAB0UL
#endif
/* Not exposed yet, internally actually called RPCAUTH_GSSMAGIC. Defined in net/sunrpc/rpc_pipe.c */
#ifndef RPC_PIPEFS_SUPER_MAGIC
#define RPC_PIPEFS_SUPER_MAGIC 0x67596969
#endif
/* Not exposed yet, defined at fs/ntfs/ntfs.h */
#ifndef NTFS_SB_MAGIC
#define NTFS_SB_MAGIC 0x5346544e
#endif
/* Not exposed yet, encoded literally in fs/ntfs3/super.c. */
#ifndef NTFS3_SUPER_MAGIC
#define NTFS3_SUPER_MAGIC 0x7366746e
#endif
+1 -2
View File
@@ -373,7 +373,6 @@ bool fstype_is_network(const char *fstype) {
/* Filesystems not present in the internal database */
return STR_IN_SET(fstype,
"ceph",
"davfs",
"glusterfs",
"lustre",
@@ -412,8 +411,8 @@ bool fstype_is_ro(const char *fstype) {
/* All Linux file systems that are necessarily read-only */
return STR_IN_SET(fstype,
"DM_verity_hash",
"iso9660",
"erofs",
"iso9660",
"squashfs");
}