Create a pseudo filesystem with init_pseudo
Create a tiny in-kernel filesystem for internal files with init_pseudo and kern_mount on Linux 6.12, the way sockfs and pipefs are built.
Some kernel objects need inodes but no mount point that users see. A pseudo filesystem gives you a superblock with almost no code, and init_pseudo sets up the context for it.
#define DEMO_MAGIC 0x44454d4fUL
static int demo_init_fs_context(struct fs_context *fc)
{
struct pseudo_fs_context *ctx = init_pseudo(fc, DEMO_MAGIC);
if (!ctx)
return -ENOMEM;
return 0;
}
static struct file_system_type demo_fs_type = {
.name = "demofs",
.init_fs_context = demo_init_fs_context,
.kill_sb = kill_anon_super,
};grep demofs /proc/filesystemsnodev demofsAfter register_filesystem(&demo_fs_type), the line appears in /proc/filesystems with nodev, since there is no block device. Call kern_mount(&demo_fs_type) to get an internal vfsmount, and allocate inodes from its superblock with new_inode.
The function fills in an empty root directory and sets the default operations. Set ctx->ops or ctx->dops before returning to override the superblock and dentry operations. Do not register the type if user space never needs to mount it: kern_mount works without it. The pattern is used for pipefs and sockfs, and the context API is described in the filesystem mount API.