__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.173: ~ $
<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

    <title>sysfs - _The_ filesystem for exporting kernel objects &#8212; The Linux Kernel  documentation</title>
    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=fa44fd50" />
    <link rel="stylesheet" type="text/css" href="../_static/alabaster.css?v=3918102e" />
    <script src="../_static/documentation_options.js?v=5929fcd5"></script>
    <script src="../_static/doctools.js?v=9bcbadda"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Tmpfs" href="tmpfs.html" />
    <link rel="prev" title="Squashfs 4.0 Filesystem" href="squashfs.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  

  
  

  </head><body>
  <div class="document">
    
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../index.html">
              <img class="logo" src="../_static/logo.svg" alt="Logo of The Linux Kernel"/>
            </a></p>
<h1 class="logo"><a href="../index.html">The Linux Kernel</a></h1>



<p class="blurb">6.18.50</p>







<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>


<p>
<h3 class="kernel-toc-contents">Contents</h3>
<input type="checkbox" class="kernel-toc-toggle" id = "kernel-toc-toggle" checked>
<label class="kernel-toc-title" for="kernel-toc-toggle"></label>

<div class="kerneltoc" id="kerneltoc">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../process/development-process.html">Development process</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/submitting-patches.html">Submitting patches</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/code-of-conduct.html">Code of conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="../maintainer/index.html">Maintainer handbook</a></li>
<li class="toctree-l1"><a class="reference internal" href="../process/index.html">All development-process docs</a></li>
</ul>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../core-api/index.html">Core API</a></li>
<li class="toctree-l1"><a class="reference internal" href="../driver-api/index.html">Driver APIs</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../subsystem-apis.html">Subsystems</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#core-subsystems">Core subsystems</a></li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#human-interfaces">Human interfaces</a></li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#networking-interfaces">Networking interfaces</a></li>
<li class="toctree-l2 current"><a class="reference internal" href="../subsystem-apis.html#storage-interfaces">Storage interfaces</a><ul class="current">
<li class="toctree-l3 current"><a class="reference internal" href="index.html">Filesystems in the Linux kernel</a></li>
<li class="toctree-l3"><a class="reference internal" href="../block/index.html">Block</a></li>
<li class="toctree-l3"><a class="reference internal" href="../cdrom/index.html">CD-ROM</a></li>
<li class="toctree-l3"><a class="reference internal" href="../scsi/index.html">SCSI Subsystem</a></li>
<li class="toctree-l3"><a class="reference internal" href="../target/index.html">TCM Virtual Device</a></li>
<li class="toctree-l3"><a class="reference internal" href="../nvme/index.html">NVMe Subsystem</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../subsystem-apis.html#other-subsystems">Other subsystems</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../locking/index.html">Locking</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../process/license-rules.html">Licensing rules</a></li>
<li class="toctree-l1"><a class="reference internal" href="../doc-guide/index.html">Writing documentation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dev-tools/index.html">Development tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dev-tools/testing-overview.html">Testing guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../kernel-hacking/index.html">Hacking guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../trace/index.html">Tracing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../fault-injection/index.html">Fault injection</a></li>
<li class="toctree-l1"><a class="reference internal" href="../livepatch/index.html">Livepatching</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rust/index.html">Rust</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../admin-guide/index.html">Administration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../kbuild/index.html">Build system</a></li>
<li class="toctree-l1"><a class="reference internal" href="../admin-guide/reporting-issues.html">Reporting issues</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tools/index.html">Userspace tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../userspace-api/index.html">Userspace API</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../firmware-guide/index.html">Firmware</a></li>
<li class="toctree-l1"><a class="reference internal" href="../devicetree/index.html">Firmware and Devicetree</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../arch/index.html">CPU architectures</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../staging/index.html">Unsorted documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../translations/index.html">Translations</a></li>
</ul>

</div>

<script type="text/javascript"> <!--
  var sbar = document.getElementsByClassName("sphinxsidebar")[0];
  let currents = document.getElementsByClassName("current")
  if (currents.length) {
    sbar.scrollTop = currents[currents.length - 1].offsetTop;
  }
  --> </script>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/filesystems/sysfs.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
        </div>
      </div>
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  



