sysfs.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. void sysfs_remove_link(struct kobject *kobj, const char *name);
  84. int __must_check sysfs_create_group(struct kobject *kobj,
  85. const struct attribute_group *grp);
  86. int sysfs_update_group(struct kobject *kobj,
  87. const struct attribute_group *grp);
  88. void sysfs_remove_group(struct kobject *kobj,
  89. const struct attribute_group *grp);
  90. int sysfs_add_file_to_group(struct kobject *kobj,
  91. const struct attribute *attr, const char *group);
  92. void sysfs_remove_file_from_group(struct kobject *kobj,
  93. const struct attribute *attr, const char *group);
  94. void sysfs_notify(struct kobject *kobj, char *dir, char *attr);
  95. extern int __must_check sysfs_init(void);
  96. #else /* CONFIG_SYSFS */
  97. static inline int sysfs_schedule_callback(struct kobject *kobj,
  98. void (*func)(void *), void *data, struct module *owner)
  99. {
  100. return -ENOSYS;
  101. }
  102. static inline int sysfs_create_dir(struct kobject *kobj)
  103. {
  104. return 0;
  105. }
  106. static inline void sysfs_remove_dir(struct kobject *kobj)
  107. {
  108. }
  109. static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
  110. {
  111. return 0;
  112. }
  113. static inline int sysfs_move_dir(struct kobject *kobj,
  114. struct kobject *new_parent_kobj)
  115. {
  116. return 0;
  117. }
  118. static inline int sysfs_create_file(struct kobject *kobj,
  119. const struct attribute *attr)
  120. {
  121. return 0;
  122. }
  123. static inline int sysfs_chmod_file(struct kobject *kobj,
  124. struct attribute *attr, mode_t mode)
  125. {
  126. return 0;
  127. }
  128. static inline void sysfs_remove_file(struct kobject *kobj,
  129. const struct attribute *attr)
  130. {
  131. }
  132. static inline int sysfs_create_bin_file(struct kobject *kobj,
  133. struct bin_attribute *attr)
  134. {
  135. return 0;
  136. }
  137. static inline void sysfs_remove_bin_file(struct kobject *kobj,
  138. struct bin_attribute *attr)
  139. {
  140. }
  141. static inline int sysfs_create_link(struct kobject *kobj,
  142. struct kobject *target, const char *name)
  143. {
  144. return 0;
  145. }
  146. static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
  147. {
  148. }
  149. static inline int sysfs_create_group(struct kobject *kobj,
  150. const struct attribute_group *grp)
  151. {
  152. return 0;
  153. }
  154. static inline int sysfs_update_group(struct kobject *kobj,
  155. const struct attribute_group *grp)
  156. {
  157. return 0;
  158. }
  159. static inline void sysfs_remove_group(struct kobject *kobj,
  160. const struct attribute_group *grp)
  161. {
  162. }
  163. static inline int sysfs_add_file_to_group(struct kobject *kobj,
  164. const struct attribute *attr, const char *group)
  165. {
  166. return 0;
  167. }
  168. static inline void sysfs_remove_file_from_group(struct kobject *kobj,
  169. const struct attribute *attr, const char *group)
  170. {
  171. }
  172. static inline void sysfs_notify(struct kobject *kobj, char *dir, char *attr)
  173. {
  174. }
  175. static inline int __must_check sysfs_init(void)
  176. {
  177. return 0;
  178. }
  179. #endif /* CONFIG_SYSFS */
  180. #endif /* _SYSFS_H_ */