sysfs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 <asm/atomic.h>
  17. struct kobject;
  18. struct module;
  19. /* FIXME
  20. * The *owner field is no longer used.
  21. * x86 tree has been cleaned up. The owner
  22. * attribute is still left for other arches.
  23. */
  24. struct attribute {
  25. const char *name;
  26. struct module *owner;
  27. mode_t mode;
  28. };
  29. struct attribute_group {
  30. const char *name;
  31. mode_t (*is_visible)(struct kobject *,
  32. struct attribute *, int);
  33. struct attribute **attrs;
  34. };
  35. /**
  36. * Use these macros to make defining attributes easier. See include/linux/device.h
  37. * for examples..
  38. */
  39. #define __ATTR(_name,_mode,_show,_store) { \
  40. .attr = {.name = __stringify(_name), .mode = _mode }, \
  41. .show = _show, \
  42. .store = _store, \
  43. }
  44. #define __ATTR_RO(_name) { \
  45. .attr = { .name = __stringify(_name), .mode = 0444 }, \
  46. .show = _name##_show, \
  47. }
  48. #define __ATTR_NULL { .attr = { .name = NULL } }
  49. #define attr_name(_attr) (_attr).attr.name
  50. struct vm_area_struct;
  51. struct bin_attribute {
  52. struct attribute attr;
  53. size_t size;
  54. void *private;
  55. ssize_t (*read)(struct kobject *, struct bin_attribute *,
  56. char *, loff_t, size_t);
  57. ssize_t (*write)(struct kobject *, struct bin_attribute *,
  58. char *, loff_t, size_t);
  59. int (*mmap)(struct kobject *, struct bin_attribute *attr,
  60. struct vm_area_struct *vma);
  61. };
  62. struct sysfs_ops {
  63. ssize_t (*show)(struct kobject *, struct attribute *,char *);
  64. ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
  65. };
  66. struct sysfs_dirent;
  67. #ifdef CONFIG_SYSFS
  68. int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
  69. void *data, struct module *owner);
  70. int __must_check sysfs_create_dir(struct kobject *kobj);
  71. void sysfs_remove_dir(struct kobject *kobj);
  72. int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
  73. int __must_check sysfs_move_dir(struct kobject *kobj,
  74. struct kobject *new_parent_kobj);
  75. int __must_check sysfs_create_file(struct kobject *kobj,
  76. const struct attribute *attr);
  77. int __must_check sysfs_create_files(struct kobject *kobj,
  78. const struct attribute **attr);
  79. int __must_check sysfs_chmod_file(struct kobject *kobj, struct attribute *attr,
  80. mode_t mode);
  81. void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
  82. void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);
  83. int __must_check sysfs_create_bin_file(struct kobject *kobj,
  84. const struct bin_attribute *attr);
  85. void sysfs_remove_bin_file(struct kobject *kobj,
  86. const struct bin_attribute *attr);
  87. int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
  88. const char *name);
  89. int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
  90. struct kobject *target,
  91. const char *name);
  92. void sysfs_remove_link(struct kobject *kobj, const char *name);
  93. int __must_check sysfs_create_group(struct kobject *kobj,
  94. const struct attribute_group *grp);
  95. int sysfs_update_group(struct kobject *kobj,
  96. const struct attribute_group *grp);
  97. void sysfs_remove_group(struct kobject *kobj,
  98. const struct attribute_group *grp);
  99. int sysfs_add_file_to_group(struct kobject *kobj,
  100. const struct attribute *attr, const char *group);
  101. void sysfs_remove_file_from_group(struct kobject *kobj,
  102. const struct attribute *attr, const char *group);
  103. void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
  104. void sysfs_notify_dirent(struct sysfs_dirent *sd);
  105. struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  106. const unsigned char *name);
  107. struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd);
  108. void sysfs_put(struct sysfs_dirent *sd);
  109. void sysfs_printk_last_file(void);
  110. int __must_check sysfs_init(void);
  111. #else /* CONFIG_SYSFS */
  112. static inline int sysfs_schedule_callback(struct kobject *kobj,
  113. void (*func)(void *), void *data, struct module *owner)
  114. {
  115. return -ENOSYS;
  116. }
  117. static inline int sysfs_create_dir(struct kobject *kobj)
  118. {
  119. return 0;
  120. }
  121. static inline void sysfs_remove_dir(struct kobject *kobj)
  122. {
  123. }
  124. static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
  125. {
  126. return 0;
  127. }
  128. static inline int sysfs_move_dir(struct kobject *kobj,
  129. struct kobject *new_parent_kobj)
  130. {
  131. return 0;
  132. }
  133. static inline int sysfs_create_file(struct kobject *kobj,
  134. const struct attribute *attr)
  135. {
  136. return 0;
  137. }
  138. static inline int sysfs_create_files(struct kobject *kobj,
  139. const struct attribute **attr)
  140. {
  141. return 0;
  142. }
  143. static inline int sysfs_chmod_file(struct kobject *kobj,
  144. struct attribute *attr, mode_t mode)
  145. {
  146. return 0;
  147. }
  148. static inline void sysfs_remove_file(struct kobject *kobj,
  149. const struct attribute *attr)
  150. {
  151. }
  152. static inline void sysfs_remove_files(struct kobject *kobj,
  153. const struct attribute **attr)
  154. {
  155. }
  156. static inline int sysfs_create_bin_file(struct kobject *kobj,
  157. const struct bin_attribute *attr)
  158. {
  159. return 0;
  160. }
  161. static inline void sysfs_remove_bin_file(struct kobject *kobj,
  162. const struct bin_attribute *attr)
  163. {
  164. }
  165. static inline int sysfs_create_link(struct kobject *kobj,
  166. struct kobject *target, const char *name)
  167. {
  168. return 0;
  169. }
  170. static inline int sysfs_create_link_nowarn(struct kobject *kobj,
  171. struct kobject *target,
  172. const char *name)
  173. {
  174. return 0;
  175. }
  176. static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
  177. {
  178. }
  179. static inline int sysfs_create_group(struct kobject *kobj,
  180. const struct attribute_group *grp)
  181. {
  182. return 0;
  183. }
  184. static inline int sysfs_update_group(struct kobject *kobj,
  185. const struct attribute_group *grp)
  186. {
  187. return 0;
  188. }
  189. static inline void sysfs_remove_group(struct kobject *kobj,
  190. const struct attribute_group *grp)
  191. {
  192. }
  193. static inline int sysfs_add_file_to_group(struct kobject *kobj,
  194. const struct attribute *attr, const char *group)
  195. {
  196. return 0;
  197. }
  198. static inline void sysfs_remove_file_from_group(struct kobject *kobj,
  199. const struct attribute *attr, const char *group)
  200. {
  201. }
  202. static inline void sysfs_notify(struct kobject *kobj, const char *dir,
  203. const char *attr)
  204. {
  205. }
  206. static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
  207. {
  208. }
  209. static inline
  210. struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  211. const unsigned char *name)
  212. {
  213. return NULL;
  214. }
  215. static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
  216. {
  217. return NULL;
  218. }
  219. static inline void sysfs_put(struct sysfs_dirent *sd)
  220. {
  221. }
  222. static inline int __must_check sysfs_init(void)
  223. {
  224. return 0;
  225. }
  226. static inline void sysfs_printk_last_file(void)
  227. {
  228. }
  229. #endif /* CONFIG_SYSFS */
  230. #endif /* _SYSFS_H_ */