sysfs.h 6.1 KB

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