sysfs.h 4.6 KB

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