xref: /linux/fs/nullfs.c (revision 85cdaca6970028bf6f544c355c90035586836ddf)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2026 Christian Brauner <brauner@kernel.org> */
3 #include <linux/fs/super_types.h>
4 #include <linux/fs_context.h>
5 #include <linux/magic.h>
6 
7 #include "mount.h"
8 
9 static const struct super_operations nullfs_super_operations = {
10 	.statfs	= simple_statfs,
11 };
12 
13 static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)
14 {
15 	struct inode *inode;
16 
17 	s->s_maxbytes		= MAX_LFS_FILESIZE;
18 	s->s_blocksize		= PAGE_SIZE;
19 	s->s_blocksize_bits	= PAGE_SHIFT;
20 	s->s_magic		= NULL_FS_MAGIC;
21 	s->s_op			= &nullfs_super_operations;
22 	s->s_export_op		= NULL;
23 	s->s_xattr		= NULL;
24 	s->s_time_gran		= 1;
25 	s->s_d_flags		= 0;
26 
27 	inode = new_inode(s);
28 	if (!inode)
29 		return -ENOMEM;
30 
31 	/* nullfs is permanently empty... */
32 	make_empty_dir_inode(inode);
33 	simple_inode_init_ts(inode);
34 	inode->i_ino	= 1;
35 	/* ... and immutable. */
36 	inode->i_flags |= S_IMMUTABLE;
37 
38 	s->s_root = d_make_root(inode);
39 	if (!s->s_root)
40 		return -ENOMEM;
41 
42 	return 0;
43 }
44 
45 static int nullfs_fs_get_tree(struct fs_context *fc)
46 {
47 	return get_tree_nodev(fc, nullfs_fs_fill_super);
48 }
49 
50 static const struct fs_context_operations nullfs_fs_context_ops = {
51 	.get_tree	= nullfs_fs_get_tree,
52 };
53 
54 static int nullfs_init_fs_context(struct fs_context *fc)
55 {
56 	fc->ops		= &nullfs_fs_context_ops;
57 	fc->sb_flags	|= SB_NOUSER;
58 	fc->s_iflags	|= SB_I_NOEXEC | SB_I_NODEV;
59 	return 0;
60 }
61 
62 struct file_system_type nullfs_fs_type = {
63 	.name			= "nullfs",
64 	.init_fs_context	= nullfs_init_fs_context,
65 	.kill_sb		= kill_anon_super,
66 };
67