kernfs-internal.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * fs/kernfs/kernfs-internal.h - kernfs internal header file
  3. *
  4. * Copyright (c) 2001-3 Patrick Mochel
  5. * Copyright (c) 2007 SUSE Linux Products GmbH
  6. * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de>
  7. *
  8. * This file is released under the GPLv2.
  9. */
  10. #ifndef __KERNFS_INTERNAL_H
  11. #define __KERNFS_INTERNAL_H
  12. #include <linux/lockdep.h>
  13. #include <linux/fs.h>
  14. #include <linux/rbtree.h>
  15. #include <linux/mutex.h>
  16. #include <linux/kernfs.h>
  17. struct sysfs_open_dirent;
  18. /* type-specific structures for sysfs_dirent->s_* union members */
  19. struct sysfs_elem_dir {
  20. unsigned long subdirs;
  21. /* children rbtree starts here and goes through sd->s_rb */
  22. struct rb_root children;
  23. /*
  24. * The kernfs hierarchy this directory belongs to. This fits
  25. * better directly in sysfs_dirent but is here to save space.
  26. */
  27. struct kernfs_root *root;
  28. };
  29. struct sysfs_elem_symlink {
  30. struct sysfs_dirent *target_sd;
  31. };
  32. struct sysfs_elem_attr {
  33. const struct kernfs_ops *ops;
  34. struct sysfs_open_dirent *open;
  35. loff_t size;
  36. };
  37. struct sysfs_inode_attrs {
  38. struct iattr ia_iattr;
  39. void *ia_secdata;
  40. u32 ia_secdata_len;
  41. };
  42. /*
  43. * sysfs_dirent - the building block of sysfs hierarchy. Each and
  44. * every sysfs node is represented by single sysfs_dirent.
  45. *
  46. * As long as s_count reference is held, the sysfs_dirent itself is
  47. * accessible. Dereferencing s_elem or any other outer entity
  48. * requires s_active reference.
  49. */
  50. struct sysfs_dirent {
  51. atomic_t s_count;
  52. atomic_t s_active;
  53. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  54. struct lockdep_map dep_map;
  55. #endif
  56. struct sysfs_dirent *s_parent;
  57. const char *s_name;
  58. struct rb_node s_rb;
  59. union {
  60. struct completion *completion;
  61. struct sysfs_dirent *removed_list;
  62. } u;
  63. const void *s_ns; /* namespace tag */
  64. unsigned int s_hash; /* ns + name hash */
  65. union {
  66. struct sysfs_elem_dir s_dir;
  67. struct sysfs_elem_symlink s_symlink;
  68. struct sysfs_elem_attr s_attr;
  69. };
  70. void *priv;
  71. unsigned short s_flags;
  72. umode_t s_mode;
  73. unsigned int s_ino;
  74. struct sysfs_inode_attrs *s_iattr;
  75. };
  76. #define SD_DEACTIVATED_BIAS INT_MIN
  77. #define SYSFS_TYPE_MASK 0x000f
  78. #define SYSFS_DIR 0x0001
  79. #define SYSFS_KOBJ_ATTR 0x0002
  80. #define SYSFS_KOBJ_LINK 0x0004
  81. #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
  82. #define SYSFS_ACTIVE_REF SYSFS_KOBJ_ATTR
  83. #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
  84. #define SYSFS_FLAG_REMOVED 0x0010
  85. #define SYSFS_FLAG_NS 0x0020
  86. #define SYSFS_FLAG_HAS_SEQ_SHOW 0x0040
  87. #define SYSFS_FLAG_HAS_MMAP 0x0080
  88. #define SYSFS_FLAG_LOCKDEP 0x0100
  89. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  90. {
  91. return sd->s_flags & SYSFS_TYPE_MASK;
  92. }
  93. /**
  94. * kernfs_root - find out the kernfs_root a sysfs_dirent belongs to
  95. * @sd: sysfs_dirent of interest
  96. *
  97. * Return the kernfs_root @sd belongs to.
  98. */
  99. static inline struct kernfs_root *kernfs_root(struct sysfs_dirent *sd)
  100. {
  101. /* if parent exists, it's always a dir; otherwise, @sd is a dir */
  102. if (sd->s_parent)
  103. sd = sd->s_parent;
  104. return sd->s_dir.root;
  105. }
  106. /*
  107. * Context structure to be used while adding/removing nodes.
  108. */
  109. struct sysfs_addrm_cxt {
  110. struct sysfs_dirent *removed;
  111. };
  112. #include "../sysfs/sysfs.h"
  113. /*
  114. * inode.c
  115. */
  116. struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
  117. void sysfs_evict_inode(struct inode *inode);
  118. int sysfs_permission(struct inode *inode, int mask);
  119. int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  120. int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  121. struct kstat *stat);
  122. int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  123. size_t size, int flags);
  124. int sysfs_inode_init(void);
  125. /*
  126. * dir.c
  127. */
  128. extern struct mutex sysfs_mutex;
  129. extern const struct dentry_operations sysfs_dentry_ops;
  130. extern const struct file_operations sysfs_dir_operations;
  131. extern const struct inode_operations sysfs_dir_inode_operations;
  132. struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
  133. void sysfs_put_active(struct sysfs_dirent *sd);
  134. void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt);
  135. int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
  136. struct sysfs_dirent *parent_sd);
  137. void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
  138. struct sysfs_dirent *sysfs_new_dirent(struct kernfs_root *root,
  139. const char *name, umode_t mode, int type);
  140. /*
  141. * file.c
  142. */
  143. extern const struct file_operations kernfs_file_operations;
  144. void sysfs_unmap_bin_file(struct sysfs_dirent *sd);
  145. /*
  146. * symlink.c
  147. */
  148. extern const struct inode_operations sysfs_symlink_inode_operations;
  149. #endif /* __KERNFS_INTERNAL_H */