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