sysfs.h 5.7 KB

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