sysfs.h 5.8 KB

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