sysfs.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. char * name;
  16. struct module * owner;
  17. mode_t mode;
  18. };
  19. struct attribute_group {
  20. 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. };
  61. #define SYSFS_ROOT 0x0001
  62. #define SYSFS_DIR 0x0002
  63. #define SYSFS_KOBJ_ATTR 0x0004
  64. #define SYSFS_KOBJ_BIN_ATTR 0x0008
  65. #define SYSFS_KOBJ_LINK 0x0020
  66. #define SYSFS_NOT_PINNED (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK)
  67. #ifdef CONFIG_SYSFS
  68. extern int
  69. sysfs_create_dir(struct kobject *);
  70. extern void
  71. sysfs_remove_dir(struct kobject *);
  72. extern int
  73. sysfs_rename_dir(struct kobject *, const char *new_name);
  74. extern int
  75. sysfs_create_file(struct kobject *, const struct attribute *);
  76. extern int
  77. sysfs_update_file(struct kobject *, const struct attribute *);
  78. extern int
  79. sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode);
  80. extern void
  81. sysfs_remove_file(struct kobject *, const struct attribute *);
  82. extern int
  83. sysfs_create_link(struct kobject * kobj, struct kobject * target, char * name);
  84. extern void
  85. sysfs_remove_link(struct kobject *, char * name);
  86. int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr);
  87. int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr);
  88. int sysfs_create_group(struct kobject *, const struct attribute_group *);
  89. void sysfs_remove_group(struct kobject *, const struct attribute_group *);
  90. #else /* CONFIG_SYSFS */
  91. static inline int sysfs_create_dir(struct kobject * k)
  92. {
  93. return 0;
  94. }
  95. static inline void sysfs_remove_dir(struct kobject * k)
  96. {
  97. ;
  98. }
  99. static inline int sysfs_rename_dir(struct kobject * k, const char *new_name)
  100. {
  101. return 0;
  102. }
  103. static inline int sysfs_create_file(struct kobject * k, const struct attribute * a)
  104. {
  105. return 0;
  106. }
  107. static inline int sysfs_update_file(struct kobject * k, const struct attribute * a)
  108. {
  109. return 0;
  110. }
  111. static inline int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
  112. {
  113. return 0;
  114. }
  115. static inline void sysfs_remove_file(struct kobject * k, const struct attribute * a)
  116. {
  117. ;
  118. }
  119. static inline int sysfs_create_link(struct kobject * k, struct kobject * t, char * n)
  120. {
  121. return 0;
  122. }
  123. static inline void sysfs_remove_link(struct kobject * k, char * name)
  124. {
  125. ;
  126. }
  127. static inline int sysfs_create_bin_file(struct kobject * k, struct bin_attribute * a)
  128. {
  129. return 0;
  130. }
  131. static inline int sysfs_remove_bin_file(struct kobject * k, struct bin_attribute * a)
  132. {
  133. return 0;
  134. }
  135. static inline int sysfs_create_group(struct kobject * k, const struct attribute_group *g)
  136. {
  137. return 0;
  138. }
  139. static inline void sysfs_remove_group(struct kobject * k, const struct attribute_group * g)
  140. {
  141. ;
  142. }
  143. #endif /* CONFIG_SYSFS */
  144. #endif /* _SYSFS_H_ */