kernfs-internal.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 <[email protected]>
  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/rwsem.h>
  15. #include <linux/xattr.h>
  16. #include <linux/kernfs.h>
  17. #include <linux/fs_context.h>
  18. struct kernfs_iattrs {
  19. kuid_t ia_uid;
  20. kgid_t ia_gid;
  21. struct timespec64 ia_atime;
  22. struct timespec64 ia_mtime;
  23. struct timespec64 ia_ctime;
  24. struct simple_xattrs xattrs;
  25. atomic_t nr_user_xattrs;
  26. atomic_t user_xattr_size;
  27. };
  28. struct kernfs_root {
  29. /* published fields */
  30. struct kernfs_node *kn;
  31. unsigned int flags; /* KERNFS_ROOT_* flags */
  32. /* private fields, do not use outside kernfs proper */
  33. struct idr ino_idr;
  34. u32 last_id_lowbits;
  35. u32 id_highbits;
  36. struct kernfs_syscall_ops *syscall_ops;
  37. /* list of kernfs_super_info of this root, protected by kernfs_rwsem */
  38. struct list_head supers;
  39. wait_queue_head_t deactivate_waitq;
  40. struct rw_semaphore kernfs_rwsem;
  41. };
  42. /* +1 to avoid triggering overflow warning when negating it */
  43. #define KN_DEACTIVATED_BIAS (INT_MIN + 1)
  44. /* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */
  45. /**
  46. * kernfs_root - find out the kernfs_root a kernfs_node belongs to
  47. * @kn: kernfs_node of interest
  48. *
  49. * Return the kernfs_root @kn belongs to.
  50. */
  51. static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn)
  52. {
  53. /* if parent exists, it's always a dir; otherwise, @sd is a dir */
  54. if (kn->parent)
  55. kn = kn->parent;
  56. return kn->dir.root;
  57. }
  58. /*
  59. * mount.c
  60. */
  61. struct kernfs_super_info {
  62. struct super_block *sb;
  63. /*
  64. * The root associated with this super_block. Each super_block is
  65. * identified by the root and ns it's associated with.
  66. */
  67. struct kernfs_root *root;
  68. /*
  69. * Each sb is associated with one namespace tag, currently the
  70. * network namespace of the task which mounted this kernfs
  71. * instance. If multiple tags become necessary, make the following
  72. * an array and compare kernfs_node tag against every entry.
  73. */
  74. const void *ns;
  75. /* anchored at kernfs_root->supers, protected by kernfs_rwsem */
  76. struct list_head node;
  77. };
  78. #define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info))
  79. static inline struct kernfs_node *kernfs_dentry_node(struct dentry *dentry)
  80. {
  81. if (d_really_is_negative(dentry))
  82. return NULL;
  83. return d_inode(dentry)->i_private;
  84. }
  85. static inline void kernfs_set_rev(struct kernfs_node *parent,
  86. struct dentry *dentry)
  87. {
  88. dentry->d_time = parent->dir.rev;
  89. }
  90. static inline void kernfs_inc_rev(struct kernfs_node *parent)
  91. {
  92. parent->dir.rev++;
  93. }
  94. static inline bool kernfs_dir_changed(struct kernfs_node *parent,
  95. struct dentry *dentry)
  96. {
  97. if (parent->dir.rev != dentry->d_time)
  98. return true;
  99. return false;
  100. }
  101. extern const struct super_operations kernfs_sops;
  102. extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache;
  103. /*
  104. * inode.c
  105. */
  106. extern const struct xattr_handler *kernfs_xattr_handlers[];
  107. void kernfs_evict_inode(struct inode *inode);
  108. int kernfs_iop_permission(struct user_namespace *mnt_userns,
  109. struct inode *inode, int mask);
  110. int kernfs_iop_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
  111. struct iattr *iattr);
  112. int kernfs_iop_getattr(struct user_namespace *mnt_userns,
  113. const struct path *path, struct kstat *stat,
  114. u32 request_mask, unsigned int query_flags);
  115. ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size);
  116. int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
  117. /*
  118. * dir.c
  119. */
  120. extern const struct dentry_operations kernfs_dops;
  121. extern const struct file_operations kernfs_dir_fops;
  122. extern const struct inode_operations kernfs_dir_iops;
  123. struct kernfs_node *kernfs_get_active(struct kernfs_node *kn);
  124. void kernfs_put_active(struct kernfs_node *kn);
  125. int kernfs_add_one(struct kernfs_node *kn);
  126. struct kernfs_node *kernfs_new_node(struct kernfs_node *parent,
  127. const char *name, umode_t mode,
  128. kuid_t uid, kgid_t gid,
  129. unsigned flags);
  130. /*
  131. * file.c
  132. */
  133. extern const struct file_operations kernfs_file_fops;
  134. bool kernfs_should_drain_open_files(struct kernfs_node *kn);
  135. void kernfs_drain_open_files(struct kernfs_node *kn);
  136. /*
  137. * symlink.c
  138. */
  139. extern const struct inode_operations kernfs_symlink_iops;
  140. /*
  141. * kernfs locks
  142. */
  143. extern struct kernfs_global_locks *kernfs_locks;
  144. #endif /* __KERNFS_INTERNAL_H */