sysfs.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /*
  2. * sysfs.h - definitions for the device driver filesystem
  3. *
  4. * Copyright (c) 2001,2002 Patrick Mochel
  5. * Copyright (c) 2004 Silicon Graphics, Inc.
  6. * Copyright (c) 2007 SUSE Linux Products GmbH
  7. * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
  8. *
  9. * Please see Documentation/filesystems/sysfs.txt for more information.
  10. */
  11. #ifndef _SYSFS_H_
  12. #define _SYSFS_H_
  13. #include <linux/compiler.h>
  14. #include <linux/errno.h>
  15. #include <linux/list.h>
  16. #include <linux/lockdep.h>
  17. #include <asm/atomic.h>
  18. struct kobject;
  19. struct module;
  20. /* FIXME
  21. * The *owner field is no longer used.
  22. * x86 tree has been cleaned up. The owner
  23. * attribute is still left for other arches.
  24. */
  25. struct attribute {
  26. const char *name;
  27. struct module *owner;
  28. mode_t mode;
  29. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  30. struct lock_class_key *key;
  31. struct lock_class_key skey;
  32. #endif
  33. };
  34. /**
  35. * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
  36. * @attr: struct attribute to initialize
  37. *
  38. * Initialize a dynamically allocated struct attribute so we can
  39. * make lockdep happy. This is a new requirement for attributes
  40. * and initially this is only needed when lockdep is enabled.
  41. * Lockdep gives a nice error when your attribute is added to
  42. * sysfs if you don't have this.
  43. */
  44. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  45. #define sysfs_attr_init(attr) \
  46. do { \
  47. static struct lock_class_key __key; \
  48. \
  49. (attr)->key = &__key; \
  50. } while(0)
  51. #else
  52. #define sysfs_attr_init(attr) do {} while(0)
  53. #endif
  54. struct attribute_group {
  55. const char *name;
  56. mode_t (*is_visible)(struct kobject *,
  57. struct attribute *, int);
  58. struct attribute **attrs;
  59. };
  60. /**
  61. * Use these macros to make defining attributes easier. See include/linux/device.h
  62. * for examples..
  63. */
  64. #define __ATTR(_name,_mode,_show,_store) { \
  65. .attr = {.name = __stringify(_name), .mode = _mode }, \
  66. .show = _show, \
  67. .store = _store, \
  68. }
  69. #define __ATTR_RO(_name) { \
  70. .attr = { .name = __stringify(_name), .mode = 0444 }, \
  71. .show = _name##_show, \
  72. }
  73. #define __ATTR_NULL { .attr = { .name = NULL } }
  74. #define attr_name(_attr) (_attr).attr.name
  75. struct vm_area_struct;
  76. struct bin_attribute {
  77. struct attribute attr;
  78. size_t size;
  79. void *private;
  80. ssize_t (*read)(struct kobject *, struct bin_attribute *,
  81. char *, loff_t, size_t);
  82. ssize_t (*write)(struct kobject *, struct bin_attribute *,
  83. char *, loff_t, size_t);
  84. int (*mmap)(struct kobject *, struct bin_attribute *attr,
  85. struct vm_area_struct *vma);
  86. };
  87. /**
  88. * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
  89. * @attr: struct bin_attribute to initialize
  90. *
  91. * Initialize a dynamically allocated struct bin_attribute so we
  92. * can make lockdep happy. This is a new requirement for
  93. * attributes and initially this is only needed when lockdep is
  94. * enabled. Lockdep gives a nice error when your attribute is
  95. * added to sysfs if you don't have this.
  96. */
  97. #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&bin_attr->attr)
  98. struct sysfs_ops {
  99. ssize_t (*show)(struct kobject *, struct attribute *,char *);
  100. ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
  101. };
  102. struct sysfs_dirent;
  103. #ifdef CONFIG_SYSFS
  104. int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
  105. void *data, struct module *owner);
  106. int __must_check sysfs_create_dir(struct kobject *kobj);
  107. void sysfs_remove_dir(struct kobject *kobj);
  108. int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
  109. int __must_check sysfs_move_dir(struct kobject *kobj,
  110. struct kobject *new_parent_kobj);
  111. int __must_check sysfs_create_file(struct kobject *kobj,
  112. const struct attribute *attr);
  113. int __must_check sysfs_create_files(struct kobject *kobj,
  114. const struct attribute **attr);
  115. int __must_check sysfs_chmod_file(struct kobject *kobj, struct attribute *attr,
  116. mode_t mode);
  117. void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
  118. void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);
  119. int __must_check sysfs_create_bin_file(struct kobject *kobj,
  120. const struct bin_attribute *attr);
  121. void sysfs_remove_bin_file(struct kobject *kobj,
  122. const struct bin_attribute *attr);
  123. int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
  124. const char *name);
  125. int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
  126. struct kobject *target,
  127. const char *name);
  128. void sysfs_remove_link(struct kobject *kobj, const char *name);
  129. int __must_check sysfs_create_group(struct kobject *kobj,
  130. const struct attribute_group *grp);
  131. int sysfs_update_group(struct kobject *kobj,
  132. const struct attribute_group *grp);
  133. void sysfs_remove_group(struct kobject *kobj,
  134. const struct attribute_group *grp);
  135. int sysfs_add_file_to_group(struct kobject *kobj,
  136. const struct attribute *attr, const char *group);
  137. void sysfs_remove_file_from_group(struct kobject *kobj,
  138. const struct attribute *attr, const char *group);
  139. void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
  140. void sysfs_notify_dirent(struct sysfs_dirent *sd);
  141. struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  142. const unsigned char *name);
  143. struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd);
  144. void sysfs_put(struct sysfs_dirent *sd);
  145. void sysfs_printk_last_file(void);
  146. int __must_check sysfs_init(void);
  147. #else /* CONFIG_SYSFS */
  148. static inline int sysfs_schedule_callback(struct kobject *kobj,
  149. void (*func)(void *), void *data, struct module *owner)
  150. {
  151. return -ENOSYS;
  152. }
  153. static inline int sysfs_create_dir(struct kobject *kobj)
  154. {
  155. return 0;
  156. }
  157. static inline void sysfs_remove_dir(struct kobject *kobj)
  158. {
  159. }
  160. static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
  161. {
  162. return 0;
  163. }
  164. static inline int sysfs_move_dir(struct kobject *kobj,
  165. struct kobject *new_parent_kobj)
  166. {
  167. return 0;
  168. }
  169. static inline int sysfs_create_file(struct kobject *kobj,
  170. const struct attribute *attr)
  171. {
  172. return 0;
  173. }
  174. static inline int sysfs_create_files(struct kobject *kobj,
  175. const struct attribute **attr)
  176. {
  177. return 0;
  178. }
  179. static inline int sysfs_chmod_file(struct kobject *kobj,
  180. struct attribute *attr, mode_t mode)
  181. {
  182. return 0;
  183. }
  184. static inline void sysfs_remove_file(struct kobject *kobj,
  185. const struct attribute *attr)
  186. {
  187. }
  188. static inline void sysfs_remove_files(struct kobject *kobj,
  189. const struct attribute **attr)
  190. {
  191. }
  192. static inline int sysfs_create_bin_file(struct kobject *kobj,
  193. const struct bin_attribute *attr)
  194. {
  195. return 0;
  196. }
  197. static inline void sysfs_remove_bin_file(struct kobject *kobj,
  198. const struct bin_attribute *attr)
  199. {
  200. }
  201. static inline int sysfs_create_link(struct kobject *kobj,
  202. struct kobject *target, const char *name)
  203. {
  204. return 0;
  205. }
  206. static inline int sysfs_create_link_nowarn(struct kobject *kobj,
  207. struct kobject *target,
  208. const char *name)
  209. {
  210. return 0;
  211. }
  212. static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
  213. {
  214. }
  215. static inline int sysfs_create_group(struct kobject *kobj,
  216. const struct attribute_group *grp)
  217. {
  218. return 0;
  219. }
  220. static inline int sysfs_update_group(struct kobject *kobj,
  221. const struct attribute_group *grp)
  222. {
  223. return 0;
  224. }
  225. static inline void sysfs_remove_group(struct kobject *kobj,
  226. const struct attribute_group *grp)
  227. {
  228. }
  229. static inline int sysfs_add_file_to_group(struct kobject *kobj,
  230. const struct attribute *attr, const char *group)
  231. {
  232. return 0;
  233. }
  234. static inline void sysfs_remove_file_from_group(struct kobject *kobj,
  235. const struct attribute *attr, const char *group)
  236. {
  237. }
  238. static inline void sysfs_notify(struct kobject *kobj, const char *dir,
  239. const char *attr)
  240. {
  241. }
  242. static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
  243. {
  244. }
  245. static inline
  246. struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  247. const unsigned char *name)
  248. {
  249. return NULL;
  250. }
  251. static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
  252. {
  253. return NULL;
  254. }
  255. static inline void sysfs_put(struct sysfs_dirent *sd)
  256. {
  257. }
  258. static inline int __must_check sysfs_init(void)
  259. {
  260. return 0;
  261. }
  262. static inline void sysfs_printk_last_file(void)
  263. {
  264. }
  265. #endif /* CONFIG_SYSFS */
  266. #endif /* _SYSFS_H_ */