aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/filesystems/sysfs.txt28
1 files changed, 14 insertions, 14 deletions
diff --git a/Documentation/filesystems/sysfs.txt b/Documentation/filesystems/sysfs.txt
index dc276598a65a..c8bce82ddcac 100644
--- a/Documentation/filesystems/sysfs.txt
+++ b/Documentation/filesystems/sysfs.txt
@@ -90,7 +90,7 @@ void device_remove_file(struct device *, struct device_attribute *);
90 90
91It also defines this helper for defining device attributes: 91It also defines this helper for defining device attributes:
92 92
93#define DEVICE_ATTR(_name,_mode,_show,_store) \ 93#define DEVICE_ATTR(_name, _mode, _show, _store) \
94struct device_attribute dev_attr_##_name = { \ 94struct device_attribute dev_attr_##_name = { \
95 .attr = {.name = __stringify(_name) , .mode = _mode }, \ 95 .attr = {.name = __stringify(_name) , .mode = _mode }, \
96 .show = _show, \ 96 .show = _show, \
@@ -99,14 +99,14 @@ struct device_attribute dev_attr_##_name = { \
99 99
100For example, declaring 100For example, declaring
101 101
102static DEVICE_ATTR(foo,0644,show_foo,store_foo); 102static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo);
103 103
104is equivalent to doing: 104is equivalent to doing:
105 105
106static struct device_attribute dev_attr_foo = { 106static struct device_attribute dev_attr_foo = {
107 .attr = { 107 .attr = {
108 .name = "foo", 108 .name = "foo",
109 .mode = 0644, 109 .mode = S_IWUSR | S_IRUGO,
110 }, 110 },
111 .show = show_foo, 111 .show = show_foo,
112 .store = store_foo, 112 .store = store_foo,
@@ -121,8 +121,8 @@ set of sysfs operations for forwarding read and write calls to the
121show and store methods of the attribute owners. 121show and store methods of the attribute owners.
122 122
123struct sysfs_ops { 123struct sysfs_ops {
124 ssize_t (*show)(struct kobject *, struct attribute *,char *); 124 ssize_t (*show)(struct kobject *, struct attribute *, char *);
125 ssize_t (*store)(struct kobject *,struct attribute *,const char *); 125 ssize_t (*store)(struct kobject *, struct attribute *, const char *);
126}; 126};
127 127
128[ Subsystems should have already defined a struct kobj_type as a 128[ Subsystems should have already defined a struct kobj_type as a
@@ -137,7 +137,7 @@ calls the associated methods.
137 137
138To illustrate: 138To illustrate:
139 139
140#define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr) 140#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
141#define to_dev(d) container_of(d, struct device, kobj) 141#define to_dev(d) container_of(d, struct device, kobj)
142 142
143static ssize_t 143static ssize_t
@@ -148,7 +148,7 @@ dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf)
148 ssize_t ret = 0; 148 ssize_t ret = 0;
149 149
150 if (dev_attr->show) 150 if (dev_attr->show)
151 ret = dev_attr->show(dev,buf); 151 ret = dev_attr->show(dev, buf);
152 return ret; 152 return ret;
153} 153}
154 154
@@ -216,16 +216,16 @@ A very simple (and naive) implementation of a device attribute is:
216 216
217static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) 217static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
218{ 218{
219 return sprintf(buf,"%s\n",dev->name); 219 return snprintf(buf, PAGE_SIZE, "%s\n", dev->name);
220} 220}
221 221
222static ssize_t store_name(struct device * dev, const char * buf) 222static ssize_t store_name(struct device * dev, const char * buf)
223{ 223{
224 sscanf(buf,"%20s",dev->name); 224 sscanf(buf, "%20s", dev->name);
225 return strlen(buf); 225 return strnlen(buf, PAGE_SIZE);
226} 226}
227 227
228static DEVICE_ATTR(name,S_IRUGO,show_name,store_name); 228static DEVICE_ATTR(name, S_IRUGO, show_name, store_name);
229 229
230 230
231(Note that the real implementation doesn't allow userspace to set the 231(Note that the real implementation doesn't allow userspace to set the
@@ -290,7 +290,7 @@ struct device_attribute {
290 290
291Declaring: 291Declaring:
292 292
293DEVICE_ATTR(_name,_str,_mode,_show,_store); 293DEVICE_ATTR(_name, _str, _mode, _show, _store);
294 294
295Creation/Removal: 295Creation/Removal:
296 296
@@ -310,7 +310,7 @@ struct bus_attribute {
310 310
311Declaring: 311Declaring:
312 312
313BUS_ATTR(_name,_mode,_show,_store) 313BUS_ATTR(_name, _mode, _show, _store)
314 314
315Creation/Removal: 315Creation/Removal:
316 316
@@ -331,7 +331,7 @@ struct driver_attribute {
331 331
332Declaring: 332Declaring:
333 333
334DRIVER_ATTR(_name,_mode,_show,_store) 334DRIVER_ATTR(_name, _mode, _show, _store)
335 335
336Creation/Removal: 336Creation/Removal:
337 337