sysfs.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 void
  79. sysfs_remove_file(struct kobject *, const struct attribute *);
  80. extern int
  81. sysfs_create_link(struct kobject * kobj, struct kobject * target, char * name);
  82. extern void
  83. sysfs_remove_link(struct kobject *, char * name);
  84. int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr);
  85. int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr);
  86. int sysfs_create_group(struct kobject *, const struct attribute_group *);
  87. void sysfs_remove_group(struct kobject *, const struct attribute_group *);
  88. #else /* CONFIG_SYSFS */
  89. static inline int sysfs_create_dir(struct kobject * k)
  90. {
  91. return 0;
  92. }
  93. static inline void sysfs_remove_dir(struct kobject * k)
  94. {
  95. ;
  96. }
  97. static inline int sysfs_rename_dir(struct kobject * k, const char *new_name)
  98. {
  99. return 0;
  100. }
  101. static inline int sysfs_create_file(struct kobject * k, const struct attribute * a)
  102. {
  103. return 0;
  104. }
  105. static inline int sysfs_update_file(struct kobject * k, const struct attribute * a)
  106. {
  107. return 0;
  108. }
  109. static inline void sysfs_remove_file(struct kobject * k, const struct attribute * a)
  110. {
  111. ;
  112. }
  113. static inline int sysfs_create_link(struct kobject * k, struct kobject * t, char * n)
  114. {
  115. return 0;
  116. }
  117. static inline void sysfs_remove_link(struct kobject * k, char * name)
  118. {
  119. ;
  120. }
  121. static inline int sysfs_create_bin_file(struct kobject * k, struct bin_attribute * a)
  122. {
  123. return 0;
  124. }
  125. static inline int sysfs_remove_bin_file(struct kobject * k, struct bin_attribute * a)
  126. {
  127. return 0;
  128. }
  129. static inline int sysfs_create_group(struct kobject * k, const struct attribute_group *g)
  130. {
  131. return 0;
  132. }
  133. static inline void sysfs_remove_group(struct kobject * k, const struct attribute_group * g)
  134. {
  135. ;
  136. }
  137. #endif /* CONFIG_SYSFS */
  138. #endif /* _SYSFS_H_ */