Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


if it is configured to be active; generating it as a module is not possible. The canonical mount point for
sysfs is/sys.

The kernel sources contain some documentation on sysfs, its relation to the driver model with respect to
thekobjectframework, and so on. It can be found inDocumentation/filesystems/sysfs.txt
andDocumentation/filesystems/sysfs-pci.txt. An overview article by the author of
sysfs himself is available in the proceedings of the Ottawa Linux Symposium 2005 on
http://www.linuxsymposium.org/2005/linuxsymposium_procv1.pdf.

Finally, note that the connection betweenkobjects and sysfs is not automatically set up. Standalone
kobjectinstances are by default not integrated into sysfs. You need to callkobject_addto make an
object visible in the filesystem. If thekobjectis a member of a kernel subsystem, the registration is
performed automatically, though.

10.3.1 Overview


struct kobject, the related data structures, and their usage are described in Chapter 1; thus, here
our discussion is restricted to a recap of the most essential points. In particular, it is important to
remember that

❑ kobjectsare included in a hierarchic organization; most important, they can have aparentand
can be included in akset. This determines where thekobjectappears in the sysfs hierarchy: If
a parent exists, a new entry in the directory of the parent is created. Otherwise, it is placed in the
directory of thekobjectthat belongs to the kset the object is contained in (if both of these possi-
bilities fail, the entry for thekobjectis located directly in the top level of the system hierarchy,
but this is obviously a rare case).
❑ Everykobjectis represented as a directory within sysfs. The files that appear in this directory
are theattributesof the object. The operations used to export and set attribute values are pro-
vided by the subsystem (class, driver, etc.) to which thekobjectbelongs.
❑ Buses, devices, drivers, and classes are the main kernel objects using thekobjectmechanism;
they thus account for nearly all entries of sysfs.

10.3.2 Data Structures


As usual, let’s first discuss the data structures used by the sysfs implementation.

Directory Entries


Directory entries are represented bystruct sysfs_direntas defined in<sysfs.h>. It is the main data
structure of sysfs; the whole implementation is centered around it. Each sysfs node is represented by a
single instance ofsysfs_dirent. The definition is as follows:

<sysfs.h>
struct sysfs_dirent {
atomic_t s_count;
atomic_t s_active;
struct sysfs_dirent *s_parent;
struct sysfs_dirent *s_sibling;
const char *s_name;
Free download pdf