sysfs.h 6.5 KB

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