<section id="sysfs-the-filesystem-for-exporting-kernel-objects">
<h1>sysfs - _The_ filesystem for exporting kernel objects<a class="headerlink" href="#sysfs-the-filesystem-for-exporting-kernel-objects" title="Link to this heading">¶</a></h1>
<p>Patrick Mochel  &lt;<a class="reference external" href="mailto:mochel&#37;&#52;&#48;osdl&#46;org">mochel<span>&#64;</span>osdl<span>&#46;</span>org</a>&gt;</p>
<p>Mike Murphy &lt;<a class="reference external" href="mailto:mamurph&#37;&#52;&#48;cs&#46;clemson&#46;edu">mamurph<span>&#64;</span>cs<span>&#46;</span>clemson<span>&#46;</span>edu</a>&gt;</p>
<dl class="field-list simple">
<dt class="field-odd">Revised<span class="colon">:</span></dt>
<dd class="field-odd"><p>16 August 2011</p>
</dd>
<dt class="field-even">Original<span class="colon">:</span></dt>
<dd class="field-even"><p>10 January 2003</p>
</dd>
</dl>
<section id="what-it-is">
<h2>What it is<a class="headerlink" href="#what-it-is" title="Link to this heading">¶</a></h2>
<p>sysfs 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.</p>
<p>sysfs is tied inherently to the kobject infrastructure. Please read
<a class="reference internal" href="../core-api/kobject.html"><span class="doc">Everything you never wanted to know about kobjects, ksets, and ktypes</span></a> for more information concerning the kobject
interface.</p>
</section>
<section id="using-sysfs">
<h2>Using sysfs<a class="headerlink" href="#using-sysfs" title="Link to this heading">¶</a></h2>
<p>sysfs is always compiled in if CONFIG_SYSFS is defined. You can access
it by doing:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>mount -t sysfs sysfs /sys
</pre></div>
</div>
</section>
<section id="directory-creation">
<h2>Directory Creation<a class="headerlink" href="#directory-creation" title="Link to this heading">¶</a></h2>
<p>For 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.</p>
<p>sysfs 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 <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">sysfs_schedule_callback()</span></code>.</p>
</section>
<section id="attributes">
<h2>Attributes<a class="headerlink" href="#attributes" title="Link to this heading">¶</a></h2>
<p>Attributes 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.</p>
<p>Attributes 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.</p>
<p>Mixing 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.</p>
<p>An attribute definition is simply:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>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);
</pre></div>
</div>
<p>A 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.</p>
<p>For example, the driver model defines <a class="reference internal" href="../driver-api/infrastructure.html#c.device_attribute" title="device_attribute"><code class="xref c c-struct docutils literal notranslate"><span class="pre">struct</span> <span class="pre">device_attribute</span></code></a> like:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>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 *);
</pre></div>
</div>
<p>It also defines this helper for defining device attributes:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#define DEVICE_ATTR(_name, _mode, _show, _store) \
struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
</pre></div>
</div>
<p>For example, declaring:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo);
</pre></div>
</div>
<p>is equivalent to doing:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>static struct device_attribute dev_attr_foo = {
        .attr = {
                .name = &quot;foo&quot;,
                .mode = S_IWUSR | S_IRUGO,
        },
        .show = show_foo,
        .store = store_foo,
};
</pre></div>
</div>
<p>Note as stated in include/linux/kernel.h “OTHER_WRITABLE?  Generally
considered a bad idea.” so trying to set a sysfs file writable for
everyone will fail reverting to RO mode for “Others”.</p>
<p>For the common cases sysfs.h provides convenience macros to make
defining attributes easier as well as making code more concise and
readable. The above case could be shortened to:</p>
<p>static <a class="reference internal" href="../driver-api/infrastructure.html#c.device_attribute" title="device_attribute"><code class="xref c c-struct docutils literal notranslate"><span class="pre">struct</span> <span class="pre">device_attribute</span></code></a> dev_attr_foo = __ATTR_RW(foo);</p>
<p>the list of helpers available to define your wrapper function is:</p>
<dl class="simple">
<dt>__ATTR_RO(name):</dt><dd><p>assumes default name_show and mode 0444</p>
</dd>
<dt>__ATTR_WO(name):</dt><dd><p>assumes a name_store only and is restricted to mode
0200 that is root write access only.</p>
</dd>
<dt>__ATTR_RO_MODE(name, mode):</dt><dd><p>for more restrictive RO access; currently
only use case is the EFI System Resource Table
(see drivers/firmware/efi/esrt.c)</p>
</dd>
<dt>__ATTR_RW(name):</dt><dd><p>assumes default name_show, name_store and setting
mode to 0644.</p>
</dd>
<dt>__ATTR_NULL:</dt><dd><p>which sets the name to NULL and is used as end of list
indicator (see: kernel/workqueue.c)</p>
</dd>
</dl>
</section>
<section id="subsystem-specific-callbacks">
<h2>Subsystem-Specific Callbacks<a class="headerlink" href="#subsystem-specific-callbacks" title="Link to this heading">¶</a></h2>
<p>When a subsystem defines a new attribute type, it must implement a
set of sysfs operations for forwarding read and write calls to the
show and store methods of the attribute owners:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>struct sysfs_ops {
        ssize_t (*show)(struct kobject *, struct attribute *, char *);
        ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t);
};
</pre></div>
</div>
<p>[ Subsystems should have already defined a <code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">kobj_type</span></code> as a
descriptor for this type, which is where the sysfs_ops pointer is
stored. See the kobject documentation for more information. ]</p>
<p>When a file is read or written, sysfs calls the appropriate method
for the type. The method then translates the generic <code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">kobject</span></code>
and <code class="xref c c-struct broken_xref docutils literal notranslate"><span class="pre">struct</span> <span class="pre">attribute</span></code> pointers to the appropriate pointer types, and
calls the associated methods.</p>
<p>To illustrate:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>#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-&gt;show)
                ret = dev_attr-&gt;show(dev, dev_attr, buf);
        if (ret &gt;= (ssize_t)PAGE_SIZE) {
                printk(&quot;dev_attr_show: %pS returned bad count\n&quot;,
                                dev_attr-&gt;show);
        }
        return ret;
}
</pre></div>
</div>
</section>
<section id="reading-writing-attribute-data">
<h2>Reading/Writing Attribute Data<a class="headerlink" href="#reading-writing-attribute-data" title="Link to this heading">¶</a></h2>
<p>To read or write attributes, <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">show()</span></code> or <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">store()</span></code> methods must be
specified when declaring the attribute. The method types should be as
simple as those defined for device attributes:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>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);
</pre></div>
</div>
<p>IOW, they should take only an object, an attribute, and a buffer as parameters.</p>
<p>sysfs 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:</p>
<ul>
<li><p>On read(2), the <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">show()</span></code> 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.</p>
<p>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 <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">show()</span></code> method will
be called again, rearmed, to fill the buffer.</p>
</li>
<li><p>On write(2), sysfs expects the entire buffer to be passed during the
first write. sysfs then passes the entire buffer to the <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">store()</span></code> method.
A terminating null is added after the data on stores. This makes
functions like <a class="reference internal" href="../core-api/kernel-api.html#c.sysfs_streq" title="sysfs_streq"><code class="xref c c-func docutils literal notranslate"><span class="pre">sysfs_streq()</span></code></a> safe to use.</p>
<p>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.</p>
<p>Attribute method implementations should operate on an identical
buffer when reading and writing values.</p>
</li>
</ul>
<p>Other notes:</p>
<ul class="simple">
<li><p>Writing causes the <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">show()</span></code> method to be rearmed regardless of current
file position.</p></li>
<li><p>The buffer will always be PAGE_SIZE bytes in length. On x86, this
is 4096.</p></li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">show()</span></code> methods should return the number of bytes printed into the
buffer.</p></li>
<li><p>New implementations of <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">show()</span></code> methods should only use <a class="reference internal" href="api-summary.html#c.sysfs_emit" title="sysfs_emit"><code class="xref c c-func docutils literal notranslate"><span class="pre">sysfs_emit()</span></code></a> or
<a class="reference internal" href="api-summary.html#c.sysfs_emit_at" title="sysfs_emit_at"><code class="xref c c-func docutils literal notranslate"><span class="pre">sysfs_emit_at()</span></code></a> when formatting the value to be returned to user space.</p></li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">store()</span></code> should return the number of bytes used from the buffer. If the
entire buffer has been used, just return the count argument.</p></li>
<li><p><code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">show()</span></code> or <code class="xref c c-func broken_xref docutils literal notranslate"><span class="pre">store()</span></code> can always return errors. If a bad value comes
through, be sure to return an error.</p></li>
<li><p>The 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.</p></li>
</ul>
<p>A very simple (and naive) implementation of a device attribute is:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>static ssize_t show_name(struct device *dev, struct device_attribute *attr,
                        char *buf)
{
        return sysfs_emit(buf, &quot;%s\n&quot;, dev-&gt;name);
}

