Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


struct sysfs_ops * ops;
int needs_read_fill;
struct list_head list;
};

The contents of the structure are as follows:countspecifies the length of the data in the buffer,pos
denotes the present position within the data for partial reads and seeking, andpagepoints to a single
page used to store the data.^6 Thesysfs_opsinstance belonging to the sysfs entry is connected with an
open file via theopspointer of the buffer.needs_read_fillspecifies if the contents of the buffer need to
be filled or not (filling the data is performed on the first read and need not be repeated for any successive
reads if no write operation was performed in the meantime).

list

sysfs_elem_attr.open

sysfs_dirent

Socket Buffers


private_data

file file

list

private_data

sysfs_open_dirent

sysfs_buffer sysfs_buffer

Figure 10-12: Connection betweenstruct sysfs_dirent,struct file,andstruct
sysfs_buffer.

To understand the meaning oflist, observe Figure 10-12, which shows howsysfs_buffersarecon-
nected withstruct fileandstruct sysfs_dirent. Each open file as represented by an instance of
struct fileis connected with one instance ofsysfs_bufferviafile->private_data. A sysfs entry can
be referenced via multiple open files, so more than onesysf_buffercan be associated with one instance
ofstruct sysfs_dirent. All these buffers are collected in a list that usessysfs_buffer->listas list ele-
ment. The list is headed by an instance ofsysfs_open_dirent. For the sake of simplicity, this structure
is not discussed in great detail. Suffice it to say that it is connected withsysfs_direntand heads the list
ofsysfs_buffers.

Generic Implementation


Recall thatsysfs_file_operationsprovidessys_open_fileto be called when a file is opened. The
associated code flow diagram is shown in Figure 10-13.

(^6) The restriction to a single page is intentional because sysfs is supposed to export onlyone simpleattribute per file; this will not
require more space than a single page.

Free download pdf