nullfs.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. static const struct super_operations nullfs_super_operations = {
  7. .statfs = simple_statfs,
  8. };
  9. static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)
  10. {
  11. struct inode *inode;
  12. s->s_maxbytes = MAX_LFS_FILESIZE;
  13. s->s_blocksize = PAGE_SIZE;
  14. s->s_blocksize_bits = PAGE_SHIFT;
  15. s->s_magic = NULL_FS_MAGIC;
  16. s->s_op = &nullfs_super_operations;
  17. s->s_export_op = NULL;
  18. s->s_xattr = NULL;
  19. s->s_time_gran = 1;
  20. s->s_d_flags = 0;
  21. inode = new_inode(s);
  22. if (!inode)
  23. return -ENOMEM;
  24. /* nullfs is permanently empty... */
  25. make_empty_dir_inode(inode);
  26. simple_inode_init_ts(inode);
  27. inode->i_ino = 1;
  28. /* ... and immutable. */
  29. inode->i_flags |= S_IMMUTABLE;
  30. s->s_root = d_make_root(inode);
  31. if (!s->s_root)
  32. return -ENOMEM;
  33. return 0;
  34. }
  35. /*
  36. * For now this is a single global instance. If needed we can make it
  37. * mountable by userspace at which point we will need to make it
  38. * multi-instance.
  39. */
  40. static int nullfs_fs_get_tree(struct fs_context *fc)
  41. {
  42. return get_tree_single(fc, nullfs_fs_fill_super);
  43. }
  44. static const struct fs_context_operations nullfs_fs_context_ops = {
  45. .get_tree = nullfs_fs_get_tree,
  46. };
  47. static int nullfs_init_fs_context(struct fs_context *fc)
  48. {
  49. fc->ops = &nullfs_fs_context_ops;
  50. fc->global = true;
  51. fc->sb_flags = SB_NOUSER;
  52. fc->s_iflags = SB_I_NOEXEC | SB_I_NODEV;
  53. return 0;
  54. }
  55. struct file_system_type nullfs_fs_type = {
  56. .name = "nullfs",
  57. .init_fs_context = nullfs_init_fs_context,
  58. .kill_sb = kill_anon_super,
  59. };