sysfs.h 4.7 KB

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