sysfs.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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/fs.h>
  11. struct sysfs_open_dirent;
  12. /* type-specific structures for sysfs_dirent->s_* union members */
  13. struct sysfs_elem_dir {
  14. struct kobject *kobj;
  15. /* children list starts here and goes through sd->s_sibling */
  16. struct sysfs_dirent *children;
  17. };
  18. struct sysfs_elem_symlink {
  19. struct sysfs_dirent *target_sd;
  20. };
  21. struct sysfs_elem_attr {
  22. struct attribute *attr;
  23. struct sysfs_open_dirent *open;
  24. };
  25. struct sysfs_elem_bin_attr {
  26. struct bin_attribute *bin_attr;
  27. struct hlist_head buffers;
  28. };
  29. struct sysfs_inode_attrs {
  30. struct iattr ia_iattr;
  31. void *ia_secdata;
  32. u32 ia_secdata_len;
  33. };
  34. /*
  35. * sysfs_dirent - the building block of sysfs hierarchy. Each and
  36. * every sysfs node is represented by single sysfs_dirent.
  37. *
  38. * As long as s_count reference is held, the sysfs_dirent itself is
  39. * accessible. Dereferencing s_elem or any other outer entity
  40. * requires s_active reference.
  41. */
  42. struct sysfs_dirent {
  43. atomic_t s_count;
  44. atomic_t s_active;
  45. struct sysfs_dirent *s_parent;
  46. struct sysfs_dirent *s_sibling;
  47. const char *s_name;
  48. union {
  49. struct sysfs_elem_dir s_dir;
  50. struct sysfs_elem_symlink s_symlink;
  51. struct sysfs_elem_attr s_attr;
  52. struct sysfs_elem_bin_attr s_bin_attr;
  53. };
  54. unsigned int s_flags;
  55. ino_t s_ino;
  56. umode_t s_mode;
  57. struct sysfs_inode_attrs *s_iattr;
  58. };
  59. #define SD_DEACTIVATED_BIAS INT_MIN
  60. #define SYSFS_TYPE_MASK 0x00ff
  61. #define SYSFS_DIR 0x0001
  62. #define SYSFS_KOBJ_ATTR 0x0002
  63. #define SYSFS_KOBJ_BIN_ATTR 0x0004
  64. #define SYSFS_KOBJ_LINK 0x0008
  65. #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
  66. #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
  67. #define SYSFS_FLAG_REMOVED 0x0200
  68. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  69. {
  70. return sd->s_flags & SYSFS_TYPE_MASK;
  71. }
  72. /*
  73. * Context structure to be used while adding/removing nodes.
  74. */
  75. struct sysfs_addrm_cxt {
  76. struct sysfs_dirent *parent_sd;
  77. struct sysfs_dirent *removed;
  78. };
  79. /*
  80. * mount.c
  81. */
  82. extern struct sysfs_dirent sysfs_root;
  83. extern struct super_block *sysfs_sb;
  84. extern struct kmem_cache *sysfs_dir_cachep;
  85. /*
  86. * dir.c
  87. */
  88. extern struct mutex sysfs_mutex;
  89. extern spinlock_t sysfs_assoc_lock;
  90. extern const struct file_operations sysfs_dir_operations;
  91. extern const struct inode_operations sysfs_dir_inode_operations;
  92. struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
  93. struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
  94. void sysfs_put_active_two(struct sysfs_dirent *sd);
  95. void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
  96. struct sysfs_dirent *parent_sd);
  97. int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
  98. int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
  99. void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
  100. void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
  101. struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
  102. const unsigned char *name);
  103. struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  104. const unsigned char *name);
  105. struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
  106. void release_sysfs_dirent(struct sysfs_dirent *sd);
  107. int sysfs_create_subdir(struct kobject *kobj, const char *name,
  108. struct sysfs_dirent **p_sd);
  109. void sysfs_remove_subdir(struct sysfs_dirent *sd);
  110. int sysfs_rename(struct sysfs_dirent *sd,
  111. struct sysfs_dirent *new_parent_sd, const char *new_name);
  112. static inline struct sysfs_dirent *__sysfs_get(struct sysfs_dirent *sd)
  113. {
  114. if (sd) {
  115. WARN_ON(!atomic_read(&sd->s_count));
  116. atomic_inc(&sd->s_count);
  117. }
  118. return sd;
  119. }
  120. #define sysfs_get(sd) __sysfs_get(sd)
  121. static inline void __sysfs_put(struct sysfs_dirent *sd)
  122. {
  123. if (sd && atomic_dec_and_test(&sd->s_count))
  124. release_sysfs_dirent(sd);
  125. }
  126. #define sysfs_put(sd) __sysfs_put(sd)
  127. /*
  128. * inode.c
  129. */
  130. struct inode *sysfs_get_inode(struct sysfs_dirent *sd);
  131. void sysfs_delete_inode(struct inode *inode);
  132. int sysfs_sd_setattr(struct sysfs_dirent *sd, struct iattr *iattr);
  133. int sysfs_permission(struct inode *inode, int mask);
  134. int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  135. int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
  136. int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  137. size_t size, int flags);
  138. int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
  139. int sysfs_inode_init(void);
  140. /*
  141. * file.c
  142. */
  143. extern const struct file_operations sysfs_file_operations;
  144. int sysfs_add_file(struct sysfs_dirent *dir_sd,
  145. const struct attribute *attr, int type);
  146. int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
  147. const struct attribute *attr, int type, mode_t amode);
  148. /*
  149. * bin.c
  150. */
  151. extern const struct file_operations bin_fops;
  152. void unmap_bin_file(struct sysfs_dirent *attr_sd);
  153. /*
  154. * symlink.c
  155. */
  156. extern const struct inode_operations sysfs_symlink_inode_operations;