sysfs.h 4.5 KB

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