sysfs.h 5.2 KB

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