diff options
Diffstat (limited to 'include/linux/sysfs.h')
| -rw-r--r-- | include/linux/sysfs.h | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index e2cee22f578a..9e8a9b555ad6 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h | |||
| @@ -17,10 +17,12 @@ | |||
| 17 | #include <linux/list.h> | 17 | #include <linux/list.h> |
| 18 | #include <linux/lockdep.h> | 18 | #include <linux/lockdep.h> |
| 19 | #include <linux/kobject_ns.h> | 19 | #include <linux/kobject_ns.h> |
| 20 | #include <linux/stat.h> | ||
| 20 | #include <linux/atomic.h> | 21 | #include <linux/atomic.h> |
| 21 | 22 | ||
| 22 | struct kobject; | 23 | struct kobject; |
| 23 | struct module; | 24 | struct module; |
| 25 | struct bin_attribute; | ||
| 24 | enum kobj_ns_type; | 26 | enum kobj_ns_type; |
| 25 | 27 | ||
| 26 | struct attribute { | 28 | struct attribute { |
| @@ -59,26 +61,28 @@ struct attribute_group { | |||
| 59 | umode_t (*is_visible)(struct kobject *, | 61 | umode_t (*is_visible)(struct kobject *, |
| 60 | struct attribute *, int); | 62 | struct attribute *, int); |
| 61 | struct attribute **attrs; | 63 | struct attribute **attrs; |
| 64 | struct bin_attribute **bin_attrs; | ||
| 62 | }; | 65 | }; |
| 63 | 66 | ||
| 64 | |||
| 65 | |||
| 66 | /** | 67 | /** |
| 67 | * Use these macros to make defining attributes easier. See include/linux/device.h | 68 | * Use these macros to make defining attributes easier. See include/linux/device.h |
| 68 | * for examples.. | 69 | * for examples.. |
| 69 | */ | 70 | */ |
| 70 | 71 | ||
| 71 | #define __ATTR(_name,_mode,_show,_store) { \ | 72 | #define __ATTR(_name,_mode,_show,_store) { \ |
| 72 | .attr = {.name = __stringify(_name), .mode = _mode }, \ | 73 | .attr = {.name = __stringify(_name), .mode = _mode }, \ |
| 73 | .show = _show, \ | 74 | .show = _show, \ |
| 74 | .store = _store, \ | 75 | .store = _store, \ |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | #define __ATTR_RO(_name) { \ | 78 | #define __ATTR_RO(_name) { \ |
| 78 | .attr = { .name = __stringify(_name), .mode = 0444 }, \ | 79 | .attr = { .name = __stringify(_name), .mode = S_IRUGO }, \ |
| 79 | .show = _name##_show, \ | 80 | .show = _name##_show, \ |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 83 | #define __ATTR_RW(_name) __ATTR(_name, (S_IWUSR | S_IRUGO), \ | ||
| 84 | _name##_show, _name##_store) | ||
| 85 | |||
| 82 | #define __ATTR_NULL { .attr = { .name = NULL } } | 86 | #define __ATTR_NULL { .attr = { .name = NULL } } |
| 83 | 87 | ||
| 84 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 88 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| @@ -92,6 +96,18 @@ struct attribute_group { | |||
| 92 | #define __ATTR_IGNORE_LOCKDEP __ATTR | 96 | #define __ATTR_IGNORE_LOCKDEP __ATTR |
| 93 | #endif | 97 | #endif |
| 94 | 98 | ||
| 99 | #define __ATTRIBUTE_GROUPS(_name) \ | ||
| 100 | static const struct attribute_group *_name##_groups[] = { \ | ||
| 101 | &_name##_group, \ | ||
| 102 | NULL, \ | ||
| 103 | } | ||
| 104 | |||
| 105 | #define ATTRIBUTE_GROUPS(_name) \ | ||
| 106 | static const struct attribute_group _name##_group = { \ | ||
| 107 | .attrs = _name##_attrs, \ | ||
| 108 | }; \ | ||
| 109 | __ATTRIBUTE_GROUPS(_name) | ||
| 110 | |||
| 95 | #define attr_name(_attr) (_attr).attr.name | 111 | #define attr_name(_attr) (_attr).attr.name |
| 96 | 112 | ||
| 97 | struct file; | 113 | struct file; |
| @@ -121,6 +137,36 @@ struct bin_attribute { | |||
| 121 | */ | 137 | */ |
| 122 | #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) | 138 | #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) |
| 123 | 139 | ||
| 140 | /* macros to create static binary attributes easier */ | ||
| 141 | #define __BIN_ATTR(_name, _mode, _read, _write, _size) { \ | ||
| 142 | .attr = { .name = __stringify(_name), .mode = _mode }, \ | ||
| 143 | .read = _read, \ | ||
| 144 | .write = _write, \ | ||
| 145 | .size = _size, \ | ||
| 146 | } | ||
| 147 | |||
| 148 | #define __BIN_ATTR_RO(_name, _size) { \ | ||
| 149 | .attr = { .name = __stringify(_name), .mode = S_IRUGO }, \ | ||
| 150 | .read = _name##_read, \ | ||
| 151 | .size = _size, \ | ||
| 152 | } | ||
| 153 | |||
| 154 | #define __BIN_ATTR_RW(_name, _size) __BIN_ATTR(_name, \ | ||
| 155 | (S_IWUSR | S_IRUGO), _name##_read, \ | ||
| 156 | _name##_write) | ||
| 157 | |||
| 158 | #define __BIN_ATTR_NULL __ATTR_NULL | ||
| 159 | |||
| 160 | #define BIN_ATTR(_name, _mode, _read, _write, _size) \ | ||
| 161 | struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \ | ||
| 162 | _write, _size) | ||
| 163 | |||
| 164 | #define BIN_ATTR_RO(_name, _size) \ | ||
| 165 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size) | ||
| 166 | |||
| 167 | #define BIN_ATTR_RW(_name, _size) \ | ||
| 168 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size) | ||
| 169 | |||
| 124 | struct sysfs_ops { | 170 | struct sysfs_ops { |
| 125 | ssize_t (*show)(struct kobject *, struct attribute *,char *); | 171 | ssize_t (*show)(struct kobject *, struct attribute *,char *); |
| 126 | ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); | 172 | ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); |
