diff options
| author | Oliver Schinagl <oliver@schinagl.nl> | 2013-07-14 19:05:59 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-07-16 13:57:37 -0400 |
| commit | 3493f69f4c4e8703961919a9a56c2d2e6a25b46f (patch) | |
| tree | 035bd6e86a4193fcda9765dcf7205cc5fb2550a8 /include/linux | |
| parent | d05a6f96c76062b5f25858ac02cf677602076f7e (diff) | |
sysfs: add more helper macro's for (bin_)attribute(_groups)
With the recent changes to sysfs there's various helper macro's.
However there's no RW, RO BIN_ helper macro's. This patch adds them.
Signed-off-by: Oliver Schinagl <oliver@schinagl.nl>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux')
| -rw-r--r-- | include/linux/sysfs.h | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 2c3b6a30697d..d907a7328025 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h | |||
| @@ -17,6 +17,7 @@ | |||
| 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; |
| @@ -94,15 +95,18 @@ struct attribute_group { | |||
| 94 | #define __ATTR_IGNORE_LOCKDEP __ATTR | 95 | #define __ATTR_IGNORE_LOCKDEP __ATTR |
| 95 | #endif | 96 | #endif |
| 96 | 97 | ||
| 97 | #define ATTRIBUTE_GROUPS(name) \ | 98 | #define __ATTRIBUTE_GROUPS(_name) \ |
| 98 | static const struct attribute_group name##_group = { \ | 99 | static const struct attribute_group *_name##_groups[] = { \ |
| 99 | .attrs = name##_attrs, \ | 100 | &_name##_group, \ |
| 100 | }; \ | ||
| 101 | static const struct attribute_group *name##_groups[] = { \ | ||
| 102 | &name##_group, \ | ||
| 103 | NULL, \ | 101 | NULL, \ |
| 104 | } | 102 | } |
| 105 | 103 | ||
| 104 | #define ATTRIBUTE_GROUPS(_name) \ | ||
| 105 | static const struct attribute_group _name##_group = { \ | ||
| 106 | .attrs = _name##_attrs, \ | ||
| 107 | }; \ | ||
| 108 | __ATTRIBUTE_GROUPS(_name) | ||
| 109 | |||
| 106 | #define attr_name(_attr) (_attr).attr.name | 110 | #define attr_name(_attr) (_attr).attr.name |
| 107 | 111 | ||
| 108 | struct file; | 112 | struct file; |
| @@ -132,15 +136,36 @@ struct bin_attribute { | |||
| 132 | */ | 136 | */ |
| 133 | #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) | 137 | #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) |
| 134 | 138 | ||
| 135 | /* macro to create static binary attributes easier */ | 139 | /* macros to create static binary attributes easier */ |
| 136 | #define BIN_ATTR(_name, _mode, _read, _write, _size) \ | 140 | #define __BIN_ATTR(_name, _mode, _read, _write, _size) { \ |
| 137 | struct bin_attribute bin_attr_##_name = { \ | 141 | .attr = { .name = __stringify(_name), .mode = _mode }, \ |
| 138 | .attr = {.name = __stringify(_name), .mode = _mode }, \ | 142 | .read = _read, \ |
| 139 | .read = _read, \ | 143 | .write = _write, \ |
| 140 | .write = _write, \ | 144 | .size = _size, \ |
| 141 | .size = _size, \ | 145 | } |
| 146 | |||
| 147 | #define __BIN_ATTR_RO(_name, _size) { \ | ||
| 148 | .attr = { .name = __stringify(_name), .mode = S_IRUGO }, \ | ||
| 149 | .read = _name##_read, \ | ||
| 150 | .size = _size, \ | ||
| 142 | } | 151 | } |
| 143 | 152 | ||
| 153 | #define __BIN_ATTR_RW(_name, _size) __BIN_ATTR(_name, \ | ||
| 154 | (S_IWUSR | S_IRUGO), _name##_read, \ | ||
| 155 | _name##_write) | ||
| 156 | |||
| 157 | #define __BIN_ATTR_NULL __ATTR_NULL | ||
| 158 | |||
| 159 | #define BIN_ATTR(_name, _mode, _read, _write, _size) \ | ||
| 160 | struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \ | ||
| 161 | _write, _size) | ||
| 162 | |||
| 163 | #define BIN_ATTR_RO(_name, _size) \ | ||
| 164 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size) | ||
| 165 | |||
| 166 | #define BIN_ATTR_RW(_name, _size) \ | ||
| 167 | struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size) | ||
| 168 | |||
| 144 | struct sysfs_ops { | 169 | struct sysfs_ops { |
| 145 | ssize_t (*show)(struct kobject *, struct attribute *,char *); | 170 | ssize_t (*show)(struct kobject *, struct attribute *,char *); |
| 146 | ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); | 171 | ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); |
