sysfs.h 5.2 KB

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