kernfs-internal.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * fs/kernfs/kernfs-internal.h - kernfs internal header file
  4. *
  5. * Copyright (c) 2001-3 Patrick Mochel
  6. * Copyright (c) 2007 SUSE Linux Products GmbH
  7. * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de>
  8. */
  9. #ifndef __KERNFS_INTERNAL_H
  10. #define __KERNFS_INTERNAL_H
  11. #include <linux/lockdep.h>
  12. #include <linux/fs.h>
  13. #include <linux/mutex.h>
  14. #include <linux/xattr.h>
  15. #include <linux/kernfs.h>
  16. #include <linux/fs_context.h>
  17. struct kernfs_iattrs {
  18. kuid_t ia_uid;
  19. kgid_t ia_gid;
  20. struct timespec64 ia_atime;
  21. struct timespec64 ia_mtime;
  22. struct timespec64 ia_ctime;
  23. struct simple_xattrs xattrs;
  24. atomic_t nr_user_xattrs;
  25. atomic_t user_xattr_size;
  26. };
  27. /* +1 to avoid triggering overflow warning when negating it */
  28. #define KN_DEACTIVATED_BIAS (INT_MIN + 1)
  29. /* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
  30. /**
  31. * kernfs_root - find out the kernfs_root a kernfs_node belongs to
  32. * @kn: kernfs_node of interest
  33. *
  34. * Return the kernfs_root @kn belongs to.
  35. */
  36. static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn)
  37. {
  38. /* if parent exists, it's always a dir; otherwise, @sd is a dir */
  39. if (kn->parent)
  40. kn = kn->parent;
  41. return kn->dir.root;
  42. }
  43. /*
  44. * mount.c
  45. */
  46. struct kernfs_super_info {
  47. struct super_block *sb;
  48. /*
  49. * The root associated with this super_block. Each super_block is
  50. * identified by the root and ns it's associated with.
  51. */
  52. struct kernfs_root *root;
  53. /*
  54. * Each sb is associated with one namespace tag, currently the
  55. * network namespace of the task which mounted this kernfs
  56. * instance. If multiple tags become necessary, make the following
  57. * an array and compare kernfs_node tag against every entry.
  58. */
  59. const void *ns;
  60. /* anchored at kernfs_root->supers, protected by kernfs_mutex */
  61. struct list_head node;
  62. };
  63. #define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info))
  64. static inline struct kernfs_node *kernfs_dentry_node(struct dentry *dentry)
  65. {
  66. if (d_really_is_negative(dentry))
  67. return NULL;
  68. return d_inode(dentry)->i_private;
  69. }
  70. extern const struct super_operations kernfs_sops;
  71. extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache;
  72. /*
  73. * inode.c
  74. */
  75. extern const struct xattr_handler *kernfs_xattr_handlers[];
  76. void kernfs_evict_inode(struct inode *inode);
  77. int kernfs_iop_permission(struct inode *inode, int mask);
  78. int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr);
  79. int kernfs_iop_getattr(const struct path *path, struct kstat *stat,
  80. u32 request_mask, unsigned int query_flags);
  81. ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size);
  82. int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
  83. /*
  84. * dir.c
  85. */
  86. extern struct mutex kernfs_mutex;
  87. extern const struct dentry_operations kernfs_dops;
  88. extern const struct file_operations kernfs_dir_fops;
  89. extern const struct inode_operations kernfs_dir_iops;
  90. struct kernfs_node *kernfs_get_active(struct kernfs_node *kn);
  91. void kernfs_put_active(struct kernfs_node *kn);
  92. int kernfs_add_one(struct kernfs_node *kn);
  93. struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
  94. const char *name, umode_t mode,
  95. kuid_t uid, kgid_t gid,
  96. unsigned flags);
  97. /*
  98. * file.c
  99. */
  100. extern const struct file_operations kernfs_file_fops;
  101. void kernfs_drain_open_files(struct kernfs_node *kn);
  102. /*
  103. * symlink.c
  104. */
  105. extern const struct inode_operations kernfs_symlink_iops;
  106. #endif /* __KERNFS_INTERNAL_H */