/fs/sysfs/sysfs.h

https://github.com/odelay941/bravo-kernel · C Header · 230 lines · 146 code · 34 blank · 50 comment · 6 complexity · 800a7debedceca439cd686460a71a017 MD5 · raw file

  1. /*
  2. * fs/sysfs/sysfs.h - sysfs internal header file
  3. *
  4. * Copyright (c) 2001-3 Patrick Mochel
  5. * Copyright (c) 2007 SUSE Linux Products GmbH
  6. * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
  7. *
  8. * This file is released under the GPLv2.
  9. */
  10. #include <linux/lockdep.h>
  11. #include <linux/fs.h>
  12. struct sysfs_open_dirent;
  13. /* type-specific structures for sysfs_dirent->s_* union members */
  14. struct sysfs_elem_dir {
  15. struct kobject *kobj;
  16. /* children list starts here and goes through sd->s_sibling */
  17. struct sysfs_dirent *children;
  18. };
  19. struct sysfs_elem_symlink {
  20. struct sysfs_dirent *target_sd;
  21. };
  22. struct sysfs_elem_attr {
  23. struct attribute *attr;
  24. struct sysfs_open_dirent *open;
  25. };
  26. struct sysfs_elem_bin_attr {
  27. struct bin_attribute *bin_attr;
  28. struct hlist_head buffers;
  29. };
  30. struct sysfs_inode_attrs {
  31. struct iattr ia_iattr;
  32. void *ia_secdata;
  33. u32 ia_secdata_len;
  34. };
  35. /*
  36. * sysfs_dirent - the building block of sysfs hierarchy. Each and
  37. * every sysfs node is represented by single sysfs_dirent.
  38. *
  39. * As long as s_count reference is held, the sysfs_dirent itself is
  40. * accessible. Dereferencing s_elem or any other outer entity
  41. * requires s_active reference.
  42. */
  43. struct sysfs_dirent {
  44. atomic_t s_count;
  45. atomic_t s_active;
  46. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  47. struct lockdep_map dep_map;
  48. #endif
  49. struct sysfs_dirent *s_parent;
  50. struct sysfs_dirent *s_sibling;
  51. const char *s_name;
  52. const void *s_ns; /* namespace tag */
  53. union {
  54. struct sysfs_elem_dir s_dir;
  55. struct sysfs_elem_symlink s_symlink;
  56. struct sysfs_elem_attr s_attr;
  57. struct sysfs_elem_bin_attr s_bin_attr;
  58. };
  59. unsigned int s_flags;
  60. unsigned short s_mode;
  61. ino_t s_ino;
  62. struct sysfs_inode_attrs *s_iattr;
  63. };
  64. #define SD_DEACTIVATED_BIAS INT_MIN
  65. #define SYSFS_TYPE_MASK 0x00ff
  66. #define SYSFS_DIR 0x0001
  67. #define SYSFS_KOBJ_ATTR 0x0002
  68. #define SYSFS_KOBJ_BIN_ATTR 0x0004
  69. #define SYSFS_KOBJ_LINK 0x0008
  70. #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
  71. #define SYSFS_ACTIVE_REF (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR)
  72. /* identify any namespace tag on sysfs_dirents */
  73. #define SYSFS_NS_TYPE_MASK 0xff00
  74. #define SYSFS_NS_TYPE_SHIFT 8
  75. #define SYSFS_FLAG_MASK ~(SYSFS_NS_TYPE_MASK|SYSFS_TYPE_MASK)
  76. #define SYSFS_FLAG_REMOVED 0x020000
  77. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  78. {
  79. return sd->s_flags & SYSFS_TYPE_MASK;
  80. }
  81. /*
  82. * Return any namespace tags on this dirent.
  83. * enum kobj_ns_type is defined in linux/kobject.h
  84. */
  85. static inline enum kobj_ns_type sysfs_ns_type(struct sysfs_dirent *sd)
  86. {
  87. return (sd->s_flags & SYSFS_NS_TYPE_MASK) >> SYSFS_NS_TYPE_SHIFT;
  88. }
  89. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  90. #define sysfs_dirent_init_lockdep(sd) \
  91. do { \
  92. struct attribute *attr = sd->s_attr.attr; \
  93. struct lock_class_key *key = attr->key; \
  94. if (!key) \
  95. key = &attr->skey; \
  96. \
  97. lockdep_init_map(&sd->dep_map, "s_active", key, 0); \
  98. } while(0)
  99. #else
  100. #define sysfs_dirent_init_lockdep(sd) do {} while(0)
  101. #endif
  102. /*
  103. * Context structure to be used while adding/removing nodes.
  104. */
  105. struct sysfs_addrm_cxt {
  106. struct sysfs_dirent *parent_sd;
  107. struct sysfs_dirent *removed;
  108. };
  109. /*
  110. * mount.c
  111. */
  112. /*
  113. * Each sb is associated with a set of namespace tags (i.e.
  114. * the network namespace of the task which mounted this sysfs
  115. * instance).
  116. */
  117. struct sysfs_super_info {
  118. const void *ns[KOBJ_NS_TYPES];
  119. };
  120. #define sysfs_info(SB) ((struct sysfs_super_info *)(SB->s_fs_info))
  121. extern struct sysfs_dirent sysfs_root;
  122. extern struct kmem_cache *sysfs_dir_cachep;
  123. /*
  124. * dir.c
  125. */
  126. extern struct mutex sysfs_mutex;
  127. extern spinlock_t sysfs_assoc_lock;
  128. extern const struct file_operations sysfs_dir_operations;
  129. extern const struct inode_operations sysfs_dir_inode_operations;
  130. struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
  131. struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
  132. void sysfs_put_active(struct sysfs_dirent *sd);
  133. void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
  134. struct sysfs_dirent *parent_sd);
  135. int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
  136. int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
  137. void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
  138. void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
  139. struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
  140. const void *ns,
  141. const unsigned char *name);
  142. struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  143. const void *ns,
  144. const unsigned char *name);
  145. struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
  146. void release_sysfs_dirent(struct sysfs_dirent *sd);
  147. int sysfs_create_subdir(struct kobject *kobj, const char *name,
  148. struct sysfs_dirent **p_sd);
  149. void sysfs_remove_subdir(struct sysfs_dirent *sd);
  150. int sysfs_rename(struct sysfs_dirent *sd,
  151. struct sysfs_dirent *new_parent_sd, const void *ns, const char *new_name);
  152. static inline struct sysfs_dirent *__sysfs_get(struct sysfs_dirent *sd)
  153. {
  154. if (sd) {
  155. WARN_ON(!atomic_read(&sd->s_count));
  156. atomic_inc(&sd->s_count);
  157. }
  158. return sd;
  159. }
  160. #define sysfs_get(sd) __sysfs_get(sd)
  161. static inline void __sysfs_put(struct sysfs_dirent *sd)
  162. {
  163. if (sd && atomic_dec_and_test(&sd->s_count))
  164. release_sysfs_dirent(sd);
  165. }
  166. #define sysfs_put(sd) __sysfs_put(sd)
  167. /*
  168. * inode.c
  169. */
  170. struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
  171. void sysfs_delete_inode(struct inode *inode);
  172. int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr *iattr);
  173. int sysfs_permission(struct inode *inode, int mask);
  174. int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  175. int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
  176. int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  177. size_t size, int flags);
  178. int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const void *ns, const char *name);
  179. int sysfs_inode_init(void);
  180. /*
  181. * file.c
  182. */
  183. extern const struct file_operations sysfs_file_operations;
  184. int sysfs_add_file(struct sysfs_dirent *dir_sd,
  185. const struct attribute *attr, int type);
  186. int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
  187. const struct attribute *attr, int type, mode_t amode);
  188. /*
  189. * bin.c
  190. */
  191. extern const struct file_operations bin_fops;
  192. void unmap_bin_file(struct sysfs_dirent *attr_sd);
  193. /*
  194. * symlink.c
  195. */
  196. extern const struct inode_operations sysfs_symlink_inode_operations;