docs: filesystems: convert sysfs.txt to ReST

- Add a SPDX header;
- Add a document title;
- Adjust document and section titles;
- use :field: markup;
- Some whitespace fixes and new line breaks;
- Mark literal blocks as such;
- Add it to filesystems/index.rst.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Link: https://lore.kernel.org/r/5c480dcb467315b5df6e25372a65e473b585c36d.1581955849.git.mchehab+huawei@kernel.org
Signed-off-by: Jonathan Corbet <corbet@lwn.net>
This commit is contained in:
Mauro Carvalho Chehab 2020-02-17 17:12:24 +01:00 committed by Jonathan Corbet
parent 31771f45c8
commit 86beb97670
2 changed files with 168 additions and 157 deletions

View File

@ -87,5 +87,6 @@ Documentation for filesystem implementations.
relay
romfs
squashfs
sysfs
virtiofs
vfat

View File

@ -1,11 +1,15 @@
.. SPDX-License-Identifier: GPL-2.0
sysfs - _The_ filesystem for exporting kernel objects.
=====================================================
sysfs - _The_ filesystem for exporting kernel objects
=====================================================
Patrick Mochel <mochel@osdl.org>
Mike Murphy <mamurph@cs.clemson.edu>
Revised: 16 August 2011
Original: 10 January 2003
:Revised: 16 August 2011
:Original: 10 January 2003
What it is:
@ -24,7 +28,7 @@ Using sysfs
~~~~~~~~~~~
sysfs is always compiled in if CONFIG_SYSFS is defined. You can access
it by doing:
it by doing::
mount -t sysfs sysfs /sys
@ -65,7 +69,7 @@ formatting of data is heavily frowned upon. Doing these things may get
you publicly humiliated and your code rewritten without notice.
An attribute definition is simply:
An attribute definition is simply::
struct attribute {
char * name;
@ -83,7 +87,7 @@ attribute. Subsystems are encouraged to define their own attribute
structure and wrapper functions for adding and removing attributes for
a specific object type.
For example, the driver model defines struct device_attribute like:
For example, the driver model defines struct device_attribute like::
struct device_attribute {
struct attribute attr;
@ -96,16 +100,16 @@ struct device_attribute {
int device_create_file(struct device *, const struct device_attribute *);
void device_remove_file(struct device *, const struct device_attribute *);
It also defines this helper for defining device attributes:
It also defines this helper for defining device attributes::
#define DEVICE_ATTR(_name, _mode, _show, _store) \
struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
For example, declaring
For example, declaring::
static DEVICE_ATTR(foo, S_IWUSR | S_IRUGO, show_foo, store_foo);
is equivalent to doing:
is equivalent to doing::
static struct device_attribute dev_attr_foo = {
.attr = {
@ -127,15 +131,21 @@ readable. The above case could be shortened to:
static struct device_attribute dev_attr_foo = __ATTR_RW(foo);
the list of helpers available to define your wrapper function is:
__ATTR_RO(name): assumes default name_show and mode 0444
__ATTR_WO(name): assumes a name_store only and is restricted to mode
__ATTR_RO(name):
assumes default name_show and mode 0444
__ATTR_WO(name):
assumes a name_store only and is restricted to mode
0200 that is root write access only.
__ATTR_RO_MODE(name, mode): fore more restrictive RO access currently
__ATTR_RO_MODE(name, mode):
fore more restrictive RO access currently
only use case is the EFI System Resource Table
(see drivers/firmware/efi/esrt.c)
__ATTR_RW(name): assumes default name_show, name_store and setting
__ATTR_RW(name):
assumes default name_show, name_store and setting
mode to 0644.
__ATTR_NULL: which sets the name to NULL and is used as end of list
__ATTR_NULL:
which sets the name to NULL and is used as end of list
indicator (see: kernel/workqueue.c)
Subsystem-Specific Callbacks
@ -143,7 +153,7 @@ Subsystem-Specific Callbacks
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.
show and store methods of the attribute owners::
struct sysfs_ops {
ssize_t (*show)(struct kobject *, struct attribute *, char *);
@ -160,7 +170,7 @@ and struct attribute pointers to the appropriate pointer types, and
calls the associated methods.
To illustrate:
To illustrate::
#define to_dev(obj) container_of(obj, struct device, kobj)
#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr)
@ -188,7 +198,7 @@ Reading/Writing Attribute Data
To 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:
simple as those defined for device attributes::
ssize_t (*show)(struct device *dev, struct device_attribute *attr, char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr,
@ -251,7 +261,7 @@ Other notes:
sure to have a way to check this, if necessary.
A very simple (and naive) implementation of a device attribute is:
A very simple (and naive) implementation of a device attribute is::
static ssize_t show_name(struct device *dev, struct device_attribute *attr,
char *buf)
@ -280,7 +290,7 @@ Top Level Directory Layout
The sysfs directory arrangement exposes the relationship of kernel
data structures.
The top level sysfs directory looks like:
The top level sysfs directory looks like::
block/
bus/
@ -296,7 +306,7 @@ directly to the internal kernel device tree, which is a hierarchy of
struct device.
bus/ contains flat directory layout of the various bus types in the
kernel. Each bus's directory contains two subdirectories:
kernel. Each bus's directory contains two subdirectories::
devices/
drivers/
@ -331,9 +341,9 @@ Current Interfaces
The following interface layers currently exist in sysfs:
- devices (include/linux/device.h)
----------------------------------
Structure:
devices (include/linux/device.h)
--------------------------------
Structure::
struct device_attribute {
struct attribute attr;
@ -343,19 +353,19 @@ struct device_attribute {
const char *buf, size_t count);
};
Declaring:
Declaring::
DEVICE_ATTR(_name, _mode, _show, _store);
Creation/Removal:
Creation/Removal::
int device_create_file(struct device *dev, const struct device_attribute * attr);
void device_remove_file(struct device *dev, const struct device_attribute * attr);
- bus drivers (include/linux/device.h)
--------------------------------------
Structure:
bus drivers (include/linux/device.h)
------------------------------------
Structure::
struct bus_attribute {
struct attribute attr;
@ -363,22 +373,22 @@ struct bus_attribute {
ssize_t (*store)(struct bus_type *, const char * buf, size_t count);
};
Declaring:
Declaring::
static BUS_ATTR_RW(name);
static BUS_ATTR_RO(name);
static BUS_ATTR_WO(name);
Creation/Removal:
Creation/Removal::
int bus_create_file(struct bus_type *, struct bus_attribute *);
void bus_remove_file(struct bus_type *, struct bus_attribute *);
- device drivers (include/linux/device.h)
-----------------------------------------
device drivers (include/linux/device.h)
---------------------------------------
Structure:
Structure::
struct driver_attribute {
struct attribute attr;
@ -387,12 +397,12 @@ struct driver_attribute {
size_t count);
};
Declaring:
Declaring::
DRIVER_ATTR_RO(_name)
DRIVER_ATTR_RW(_name)
Creation/Removal:
Creation/Removal::
int driver_create_file(struct device_driver *, const struct driver_attribute *);
void driver_remove_file(struct device_driver *, const struct driver_attribute *);