sysfs.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. /* 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 *, char *, loff_t, size_t);
  53. ssize_t (*write)(struct kobject *, 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. #define SYSFS_TYPE_MASK 0x00ff
  62. #define SYSFS_ROOT 0x0001
  63. #define SYSFS_DIR 0x0002
  64. #define SYSFS_KOBJ_ATTR 0x0004
  65. #define SYSFS_KOBJ_BIN_ATTR 0x0008
  66. #define SYSFS_KOBJ_LINK 0x0020
  67. #define SYSFS_NOT_PINNED (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK)
  68. #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
  69. #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
  70. #define SYSFS_FLAG_REMOVED 0x0100
  71. #ifdef CONFIG_SYSFS
  72. extern int sysfs_schedule_callback(struct kobject *kobj,
  73. void (*func)(void *), void *data, struct module *owner);
  74. extern int __must_check
  75. sysfs_create_dir(struct kobject *, struct dentry *);
  76. extern void
  77. sysfs_remove_dir(struct kobject *);
  78. extern int __must_check
  79. sysfs_rename_dir(struct kobject *, struct dentry *, const char *new_name);
  80. extern int __must_check
  81. sysfs_move_dir(struct kobject *, struct kobject *);
  82. extern int __must_check
  83. sysfs_create_file(struct kobject *, const struct attribute *);
  84. extern int __must_check
  85. sysfs_update_file(struct kobject *, const struct attribute *);
  86. extern int __must_check
  87. sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode);
  88. extern void
  89. sysfs_remove_file(struct kobject *, const struct attribute *);
  90. extern int __must_check
  91. sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name);
  92. extern void
  93. sysfs_remove_link(struct kobject *, const char * name);
  94. int __must_check sysfs_create_bin_file(struct kobject *kobj,
  95. struct bin_attribute *attr);
  96. void sysfs_remove_bin_file(struct kobject *kobj, struct bin_attribute *attr);
  97. int __must_check sysfs_create_group(struct kobject *,
  98. const struct attribute_group *);
  99. void sysfs_remove_group(struct kobject *, const struct attribute_group *);
  100. int sysfs_add_file_to_group(struct kobject *kobj,
  101. const struct attribute *attr, const char *group);
  102. void sysfs_remove_file_from_group(struct kobject *kobj,
  103. const struct attribute *attr, const char *group);
  104. void sysfs_notify(struct kobject * k, char *dir, char *attr);
  105. extern int sysfs_make_shadowed_dir(struct kobject *kobj,
  106. void * (*follow_link)(struct dentry *, struct nameidata *));
  107. extern struct dentry *sysfs_create_shadow_dir(struct kobject *kobj);
  108. extern void sysfs_remove_shadow_dir(struct dentry *dir);
  109. extern int __must_check sysfs_init(void);
  110. #else /* CONFIG_SYSFS */
  111. static inline int sysfs_schedule_callback(struct kobject *kobj,
  112. void (*func)(void *), void *data, struct module *owner)
  113. {
  114. return -ENOSYS;
  115. }
  116. static inline int sysfs_create_dir(struct kobject * k, struct dentry *shadow)
  117. {
  118. return 0;
  119. }
  120. static inline void sysfs_remove_dir(struct kobject * k)
  121. {
  122. ;
  123. }
  124. static inline int sysfs_rename_dir(struct kobject * k,
  125. struct dentry *new_parent,
  126. const char *new_name)
  127. {
  128. return 0;
  129. }
  130. static inline int sysfs_move_dir(struct kobject * k, struct kobject * new_parent)
  131. {
  132. return 0;
  133. }
  134. static inline int sysfs_create_file(struct kobject * k, const struct attribute * a)
  135. {
  136. return 0;
  137. }
  138. static inline int sysfs_update_file(struct kobject * k, const struct attribute * a)
  139. {
  140. return 0;
  141. }
  142. static inline int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
  143. {
  144. return 0;
  145. }
  146. static inline void sysfs_remove_file(struct kobject * k, const struct attribute * a)
  147. {
  148. ;
  149. }
  150. static inline int sysfs_create_link(struct kobject * k, struct kobject * t, const char * n)
  151. {
  152. return 0;
  153. }
  154. static inline void sysfs_remove_link(struct kobject * k, const char * name)
  155. {
  156. ;
  157. }
  158. static inline int sysfs_create_bin_file(struct kobject * k, struct bin_attribute * a)
  159. {
  160. return 0;
  161. }
  162. static inline int sysfs_remove_bin_file(struct kobject * k, struct bin_attribute * a)
  163. {
  164. return 0;
  165. }
  166. static inline int sysfs_create_group(struct kobject * k, const struct attribute_group *g)
  167. {
  168. return 0;
  169. }
  170. static inline void sysfs_remove_group(struct kobject * k, const struct attribute_group * g)
  171. {
  172. ;
  173. }
  174. static inline int sysfs_add_file_to_group(struct kobject *kobj,
  175. const struct attribute *attr, const char *group)
  176. {
  177. return 0;
  178. }
  179. static inline void sysfs_remove_file_from_group(struct kobject *kobj,
  180. const struct attribute *attr, const char *group)
  181. {
  182. }
  183. static inline void sysfs_notify(struct kobject * k, char *dir, char *attr)
  184. {
  185. }
  186. static inline int sysfs_make_shadowed_dir(struct kobject *kobj,
  187. void * (*follow_link)(struct dentry *, struct nameidata *))
  188. {
  189. return 0;
  190. }
  191. static inline int __must_check sysfs_init(void)
  192. {
  193. return 0;
  194. }
  195. #endif /* CONFIG_SYSFS */
  196. #endif /* _SYSFS_H_ */