sphinx.addnodesdocument)}( rawsourcechildren]( translations LanguagesNode)}(hhh](h pending_xref)}(hhh]docutils.nodesTextChinese (Simplified)}parenthsba attributes}(ids]classes]names]dupnames]backrefs] refdomainstdreftypedoc reftarget%/translations/zh_CN/filesystems/sysfsmodnameN classnameN refexplicitutagnamehhh ubh)}(hhh]hChinese (Traditional)}hh2sbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/zh_TW/filesystems/sysfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hItalian}hhFsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/it_IT/filesystems/sysfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hJapanese}hhZsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/ja_JP/filesystems/sysfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hKorean}hhnsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/ko_KR/filesystems/sysfsmodnameN classnameN refexplicituh1hhh ubh)}(hhh]hSpanish}hhsbah}(h]h ]h"]h$]h&] refdomainh)reftypeh+ reftarget%/translations/sp_SP/filesystems/sysfsmodnameN classnameN refexplicituh1hhh ubeh}(h]h ]h"]h$]h&]current_languageEnglishuh1h hh _documenthsourceNlineNubhcomment)}(h SPDX-License-Identifier: GPL-2.0h]h SPDX-License-Identifier: GPL-2.0}hhsbah}(h]h ]h"]h$]h&] xml:spacepreserveuh1hhhhhh?/var/lib/git/docbuild/linux/Documentation/filesystems/sysfs.rsthKubhsection)}(hhh](htitle)}(h5sysfs - _The_ filesystem for exporting kernel objectsh]h5sysfs - _The_ filesystem for exporting kernel objects}(hhhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhhhhhKubh paragraph)}(h!Patrick Mochel h](hPatrick Mochel <}(hhhhhNhNubh reference)}(hmochel@osdl.orgh]hmochel@osdl.org}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:mochel@osdl.orguh1hhhubh>}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhKhhhhubh)}(h$Mike Murphy h](h Mike Murphy <}(hhhhhNhNubh)}(hmamurph@cs.clemson.eduh]hmamurph@cs.clemson.edu}(hhhhhNhNubah}(h]h ]h"]h$]h&]refurimailto:mamurph@cs.clemson.eduuh1hhhubh>}(hhhhhNhNubeh}(h]h ]h"]h$]h&]uh1hhhhK hhhhubh field_list)}(hhh](hfield)}(hhh](h field_name)}(hRevisedh]hRevised}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjhhhKubh field_body)}(h16 August 2011h]h)}(hj/h]h16 August 2011}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hj-ubah}(h]h ]h"]h$]h&]uh1j+hjubeh}(h]h ]h"]h$]h&]uh1jhhhK hjhhubj)}(hhh](j)}(hOriginalh]hOriginal}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1jhjJhhhKubj,)}(h10 January 2003 h]h)}(h10 January 2003h]h10 January 2003}(hj_hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK hj[ubah}(h]h ]h"]h$]h&]uh1j+hjJubeh}(h]h ]h"]h$]h&]uh1jhhhK hjhhubeh}(h]h ]h"]h$]h&]uh1jhhhhhhhK ubh)}(hhh](h)}(h What it ish]h What it is}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hsysfs is a RAM-based filesystem initially based on ramfs. It provides a means to export kernel data structures, their attributes, and the linkages between them to userspace.h]hsysfs is a RAM-based filesystem initially based on ramfs. It provides a means to export kernel data structures, their attributes, and the linkages between them to userspace.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hsysfs is tied inherently to the kobject infrastructure. Please read Documentation/core-api/kobject.rst for more information concerning the kobject interface.h]hsysfs is tied inherently to the kobject infrastructure. Please read Documentation/core-api/kobject.rst for more information concerning the kobject interface.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubeh}(h] what-it-isah ]h"] what it isah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(h Using sysfsh]h Using sysfs}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hTsysfs is always compiled in if CONFIG_SYSFS is defined. You can access it by doing::h]hSsysfs is always compiled in if CONFIG_SYSFS is defined. You can access it by doing:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh literal_block)}(hmount -t sysfs sysfs /sysh]hmount -t sysfs sysfs /sys}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhK!hjhhubeh}(h] using-sysfsah ]h"] using sysfsah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hDirectory Creationh]hDirectory Creation}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhK%ubh)}(hXWFor every kobject that is registered with the system, a directory is created for it in sysfs. That directory is created as a subdirectory of the kobject's parent, expressing internal object hierarchies to userspace. Top-level directories in sysfs represent the common ancestors of object hierarchies; i.e. the subsystems the objects belong to.h]hXYFor every kobject that is registered with the system, a directory is created for it in sysfs. That directory is created as a subdirectory of the kobject’s parent, expressing internal object hierarchies to userspace. Top-level directories in sysfs represent the common ancestors of object hierarchies; i.e. the subsystems the objects belong to.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK'hjhhubh)}(hXsysfs internally stores a pointer to the kobject that implements a directory in the kernfs_node object associated with the directory. In the past this kobject pointer has been used by sysfs to do reference counting directly on the kobject whenever the file is opened or closed. With the current sysfs implementation the kobject reference count is only modified directly by the function sysfs_schedule_callback().h]hXsysfs internally stores a pointer to the kobject that implements a directory in the kernfs_node object associated with the directory. In the past this kobject pointer has been used by sysfs to do reference counting directly on the kobject whenever the file is opened or closed. With the current sysfs implementation the kobject reference count is only modified directly by the function sysfs_schedule_callback().}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK.hjhhubeh}(h]directory-creationah ]h"]directory creationah$]h&]uh1hhhhhhhhK%ubh)}(hhh](h)}(h Attributesh]h Attributes}(hj#hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhK7ubh)}(hAttributes can be exported for kobjects in the form of regular files in the filesystem. sysfs forwards file I/O operations to methods defined for the attributes, providing a means to read and write kernel attributes.h]hAttributes can be exported for kobjects in the form of regular files in the filesystem. sysfs forwards file I/O operations to methods defined for the attributes, providing a means to read and write kernel attributes.}(hj1hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK9hj hhubh)}(hAttributes should be ASCII text files, preferably with only one value per file. It is noted that it may not be efficient to contain only one value per file, so it is socially acceptable to express an array of values of the same type.h]hAttributes should be ASCII text files, preferably with only one value per file. It is noted that it may not be efficient to contain only one value per file, so it is socially acceptable to express an array of values of the same type.}(hj?hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhK>hj hhubh)}(hMixing types, expressing multiple lines of data, and doing fancy formatting of data is heavily frowned upon. Doing these things may get you publicly humiliated and your code rewritten without notice.h]hMixing types, expressing multiple lines of data, and doing fancy formatting of data is heavily frowned upon. Doing these things may get you publicly humiliated and your code rewritten without notice.}(hjMhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKChj hhubh)}(h#An attribute definition is simply::h]h"An attribute definition is simply:}(hj[hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKHhj hhubj)}(hX'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);h]hX'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);}hjisbah}(h]h ]h"]h$]h&]hhuh1jhhhKJhj hhubh)}(hA bare attribute contains no means to read or write the value of the attribute. Subsystems are encouraged to define their own attribute structure and wrapper functions for adding and removing attributes for a specific object type.h]hA bare attribute contains no means to read or write the value of the attribute. Subsystems are encouraged to define their own attribute structure and wrapper functions for adding and removing attributes for a specific object type.}(hjwhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKUhj hhubh)}(hDFor example, the driver model defines struct device_attribute like::h]hCFor example, the driver model defines struct device_attribute like:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKZhj hhubj)}(hXstruct 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 *);h]hXstruct 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 *);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhK\hj hhubh)}(hshow) ret = dev_attr->show(dev, dev_attr, buf); if (ret >= (ssize_t)PAGE_SIZE) { printk("dev_attr_show: %pS returned bad count\n", dev_attr->show); } return ret; }h]hX`#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 = kobj_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) { printk("dev_attr_show: %pS returned bad count\n", dev_attr->show); } return ret; }}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhj1hhubeh}(h]subsystem-specific-callbacksah ]h"]subsystem-specific callbacksah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hReading/Writing Attribute Datah]hReading/Writing Attribute Data}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhKubh)}(hTo read or write attributes, show() or store() methods must be specified when declaring the attribute. The method types should be as simple as those defined for device attributes::h]hTo read or write attributes, show() or store() methods must be specified when declaring the attribute. The method types should be as simple as those defined for device attributes:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hssize_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);h]hssize_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);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhKhjhhubh)}(hOIOW, they should take only an object, an attribute, and a buffer as parameters.h]hOIOW, they should take only an object, an attribute, and a buffer as parameters.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh)}(hsysfs allocates a buffer of size (PAGE_SIZE) and passes it to the method. sysfs will call the method exactly once for each read or write. This forces the following behavior on the method implementations:h]hsysfs allocates a buffer of size (PAGE_SIZE) and passes it to the method. sysfs will call the method exactly once for each read or write. This forces the following behavior on the method implementations:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubh bullet_list)}(hhh](h list_item)}(hXOn read(2), the show() method should fill the entire buffer. Recall that an attribute should only be exporting one value, or an array of similar values, so this shouldn't be that expensive. This allows userspace to do partial reads and forward seeks arbitrarily over the entire file at will. If userspace seeks back to zero or does a pread(2) with an offset of '0' the show() method will be called again, rearmed, to fill the buffer. h](h)}(hOn read(2), the show() method should fill the entire buffer. Recall that an attribute should only be exporting one value, or an array of similar values, so this shouldn't be that expensive.h]hOn read(2), the show() method should fill the entire buffer. Recall that an attribute should only be exporting one value, or an array of similar values, so this shouldn’t be that expensive.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hThis allows userspace to do partial reads and forward seeks arbitrarily over the entire file at will. If userspace seeks back to zero or does a pread(2) with an offset of '0' the show() method will be called again, rearmed, to fill the buffer.h]hThis allows userspace to do partial reads and forward seeks arbitrarily over the entire file at will. If userspace seeks back to zero or does a pread(2) with an offset of ‘0’ the show() method will be called again, rearmed, to fill the buffer.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjhhhhhNubj)}(hXOn write(2), sysfs expects the entire buffer to be passed during the first write. sysfs then passes the entire buffer to the store() method. A terminating null is added after the data on stores. This makes functions like sysfs_streq() safe to use. When writing sysfs files, userspace processes should first read the entire file, modify the values it wishes to change, then write the entire buffer back. Attribute method implementations should operate on an identical buffer when reading and writing values. h](h)}(hOn write(2), sysfs expects the entire buffer to be passed during the first write. sysfs then passes the entire buffer to the store() method. A terminating null is added after the data on stores. This makes functions like sysfs_streq() safe to use.h]hOn write(2), sysfs expects the entire buffer to be passed during the first write. sysfs then passes the entire buffer to the store() method. A terminating null is added after the data on stores. This makes functions like sysfs_streq() safe to use.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hWhen writing sysfs files, userspace processes should first read the entire file, modify the values it wishes to change, then write the entire buffer back.h]hWhen writing sysfs files, userspace processes should first read the entire file, modify the values it wishes to change, then write the entire buffer back.}(hj&hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubh)}(hgAttribute method implementations should operate on an identical buffer when reading and writing values.h]hgAttribute method implementations should operate on an identical buffer when reading and writing values.}(hj4hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubeh}(h]h ]h"]h$]h&]uh1jhjhhhhhNubeh}(h]h ]h"]h$]h&]bullet-uh1jhhhKhjhhubh)}(h Other notes:h]h Other notes:}(hjPhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjhhubj)}(hhh](j)}(hTWriting causes the show() method to be rearmed regardless of current file position. h]h)}(hSWriting causes the show() method to be rearmed regardless of current file position.h]hSWriting causes the show() method to be rearmed regardless of current file position.}(hjehhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjaubah}(h]h ]h"]h$]h&]uh1jhj^hhhhhNubj)}(hKThe buffer will always be PAGE_SIZE bytes in length. On x86, this is 4096. h]h)}(hJThe buffer will always be PAGE_SIZE bytes in length. On x86, this is 4096.h]hJThe buffer will always be PAGE_SIZE bytes in length. On x86, this is 4096.}(hj}hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjyubah}(h]h ]h"]h$]h&]uh1jhj^hhhhhNubj)}(hJshow() methods should return the number of bytes printed into the buffer. h]h)}(hIshow() methods should return the number of bytes printed into the buffer.h]hIshow() methods should return the number of bytes printed into the buffer.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj^hhhhhNubj)}(hoshow() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space. h]h)}(hnshow() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.h]hnshow() should only use sysfs_emit() or sysfs_emit_at() when formatting the value to be returned to user space.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj^hhhhhNubj)}(hstore() should return the number of bytes used from the buffer. If the entire buffer has been used, just return the count argument. h]h)}(hstore() should return the number of bytes used from the buffer. If the entire buffer has been used, just return the count argument.h]hstore() should return the number of bytes used from the buffer. If the entire buffer has been used, just return the count argument.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj^hhhhhNubj)}(hfshow() or store() can always return errors. If a bad value comes through, be sure to return an error. h]h)}(heshow() or store() can always return errors. If a bad value comes through, be sure to return an error.h]heshow() or store() can always return errors. If a bad value comes through, be sure to return an error.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj^hhhhhNubj)}(hThe object passed to the methods will be pinned in memory via sysfs reference counting its embedded object. However, the physical entity (e.g. device) the object represents may not be present. Be sure to have a way to check this, if necessary. h]h)}(hThe object passed to the methods will be pinned in memory via sysfs reference counting its embedded object. However, the physical entity (e.g. device) the object represents may not be present. Be sure to have a way to check this, if necessary.h]hThe object passed to the methods will be pinned in memory via sysfs reference counting its embedded object. However, the physical entity (e.g. device) the object represents may not be present. Be sure to have a way to check this, if necessary.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhKhjubah}(h]h ]h"]h$]h&]uh1jhj^hhhhhNubeh}(h]h ]h"]h$]h&]jNjOuh1jhhhKhjhhubh)}(hCA very simple (and naive) implementation of a device attribute is::h]hBA very simple (and naive) implementation of a device attribute is:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hXstatic ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) { return sysfs_emit(buf, "%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);h]hXstatic ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) { return sysfs_emit(buf, "%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);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhMhjhhubh)}(hY(Note that the real implementation doesn't allow userspace to set the name for a device.)h]h[(Note that the real implementation doesn’t allow userspace to set the name for a device.)}(hj+hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubeh}(h]reading-writing-attribute-dataah ]h"]reading/writing attribute dataah$]h&]uh1hhhhhhhhKubh)}(hhh](h)}(hTop Level Directory Layouth]hTop Level Directory Layout}(hjDhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjAhhhhhMubh)}(hSThe sysfs directory arrangement exposes the relationship of kernel data structures.h]hSThe sysfs directory arrangement exposes the relationship of kernel data structures.}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjAhhubh)}(h*The top level sysfs directory looks like::h]h)The top level sysfs directory looks like:}(hj`hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM"hjAhhubj)}(hVblock/ bus/ class/ dev/ devices/ firmware/ fs/ hypervisor/ kernel/ module/ net/ power/h]hVblock/ bus/ class/ dev/ devices/ firmware/ fs/ hypervisor/ kernel/ module/ net/ power/}hjnsbah}(h]h ]h"]h$]h&]hhuh1jhhhM$hjAhhubh)}(hdevices/ contains a filesystem representation of the device tree. It maps directly to the internal kernel device tree, which is a hierarchy of struct device.h]hdevices/ contains a filesystem representation of the device tree. It maps directly to the internal kernel device tree, which is a hierarchy of struct device.}(hj|hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM1hjAhhubh)}(h~bus/ contains flat directory layout of the various bus types in the kernel. Each bus's directory contains two subdirectories::h]hbus/ contains flat directory layout of the various bus types in the kernel. Each bus’s directory contains two subdirectories:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM5hjAhhubj)}(hdevices/ drivers/h]hdevices/ drivers/}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhM8hjAhhubh)}(hudevices/ contains symlinks for each device discovered in the system that point to the device's directory under root/.h]hwdevices/ contains symlinks for each device discovered in the system that point to the device’s directory under root/.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM;hjAhhubh)}(hdrivers/ contains a directory for each device driver that is loaded for devices on that particular bus (this assumes that drivers do not span multiple bus types).h]hdrivers/ contains a directory for each device driver that is loaded for devices on that particular bus (this assumes that drivers do not span multiple bus types).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM>hjAhhubh)}(hfs/ contains a directory for some filesystems. Currently each filesystem wanting to export attributes must create its own hierarchy below fs/ (see ./fuse.rst for an example).h]hfs/ contains a directory for some filesystems. Currently each filesystem wanting to export attributes must create its own hierarchy below fs/ (see ./fuse.rst for an example).}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMBhjAhhubh)}(h}module/ contains parameter values and state information for all loaded system modules, for both builtin and loadable modules.h]h}module/ contains parameter values and state information for all loaded system modules, for both builtin and loadable modules.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMFhjAhhubh)}(hX,dev/ contains two directories: char/ and block/. Inside these two directories there are symlinks named :. These symlinks point to the sysfs directory for the given device. /sys/dev provides a quick way to lookup the sysfs interface for a device from the result of a stat(2) operation.h]hX,dev/ contains two directories: char/ and block/. Inside these two directories there are symlinks named :. These symlinks point to the sysfs directory for the given device. /sys/dev provides a quick way to lookup the sysfs interface for a device from the result of a stat(2) operation.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMIhjAhhubh)}(hjMore information on driver-model specific features can be found in Documentation/driver-api/driver-model/.h]hjMore information on driver-model specific features can be found in Documentation/driver-api/driver-model/.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMOhjAhhubh)}(hTODO: Finish this section.h]hTODO: Finish this section.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMShjAhhubeh}(h]top-level-directory-layoutah ]h"]top level directory layoutah$]h&]uh1hhhhhhhhMubh)}(hhh](h)}(hCurrent Interfacesh]hCurrent Interfaces}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMWubh)}(h8The following interface layers currently exist in sysfs.h]h8The following interface layers currently exist in sysfs.}(hj!hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMYhjhhubh)}(hhh](h)}(h devices (include/linux/device.h)h]h devices (include/linux/device.h)}(hj2hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj/hhhhhM]ubh)}(h Structure::h]h Structure:}(hj@hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM^hj/hhubj)}(hX1struct 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); };h]hX1struct 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); };}hjNsbah}(h]h ]h"]h$]h&]hhuh1jhhhM`hj/hhubh)}(h Declaring::h]h Declaring:}(hj\hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhhj/hhubj)}(h)DEVICE_ATTR(_name, _mode, _show, _store);h]h)DEVICE_ATTR(_name, _mode, _show, _store);}hjjsbah}(h]h ]h"]h$]h&]hhuh1jhhhMjhj/hhubh)}(hCreation/Removal::h]hCreation/Removal:}(hjxhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMlhj/hhubj)}(hint device_create_file(struct device *dev, const struct device_attribute * attr); void device_remove_file(struct device *dev, const struct device_attribute * attr);h]hint device_create_file(struct device *dev, const struct device_attribute * attr); void device_remove_file(struct device *dev, const struct device_attribute * attr);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhMnhj/hhubeh}(h]devices-include-linux-device-hah ]h"] devices (include/linux/device.h)ah$]h&]uh1hhjhhhhhM]ubh)}(hhh](h)}(h$bus drivers (include/linux/device.h)h]h$bus drivers (include/linux/device.h)}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhjhhhhhMsubh)}(h Structure::h]h Structure:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMthjhhubj)}(hstruct bus_attribute { struct attribute attr; ssize_t (*show)(const struct bus_type *, char * buf); ssize_t (*store)(const struct bus_type *, const char * buf, size_t count); };h]hstruct bus_attribute { struct attribute attr; ssize_t (*show)(const struct bus_type *, char * buf); ssize_t (*store)(const struct bus_type *, const char * buf, size_t count); };}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhMvhjhhubh)}(h Declaring::h]h Declaring:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhM|hjhhubj)}(hMstatic BUS_ATTR_RW(name); static BUS_ATTR_RO(name); static BUS_ATTR_WO(name);h]hMstatic BUS_ATTR_RW(name); static BUS_ATTR_RO(name); static BUS_ATTR_WO(name);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhM~hjhhubh)}(hCreation/Removal::h]hCreation/Removal:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhjhhubj)}(hint bus_create_file(struct bus_type *, struct bus_attribute *); void bus_remove_file(struct bus_type *, struct bus_attribute *);h]hint bus_create_file(struct bus_type *, struct bus_attribute *); void bus_remove_file(struct bus_type *, struct bus_attribute *);}hjsbah}(h]h ]h"]h$]h&]hhuh1jhhhMhjhhubeh}(h]"bus-drivers-include-linux-device-hah ]h"]$bus drivers (include/linux/device.h)ah$]h&]uh1hhjhhhhhMsubh)}(hhh](h)}(h'device drivers (include/linux/device.h)h]h'device drivers (include/linux/device.h)}(hj hhhNhNubah}(h]h ]h"]h$]h&]uh1hhj hhhhhMubh)}(h Structure::h]h Structure:}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj)}(hstruct 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); };h]hstruct 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); };}hj(sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj hhubh)}(h Declaring::h]h Declaring:}(hj6hhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj)}(h+DRIVER_ATTR_RO(_name) DRIVER_ATTR_RW(_name)h]h+DRIVER_ATTR_RO(_name) DRIVER_ATTR_RW(_name)}hjDsbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj hhubh)}(hCreation/Removal::h]hCreation/Removal:}(hjRhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj hhubj)}(hint driver_create_file(struct device_driver *, const struct driver_attribute *); void driver_remove_file(struct device_driver *, const struct driver_attribute *);h]hint driver_create_file(struct device_driver *, const struct driver_attribute *); void driver_remove_file(struct device_driver *, const struct driver_attribute *);}hj`sbah}(h]h ]h"]h$]h&]hhuh1jhhhMhj hhubeh}(h]%device-drivers-include-linux-device-hah ]h"]'device drivers (include/linux/device.h)ah$]h&]uh1hhjhhhhhMubeh}(h]current-interfacesah ]h"]current interfacesah$]h&]uh1hhhhhhhhMWubh)}(hhh](h)}(h Documentationh]h Documentation}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhj~hhhhhMubh)}(hX>The sysfs directory structure and the attributes in each directory define an ABI between the kernel and user space. As for any ABI, it is important that this ABI is stable and properly documented. All new sysfs attributes must be documented in Documentation/ABI. See also Documentation/ABI/README for more information.h]hX>The sysfs directory structure and the attributes in each directory define an ABI between the kernel and user space. As for any ABI, it is important that this ABI is stable and properly documented. All new sysfs attributes must be documented in Documentation/ABI. See also Documentation/ABI/README for more information.}(hjhhhNhNubah}(h]h ]h"]h$]h&]uh1hhhhMhj~hhubeh}(h] documentationah ]h"] documentationah$]h&]uh1hhhhhhhhMubeh}(h]1sysfs-the-filesystem-for-exporting-kernel-objectsah ]h"]5sysfs - _the_ filesystem for exporting kernel objectsah$]h&]uh1hhhhhhhhKubeh}(h]h ]h"]h$]h&]sourcehuh1hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh _destinationN _config_files]7/var/lib/git/docbuild/linux/Documentation/docutils.confafile_insertion_enabled raw_enabledKline_length_limitM'pep_referencesN pep_base_urlhttps://peps.python.org/pep_file_url_templatepep-%04drfc_referencesN rfc_base_url&https://datatracker.ietf.org/doc/html/ tab_widthKtrim_footnote_reference_spacesyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xform image_loadinglinkembed_stylesheetcloak_email_addressessection_self_linkenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jjjjjjjjj.j+jjj>j;j j j{jxjjjjjsjpjju nametypes}(jjjjj.jj>j j{jjjsjuh}(jhjjjjjjj+j jj1j;jj jAjxjjj/jjjpj jj~u footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN include_log] decorationNhhub.