Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


union {
struct sysfs_elem_dir s_dir;
struct sysfs_elem_symlink s_symlink;
struct sysfs_elem_attr s_attr;
struct sysfs_elem_bin_attr s_bin_attr;
};

unsigned int s_flags;
ino_t s_ino;
umode_t s_mode;
struct iattr *s_iattr;
};

❑ s_siblingands_childrenare used to capture the parent/child relationship between sysfs
entries in a data structure:s_siblingis used to connect all children of a parent among each
other, ands_childrenis used by the parent element to serve as a list head.


❑ The kernel usess_flagswith a twofold purpose: First, it is used to set the type of the sysfs entry.
Second, it can set a number of flags. The lower 8 bits are used for the type; they can be accessed
with the auxiliary functionsysfs_type. The type can be any ofSYSFS_DIR,SYSFS_KOBJ_ATTR,
SYSFS_KOBJ_BIN_ATTRorSYSFS_KOBJ_LINK, depending on whether the instance is a directory, a
regular respectively binary attribute, or a symbolic link.
The remaining bits are reserved for flags. Currently, onlySYSFS_FLAG_REMOVEDis defined, which
is set when a sysfs entry is in the process of being removed.


❑ Information about the access mode of the file associated with thesysfs_direntinstance is
stored ins_mode. Attributes are described by aniattrinstance pointed at bys_iattr;ifthisisa
NULLpointer, a default set of attributes is used.


❑ s_namepoints to the filename for the file, directory, or link represented by the object.


❑ Depending on the type of the sysfs entry, different types of data are associated with it. Since an
entry can only represent a single type at a time,the data structures that encapsulate the entry’s
payload are collected in an anonymous union. The members are defined as follows:
fs/sysfs/sysfs.h
struct sysfs_elem_dir {
struct kobject kobj;
/
children list starts here and goes through sd->s_sibling /
struct sysfs_dirent
children;
};


struct sysfs_elem_symlink {
struct sysfs_dirent *target_sd;
};

struct sysfs_elem_attr {
struct attribute *attr;
struct sysfs_open_dirent *open;
};

struct sysfs_elem_bin_attr {
struct bin_attribute *bin_attr;
};
Free download pdf