sysfs.h 5.7 KB

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