Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752044Ab2H2Eyo (ORCPT ); Wed, 29 Aug 2012 00:54:44 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:38320 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751096Ab2H2Eyn (ORCPT ); Wed, 29 Aug 2012 00:54:43 -0400 MIME-Version: 1.0 Date: Wed, 29 Aug 2012 12:54:41 +0800 Message-ID: Subject: [PATCH]Documentation: Chinese translation of Documentation/filesystems/sysfs.txt From: Ninja Tekkaman To: Harry Wei Cc: Greg-Kroah-Hartman , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Patrick Mochel , Mike Murphy , kernel@vger.linux-kernel.cn Content-Type: text/plain; charset=GB2312 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id q7T4sohW020387 Content-Length: 11438 Lines: 395 This is a Chinese translated version of Documentation/filesystems/sysfs.txt Signed-off-by: Fu Wei --- Documentation/zh_CN/filesystems/sysfs.txt | 372 +++++++++++++++++++++++++++++ 1 file changed, 372 insertions(+) create mode 100644 Documentation/zh_CN/filesystems/sysfs.txt diff --git a/Documentation/zh_CN/filesystems/sysfs.txt b/Documentation/zh_CN/filesystems/sysfs.txt new file mode 100644 index 0000000..b4bee3a --- /dev/null +++ b/Documentation/zh_CN/filesystems/sysfs.txt @@ -0,0 +1,372 @@ +Chinese translated version of Documentation/filesystems/sysfs.txt + +If you have any comment or update to the content, please contact the +original document maintainer directly. However, if you have a problem +communicating in English you can also ask the Chinese maintainer for +help. Contact the Chinese maintainer if this translation is outdated +or if there is a problem with the translation. + +Maintainer: Patrick Mochel + Mike Murphy +Chinese maintainer: Fu Wei +--------------------------------------------------------------------- +Documentation/filesystems/sysfs.txt ?????ķ??? + +?????????ۻ????±??ĵ????ݣ???ֱ????ϵԭ?ĵ???ά???ߡ???????ʹ??Ӣ?? +?????????ѵĻ???Ҳ?????????İ?ά???????????????????????²???ʱ???߷? +?????????⣬????ϵ???İ?ά???ߡ? +Ӣ?İ?ά???ߣ? Patrick Mochel + Mike Murphy +???İ?ά???ߣ? ???? Fu Wei +???İ淭???ߣ? ???? Fu Wei +???İ?У???ߣ? ???? Fu Wei + + +????Ϊ???? +--------------------------------------------------------------------- +sysfs - ???ڵ????ں˶???(kobject)???ļ?ϵͳ + +Patrick Mochel +Mike Murphy + +?޶?: 16 August 2011 +ԭʼ?汾: 10 January 2003 + + +sysfs ????: +~~~~~~~~~~ + +sysfs ??һ?????????? ramfs ??λ???ڴ????ļ?ϵͳ?????ṩ?????ں? +???ݽṹ???????ԣ??Լ?????֮???Ĺ??????û??ռ??ķ????? + +sysfs ʼ???? kobject ?ĵײ??ṹ???????ء????Ķ? +Documentation/kobject.txt ?ĵ??Ի??ø??????? kobject ?ӿڵ? +??Ϣ?? + + +ʹ?? sysfs +~~~~~~~~~~~ + +ֻҪ?ں??????ж????? CONFIG_SYSFS ??sysfs ???DZ????????ںˡ????? +ͨ????????????????: + + mount -t sysfs sysfs /sys + + +????Ŀ¼ +~~~~~~~~ + +?κ? kobject ??ϵͳ??ע?ᣬ?ͻ???һ??Ŀ¼?? sysfs ?б??????????? +Ŀ¼????Ϊ?? kobject ?ĸ?????????Ŀ¼????Ŀ¼?????ģ???׼ȷ?ش??? +?ں˵Ķ??????ε??û??ռ䡣sysfs ?еĶ???Ŀ¼???????ں˶??????ε? +??ͬ???ȣ????磺ijЩ????????ij????ϵͳ?? + +Sysfs ??????Ŀ¼?????? sysfs_dirent ???????ڲ?????һ??ָ??ʵ?? +Ŀ¼?? kobject ??ָ?롣??ǰ?????? kobject ָ?뱻 sysfs ֱ?????? +kobject ?ļ??????͹رյ????ü??????????ڵ? sysfs ʵ???У?kobject +???ü???ֻ??ͨ?? sysfs_schedule_callback() ????ֱ???޸ġ? + + +???? +~~~~ + +kobject ?????Կ????ļ?ϵͳ??????ͨ?ļ?????ʽ??????Sysfs Ϊ???Զ??? +???????ļ? I/O ?????ķ????????ṩ???ں????ԵĶ?д?? + + +????ӦΪ ASCII ???ı??ļ?????һ???ļ?ֻ?洢һ??????ֵΪ?ˡ???һ?? +?ļ?ֻ????һ??????ֵ????Ӱ??Ч?ʣ?????һ????????ͬ???????͵?????ֵ +????Ҳ???㷺?ؽ??ܡ? + +???????͡??????????????Լ?һЩ?????????ݸ?ʽ???⵽ǿ?ҷ??ԡ????????? +?ܶ?????,??????????????δ֪ͨ???ߵ??????±???д?? + + +һ???????????Խṹ????????: + +struct attribute { + char * name; + struct module *owner; + umode_t mode; +}; + + +int sysfs_create_file(struct kobject * kobj, const struct attribute * attr); +void sysfs_remove_file(struct kobject * kobj, const struct attribute * attr); + + +һ???????????Խṹ??????????д??????ֵ?ķ???????ϵͳ????Ϊ??ɾ?ض? +???????͵????Զ????Լ??????Խṹ???ͷ?װ?????? + +????:????????ģ?Ͷ????? device_attribute ?ṹ??????: + +struct device_attribute { + struct attribute attr; + ssize_t (*show)(struct device *dev, struct device_attribute *attr, + char *buf); + ssize_t (*store)(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count); +}; + +int device_create_file(struct device *, const struct device_attribute *); +void device_remove_file(struct device *, const struct device_attribute *); + +Ϊ?˶????豸???ԣ?ͬʱ??????һ?¸?????: + +#define DEVICE_ATTR(_name, _mode, _show, _store) \ +struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) + +????:???? + +static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo); + +??ͬ?????´??룺 + +static struct device_attribute dev_attr_foo = { + .attr = { + .name = "foo", + .mode = S_IWUSR | S_IRUGO, + .show = show_foo, + .store = store_foo, + }, +}; + + +??ϵͳ???еĻص????? +~~~~~~~~~~~~~~~~~~~ + +??һ????ϵͳ????һ???µ?????????ʱ??????ʵ??һϵ?е? sysfs ?????? +?԰?????д????ʵ???????????ߵ???ʾ?ʹ??淽???? + +struct sysfs_ops { + ssize_t (*show)(struct kobject *, struct attribute *, char *); + ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); +}; + +[??ϵͳӦ?Ѿ???????һ?? struct kobj_type ?ṹ????Ϊ???????͵? +???????????ڴ˱??? sysfs_ops ??ָ?롣????????Ϣ?μ? kobject ?? +?ĵ?] + +sysfs ??Ϊ???????͵????ʵ??ķ???????һ???ļ?????дʱ???????????? +??һ????kobject ?? attribute ?ṹ??ָ??ת??Ϊ?ʵ???ָ?????ͺ? +???????????ĺ????? + + +ʾ??: + +#define to_dev(obj) container_of(obj, struct device, kobj) +#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) + +static ssize_t dev_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct device_attribute *dev_attr = to_dev_attr(attr); + struct device *dev = to_dev(kobj); + ssize_t ret = -EIO; + + if (dev_attr->show) + ret = dev_attr->show(dev, dev_attr, buf); + if (ret >= (ssize_t)PAGE_SIZE) { + print_symbol("dev_attr_show: %s returned bad count\n", + (unsigned long)dev_attr->show); + } + return ret; +} + + + +??д???????? +~~~~~~~~~~~~ + +??????????ʱ??????ָ?? show() ?? store() ????????ʵ?????Ե? +????д????Щ??????????Ӧ?ú????µ??豸???Զ???һ???????? + +ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf); +ssize_t (*store)(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count); + +Ҳ????˵,????Ӧֻ??һ????????????һ?????Ժ?һ??????ָ????Ϊ?????? + +sysfs ??????һ????СΪ (PAGE_SIZE) ?Ļ??????????ݸ??????????? +Sysfs ????Ϊÿ?ζ?д????????һ??????????????ʹ????Щ??????ִ??ʱ +?????????µ???Ϊ: + +- ?ڶ????棨read(2)????show() ????Ӧ?????????????????????????? + Ӧֻ??????һ??????ֵ????һ??ͬ????????ֵ?????飬???????????۽? + ???᲻̫?ߡ? + + ??ʹ???û??ռ????Ծֲ??ض???????????ǰ?????????ļ????????û??ռ? + ??????????????ʹ?á?0??ƫ??ִ??һ??pread(2)??????show()?????? + ?ٴα????ã??????????仺?档 + +- ??д???棨write(2)????sysfs ϣ???ڵ?һ??д????ʱ?õ????????????? + ֮?? Sysfs ???????????????? store() ?????? + + ??Ҫд sysfs ?ļ?ʱ???û??ռ?????Ӧ???ȶ?ȡ?????ļ????޸???Ҫ + ?ı???ֵ??Ȼ????д???????????? + + ?ڶ?д????ֵʱ?????Է?????ִ??Ӧ??????ͬ?Ļ??????? + +ע??: + +- д???????µ? show() ???????أ??????Ե?ǰ?ļ?λ?á? + +- ??????Ӧ???? PAGE_SIZE ??С??????i386??????ֵΪ4096?? + +- show() ????Ӧ?÷???д?뻺???????ֽ?????Ҳ???? snprintf()?? + ????ֵ?? + +- show() Ӧʼ??ʹ?? snprintf()?? + +- store() Ӧ???ػ????????????ֽ????????????????涼????????ֻ?践?? + count ?????? + +- show() ?? store() ???Է??ش???ֵ?????õ?һ???Ƿ?ֵ?????뷵??һ?? + ????ֵ?? + +- һ?????ݸ??????Ķ???????ͨ?? sysfs ???ö?????Ƕ?????ü????̶??? + ?ڴ??С????????ˣ???????????????ʵ??(???豸)?????Ѳ????ڡ????б?Ҫ?? + Ӧ??ʵ??һ?????????ơ? + +һ????????(δ??ʵ??֤ʵ??)?豸????ʵ?????£? + +static ssize_t show_name(struct device *dev, struct device_attribute *attr, + char *buf) +{ + return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name); +} + +static ssize_t store_name(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + snprintf(dev->name, sizeof(dev->name), "%.*s", + (int)min(count, sizeof(dev->name) - 1), buf); + return count; +} + +static DEVICE_ATTR(name, S_IRUGO, show_name, store_name); + + +??ע?⣺??????ʵ?ֲ??????û??ռ??????豸?????? + +????Ŀ¼???? +~~~~~~~~~~~~ + +sysfs Ŀ¼?İ?????ʾ???ں????ݽṹ֮???Ĺ?ϵ?? + +???? sysfs Ŀ¼????: + +block/ +bus/ +class/ +dev/ +devices/ +firmware/ +net/ +fs/ + +devices/ ??????һ???豸?????ļ?ϵͳ??ʾ????ֱ??ӳ?????ڲ????ں? +?豸??????ӳ???豸?IJ??νṹ?? + +bus/ ???????ں??и??????????͵?ƽ??Ŀ¼???֡?ÿ??????Ŀ¼???????? +??Ŀ¼: + + devices/ + drivers/ + +devices/ ??????ϵͳ?г??ֵ?ÿ???豸?ķ??????ӣ?????ָ?? root/ ?µ? +?豸Ŀ¼?? + +drivers/ ??????ÿ????Ϊ?ض??????ϵ??豸?????ص???????????Ŀ¼(???? +?ٶ?????û?п?Խ????????????)?? + +fs/ ??????һ??Ϊ?ļ?ϵͳ??????Ŀ¼??????ÿ????Ҫ???????Ե??ļ?ϵͳ???? +?? fs/ ?´????Լ??IJ??νṹ(?μ?Documentation/filesystems/fuse.txt)?? + +dev/ ??????????Ŀ¼?? char/ ?? block/????????????Ŀ¼?У????? +: ??ʽ?????ķ??????ӡ???Щ????????ָ?? sysfs Ŀ¼ +????Ӧ???豸??/sys/dev ?ṩһ??ͨ??һ?? stat(2) ?????????????? +?豸 sysfs ?ӿڿ??ݵķ????? + +?????й? driver-model ????????Ϣ?????? Documentation/driver-model/ +???ҵ??? + + +TODO: ??????һ?ڡ? + + +??ǰ?ӿ? +~~~~~~~~ + +???µĽӿڲ??ձ??????ڵ?ǰ??sysfs??: + +- ?豸 (include/linux/device.h) +---------------------------------- +?ṹ??: + +struct device_attribute { + struct attribute attr; + ssize_t (*show)(struct device *dev, struct device_attribute *attr, + char *buf); + ssize_t (*store)(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count); +}; + +????: + +DEVICE_ATTR(_name, _mode, _show, _store); + +??/ɾ????: + +int device_create_file(struct device *dev, const struct device_attribute * attr); +void device_remove_file(struct device *dev, const struct device_attribute * attr); + + +- ???????????? (include/linux/device.h) +-------------------------------------- +?ṹ??: + +struct bus_attribute { + struct attribute attr; + ssize_t (*show)(struct bus_type *, char * buf); + ssize_t (*store)(struct bus_type *, const char * buf, size_t count); +}; + +????: + +BUS_ATTR(_name, _mode, _show, _store) + +??/ɾ????: + +int bus_create_file(struct bus_type *, struct bus_attribute *); +void bus_remove_file(struct bus_type *, struct bus_attribute *); + + +- ?豸???????? (include/linux/device.h) +----------------------------------------- + +?ṹ??: + +struct driver_attribute { + struct attribute attr; + ssize_t (*show)(struct device_driver *, char * buf); + ssize_t (*store)(struct device_driver *, const char * buf, + size_t count); +}; + +????: + +DRIVER_ATTR(_name, _mode, _show, _store) + +??/ɾ???ԣ? + +int driver_create_file(struct device_driver *, const struct driver_attribute *); +void driver_remove_file(struct device_driver *, const struct driver_attribute *); + + +?ĵ? +~~~~ + +sysfs Ŀ¼?ṹ?Լ????а????????Զ?????һ???ں????û??ռ?֮???? ABI?? +?????κ? ABI???????????ȶ????ʵ????ĵ??Ƿdz???Ҫ?ġ??????µ? sysfs +???Ա????? Documentation/ABI ?????ĵ??????? Documentation/ABI/README?? -- 1.7.9.5 ????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?