sysfs.h 4.3 KB

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