1Chinese translated version of Documentation/filesystems/sysfs.txt
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly.  However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help.  Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Maintainer: Patrick Mochel	<mochel@osdl.org>
10		Mike Murphy <mamurph@cs.clemson.edu>
11Chinese maintainer: Fu Wei <tekkamanninja@gmail.com>
12---------------------------------------------------------------------
13Documentation/filesystems/sysfs.txt ���������������
14
15������������������������������������������������������������������������������������������������������
16������������������������������������������������������������������������������������������������������
17������������������������������������������������
18��������������������� Patrick Mochel	<mochel@osdl.org>
19		Mike Murphy <mamurph@cs.clemson.edu>
20��������������������� ������ Fu Wei <tekkamanninja@gmail.com>
21��������������������� ������ Fu Wei <tekkamanninja@gmail.com>
22��������������������� ������ Fu Wei <tekkamanninja@gmail.com>
23
24
25���������������
26---------------------------------------------------------------------
27sysfs - ������������������������(kobject)���������������
28
29Patrick Mochel	<mochel@osdl.org>
30Mike Murphy <mamurph@cs.clemson.edu>
31
32������:    16 August 2011
33������������:   10 January 2003
34
35
36sysfs ������:
37~~~~~~~~~~
38
39sysfs ��������������������� ramfs ������������������������������������������������������
40���������������������������������������������������������������������������������
41
42sysfs ��������� kobject ���������������������������������������
43Documentation/kobject.txt ��������������������������� kobject ���������
44���������
45
46
47������ sysfs
48~~~~~~~~~~~
49
50������������������������������ CONFIG_SYSFS ���sysfs ���������������������������������
51���������������������������:
52
53    mount -t sysfs sysfs /sys
54
55
56������������
57~~~~~~~~
58
59������ kobject ��������������������������������������������� sysfs ���������������������
60������������������ kobject ������������������������������������������������������������������
61���������������������������������������sysfs ������������������������������������������������
62������������������������������������������������������������
63
64Sysfs ������������������������ kernfs_node ���������������������������������������
65��������� kobject ��������������������������� kobject ��������� sysfs ������������
66kobject ��������������������������������������������������� sysfs ������������kobject
67������������������������ sysfs_schedule_callback() ���������������������
68
69
70������
71~~~~
72
73kobject ���������������������������������������������������������������Sysfs ���������������
74��������������� I/O ������������������������������������������������������
75
76
77������������ ASCII ���������������������������������������������������������������������������
78���������������������������������������������������������������������������������������������������
79������������������������������
80
81������������������������������������������������������������������������������������������������������
82������������,������������������������������������������������������������
83
84
85���������������������������������������:
86
87struct attribute {
88        char                    * name;
89        struct module		*owner;
90        umode_t                 mode;
91};
92
93
94int sysfs_create_file(struct kobject * kobj, const struct attribute * attr);
95void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr);
96
97
98���������������������������������������������������������������������������������������������������
99���������������������������������������������������������������������
100
101������:��������������������������� device_attribute ���������������:
102
103struct device_attribute {
104	struct attribute	attr;
105	ssize_t (*show)(struct device *dev, struct device_attribute *attr,
106			char *buf);
107	ssize_t (*store)(struct device *dev, struct device_attribute *attr,
108			 const char *buf, size_t count);
109};
110
111int device_create_file(struct device *, const struct device_attribute *);
112void device_remove_file(struct device *, const struct device_attribute *);
113
114���������������������������������������������������������:
115
116#define DEVICE_ATTR(_name, _mode, _show, _store) \
117struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
118
119������:������
120
121static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo);
122
123������������������������
124
125static struct device_attribute dev_attr_foo = {
126       .attr	= {
127		.name = "foo",
128		.mode = S_IWUSR | S_IRUGO,
129		.show = show_foo,
130		.store = store_foo,
131	},
132};
133
134
135������������������������������
136~~~~~~~~~~~~~~~~~~~
137
138������������������������������������������������������������������������������ sysfs ���������
139���������������������������������������������������������������������
140
141struct sysfs_ops {
142        ssize_t (*show)(struct kobject *, struct attribute *, char *);
143        ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
144};
145
146[��������������������������������� struct kobj_type ������������������������������
147��������������������������� sysfs_ops ��������������������������������� kobject ���
148������]
149
150sysfs ���������������������������������������������������������������������������������������
151������������kobject ��� attribute ������������������������������������������������
152���������������������������
153
154
155������:
156
157#define to_dev(obj) container_of(obj, struct device, kobj)
158#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
159
160static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr,
161                             char *buf)
162{
163        struct device_attribute *dev_attr = to_dev_attr(attr);
164        struct device *dev = to_dev(kobj);
165        ssize_t ret = -EIO;
166
167        if (dev_attr->show)
168                ret = dev_attr->show(dev, dev_attr, buf);
169        if (ret >= (ssize_t)PAGE_SIZE) {
170                print_symbol("dev_attr_show: %s returned bad count\n",
171                                (unsigned long)dev_attr->show);
172        }
173        return ret;
174}
175
176
177
178������������������
179~~~~~~~~~~~~
180
181��������������������������������� show() ��� store() ���������������������������
182������������������������������������������������������������������������������������
183
184ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);
185ssize_t (*store)(struct device *dev, struct device_attribute *attr,
186                 const char *buf, size_t count);
187
188������������,������������������������������������������������������������������������������������
189
190sysfs ������������������������ (PAGE_SIZE) ���������������������������������������
191Sysfs ���������������������������������������������������������������������������������������
192������������������������:
193
194- ���������������read(2)������show() ������������������������������������������������
195  ���������������������������������������������������������������������������������������������
196  ������������������
197
198  ������������������������������������������������������������������������������������������������
199  ������������������������������0���������������������pread(2)���������show()���������
200  ������������������������������������������
201
202- ���������������write(2)������sysfs ������������������������������������������������������
203  ������ Sysfs ������������������������ store() ���������
204
205  ��������� sysfs ������������������������������������������������������������������������
206  ���������������������������������������������
207
208  ���������������������������������������������������������������������������
209
210������:
211
212- ������������������ show() ���������������������������������������������
213
214- ������������������ PAGE_SIZE ���������������i386���������������4096���
215
216- show() ��������������������������������������������������������� snprintf()���
217  ������������
218
219- show() ��������������� snprintf()���
220
221- store() ������������������������������������������������������������������������������������
222  count ���������
223
224- show() ��� store() ���������������������������������������������������������������������
225  ������������
226
227- ������������������������������������������ sysfs ������������������������������������������
228  ������������������������������������������������������(���������)������������������������������������
229  ���������������������������������
230
231���������������(���������������������)���������������������������
232
233static ssize_t show_name(struct device *dev, struct device_attribute *attr,
234                         char *buf)
235{
236	return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name);
237}
238
239static ssize_t store_name(struct device *dev, struct device_attribute *attr,
240                          const char *buf, size_t count)
241{
242        snprintf(dev->name, sizeof(dev->name), "%.*s",
243                 (int)min(count, sizeof(dev->name) - 1), buf);
244	return count;
245}
246
247static DEVICE_ATTR(name, S_IRUGO, show_name, store_name);
248
249
250���������������������������������������������������������������������
251
252������������������
253~~~~~~~~~~~~
254
255sysfs ������������������������������������������������������������
256
257������ sysfs ������������:
258
259block/
260bus/
261class/
262dev/
263devices/
264firmware/
265net/
266fs/
267
268devices/ ���������������������������������������������������������������������������������
269���������������������������������������������
270
271bus/ ������������������������������������������������������������������������������������������
272���������:
273
274	devices/
275	drivers/
276
277devices/ ��������������������������������������������������������������������� root/ ������
278���������������
279
280drivers/ ������������������������������������������������������������������������������(������
281������������������������������������������)���
282
283fs/ ���������������������������������������������������������������������������������������������������
284��� fs/ ������������������������������(������Documentation/filesystems/fuse.txt)���
285
286dev/ ������������������������ char/ ��� block/������������������������������������
287<major>:<minor> ������������������������������������������������������ sysfs ������
288���������������������/sys/dev ������������������������ stat(2) ���������������������
289������ sysfs ������������������������
290
291������������ driver-model ������������������������ Documentation/driver-model/
292������������
293
294
295TODO: ������������������
296
297
298������������
299~~~~~~~~
300
301������������������������������������������sysfs���:
302
303- ������ (include/linux/device.h)
304----------------------------------
305���������:
306
307struct device_attribute {
308	struct attribute	attr;
309	ssize_t (*show)(struct device *dev, struct device_attribute *attr,
310			char *buf);
311	ssize_t (*store)(struct device *dev, struct device_attribute *attr,
312			 const char *buf, size_t count);
313};
314
315������:
316
317DEVICE_ATTR(_name, _mode, _show, _store);
318
319���/���������:
320
321int device_create_file(struct device *dev, const struct device_attribute * attr);
322void device_remove_file(struct device *dev, const struct device_attribute * attr);
323
324
325- ������������������ (include/linux/device.h)
326--------------------------------------
327���������:
328
329struct bus_attribute {
330        struct attribute        attr;
331        ssize_t (*show)(struct bus_type *, char * buf);
332        ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
333};
334
335������:
336
337BUS_ATTR(_name, _mode, _show, _store)
338
339���/���������:
340
341int bus_create_file(struct bus_type *, struct bus_attribute *);
342void bus_remove_file(struct bus_type *, struct bus_attribute *);
343
344
345- ������������������ (include/linux/device.h)
346-----------------------------------------
347
348���������:
349
350struct driver_attribute {
351        struct attribute        attr;
352        ssize_t (*show)(struct device_driver *, char * buf);
353        ssize_t (*store)(struct device_driver *, const char * buf,
354                         size_t count);
355};
356
357������:
358
359DRIVER_ATTR(_name, _mode, _show, _store)
360
361���/������������
362
363int driver_create_file(struct device_driver *, const struct driver_attribute *);
364void driver_remove_file(struct device_driver *, const struct driver_attribute *);
365
366
367������
368~~~~
369
370sysfs ������������������������������������������������������������������������������������ ABI���
371������������ ABI������������������������������������������������������������������������ sysfs
372��������������� Documentation/ABI ��������������������� Documentation/ABI/README���
373