static ssize_t store_name(struct device *dev, struct device_attribute *attr,
                        const char *buf, size_t count)
{
        snprintf(dev-&gt;name, sizeof(dev-&gt;name), &quot;%.*s&quot;,
                (int)min(count, sizeof(dev-&gt;name) - 1), buf);
        return count;
}

static DEVICE_ATTR(name, S_IRUGO, show_name, store_name);
</pre></div>
</div>
<p>(Note that the real implementation doesn’t allow userspace to set the
name for a device.)</p>
</section>
<section id="top-level-directory-layout">
<h2>Top Level Directory Layout<a class="headerlink" href="#top-level-directory-layout" title="Link to this heading">¶</a></h2>
<p>The sysfs directory arrangement exposes the relationship of kernel
data structures.</p>
<p>The top level sysfs directory looks like:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>block/
bus/
class/
dev/
devices/
firmware/
fs/
hypervisor/
kernel/
module/
power/
</pre></div>
</div>
<p>devices/ contains a filesystem representation of the device tree. It maps
directly to the internal kernel device tree, which is a hierarchy of
<a class="reference internal" href="../driver-api/infrastructure.html#c.device" title="device"><code class="xref c c-struct docutils literal notranslate"><span class="pre">struct</span> <span class="pre">device</span></code></a>.</p>
<p>bus/ contains flat directory layout of the various bus types in the
kernel. Each bus’s directory contains two subdirectories:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>devices/
drivers/
</pre></div>
</div>
<p>devices/ contains symlinks for each device discovered in the system
that point to the device’s directory under /sys/devices.</p>
<p>drivers/ 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).</p>
<p>fs/ contains a directory for some filesystems.  Currently each
filesystem wanting to export attributes must create its own hierarchy
below fs/ (see <a class="reference internal" href="fuse/fuse.html"><span class="doc">FUSE Overview</span></a> for an example).</p>
<p>module/ contains parameter values and state information for all
loaded system modules, for both builtin and loadable modules.</p>
<p>dev/ contains two directories: char/ and block/. Inside these two
directories there are symlinks named &lt;major&gt;:&lt;minor&gt;.  These symlinks
point to the directories under /sys/devices for each device.  /sys/dev provides a
quick way to lookup the sysfs interface for a device from the result of
a stat(2) operation.</p>
<p>More information on driver-model specific features can be found in
Documentation/driver-api/driver-model/.</p>
<p>block/ contains symlinks to all the block devices discovered on the system.
These symlinks point to directories under /sys/devices.</p>
<p>class/ contains a directory for each device class, grouped by functional type.
Each directory in class/ contains symlinks to devices in the /sys/devices directory.</p>
<p>firmware/ contains system firmware data and configuration such as firmware tables,
ACPI information, and device tree data.</p>
<p>hypervisor/ contains virtualization platform information and provides an interface to
the underlying hypervisor.  It is only present when running on a virtual machine.</p>
<p>kernel/ contains runtime kernel parameters, configuration settings, and status.</p>
<p>power/ contains power management subsystem information including
sleep states, suspend/resume capabilities, and policies.</p>
</section>
<section id="current-interfaces">
<h2>Current Interfaces<a class="headerlink" href="#current-interfaces" title="Link to this heading">¶</a></h2>
<p>The following interface layers currently exist in sysfs.</p>
<section id="devices-include-linux-device-h">
<h3>devices (include/linux/device.h)<a class="headerlink" href="#devices-include-linux-device-h" title="Link to this heading">¶</a></h3>
<p>Structure:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>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);
};
</pre></div>
</div>
<p>Declaring:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>DEVICE_ATTR(_name, _mode, _show, _store);
</pre></div>
</div>
<p>Creation/Removal:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>int device_create_file(struct device *dev, const struct device_attribute * attr);
void device_remove_file(struct device *dev, const struct device_attribute * attr);
</pre></div>
</div>
</section>
<section id="bus-drivers-include-linux-device-h">
<h3>bus drivers (include/linux/device.h)<a class="headerlink" href="#bus-drivers-include-linux-device-h" title="Link to this heading">¶</a></h3>
<p>Structure:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>struct 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);
};
</pre></div>
</div>
<p>Declaring:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>static BUS_ATTR_RW(name);
static BUS_ATTR_RO(name);
static BUS_ATTR_WO(name);
</pre></div>
</div>
<p>Creation/Removal:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>int bus_create_file(struct bus_type *, struct bus_attribute *);
void bus_remove_file(struct bus_type *, struct bus_attribute *);
</pre></div>
</div>
</section>
<section id="device-drivers-include-linux-device-h">
<h3>device drivers (include/linux/device.h)<a class="headerlink" href="#device-drivers-include-linux-device-h" title="Link to this heading">¶</a></h3>
<p>Structure:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>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);
};
</pre></div>
</div>
<p>Declaring:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>DRIVER_ATTR_RO(_name)
DRIVER_ATTR_RW(_name)
</pre></div>
</div>
<p>Creation/Removal:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>int driver_create_file(struct device_driver *, const struct driver_attribute *);
void driver_remove_file(struct device_driver *, const struct driver_attribute *);
</pre></div>
</div>
</section>
</section>
<section id="documentation">
<h2>Documentation<a class="headerlink" href="#documentation" title="Link to this heading">¶</a></h2>
<p>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.</p>
</section>
</section>


          </div>
          
        </div>
      </div>
    <div class="clearer"></div>
  </div>
    <div class="footer">
      &#169;The kernel development community.
      
      |
      Powered by <a href="https://www.sphinx-doc.org/">Sphinx 8.1.3</a>
      &amp; <a href="https://alabaster.readthedocs.io">Alabaster 0.7.16</a>
      
      |
      <a href="../_sources/filesystems/sysfs.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>

