sysfs.h 5.1 KB

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