Filemanager

Name Type Size Permission Actions
caching Folder 0755
ext4 Folder 0755
fuse Folder 0755
iomap Folder 0755
nfs Folder 0755
smb Folder 0755
spufs Folder 0755
xfs Folder 0755
9p.html File 24.15 KB 0644
adfs.html File 13.15 KB 0644
affs.html File 18.5 KB 0644
afs.html File 19.14 KB 0644
api-summary.html File 831.83 KB 0644
autofs-mount-control.html File 32.3 KB 0644
autofs.html File 38.96 KB 0644
automount-support.html File 12.79 KB 0644
befs.html File 14.41 KB 0644
bfs.html File 10.72 KB 0644
btrfs.html File 9.7 KB 0644
buffer.html File 48.88 KB 0644
ceph.html File 18.87 KB 0644
coda.html File 65.97 KB 0644
configfs.html File 36.14 KB 0644
cramfs.html File 14.95 KB 0644
dax.html File 25.37 KB 0644
debugfs.html File 21.71 KB 0644
devpts.html File 10.61 KB 0644
directory-locking.html File 23.11 KB 0644
dlmfs.html File 14.28 KB 0644
dnotify.html File 12.09 KB 0644
ecryptfs.html File 11.96 KB 0644
efivarfs.html File 10 KB 0644
erofs.html File 29.42 KB 0644
ext2.html File 32.92 KB 0644
ext3.html File 8.29 KB 0644
f2fs.html File 67.87 KB 0644
fiemap.html File 23.32 KB 0644
files.html File 16.52 KB 0644
fscrypt.html File 107.9 KB 0644
fsverity.html File 64.53 KB 0644
gfs2-glocks.html File 21.71 KB 0644
gfs2-uevents.html File 12.88 KB 0644
gfs2.html File 10.38 KB 0644
hfs.html File 12.31 KB 0644
hfsplus.html File 10.28 KB 0644
hpfs.html File 26.83 KB 0644
idmappings.html File 74.42 KB 0644
index.html File 68.19 KB 0644
inotify.html File 12.35 KB 0644
isofs.html File 12.17 KB 0644
journalling.html File 115.17 KB 0644
locking.html File 52.92 KB 0644
locks.html File 11.91 KB 0644
mount_api.html File 49.94 KB 0644
multigrain-ts.html File 15 KB 0644
netfs_library.html File 86.81 KB 0644
nilfs2.html File 22.21 KB 0644
ntfs3.html File 13.64 KB 0644
ocfs2-online-filecheck.html File 13.13 KB 0644
ocfs2.html File 15.76 KB 0644
omfs.html File 13.12 KB 0644
orangefs.html File 35.89 KB 0644
overlayfs.html File 54.83 KB 0644
path-lookup.html File 123.09 KB 0644
porting.html File 94.09 KB 0644
proc.html File 140.32 KB 0644
qnx6.html File 16.36 KB 0644
quota.html File 12.12 KB 0644
ramfs-rootfs-initramfs.html File 27.94 KB 0644
relay.html File 40.38 KB 0644
resctrl.html File 93.99 KB 0644
romfs.html File 18.06 KB 0644
seq_file.html File 36.49 KB 0644
sharedsubtree.html File 46.25 KB 0644
splice.html File 79.36 KB 0644
squashfs.html File 24.34 KB 0644
sysfs.html File 29.32 KB 0644
tmpfs.html File 22.95 KB 0644
ubifs-authentication.html File 33.04 KB 0644
ubifs.html File 15.06 KB 0644
udf.html File 12.11 KB 0644
vfat.html File 26.07 KB 0644
vfs.html File 167.26 KB 0644
virtiofs.html File 12.16 KB 0644
zonefs.html File 35.71 KB 0644
Filemanager