Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


sysfs_put_active(respectively,sysfs_put_active_two) as soon as the operation with the
associated internal data is finished.

Extended Attributes


Let us turn our attention to the data structures that represent attributes and the mechanisms used to
declare new attributes:

Socket Data Structures


Attributes are defined by the following data structure:

include/linu/<sysfs.h>
struct attribute {
const char * name;
struct module * owner;
mode_t mode;
};

nameprovides a name for the attribute that is used as a filename in sysfs (thus attributes that belong to
the same object need to have unique names), whilemodespecifies the access mode.ownerpoints to the
moduleinstance to which the owner of the attribute belongs.

It is also possible to define a group of attributes with the aid of the following data structure:

<sysfs.h>
struct attribute_group {
const char * name;
struct attribute ** attrs;
};

nameis a name for the group, andattrspoints to an array ofattributeinstances terminated by aNULL
entry.

Note that these data structures only provide a means to represent attributes, but do not specify how
to read or modify them. This is covered in Section 10.3.4. The separation of representation and access
method was chosen because all attributes belonging to acertain entity (e.g., a driver, a device class, etc.)
are modified in a similar way, so it makes sense to transfer this group property to the export/import
mechanism. Note, though, that it is customary that theshowandstoreoperations of the subsystem rely
on attribute-specific show and store methods that are internally connected with the attribute and that
differ on a per-attribute basis. The implementation details are left to the respective subsystem; sysfs is
unconcerned about this.

For a read/write attribute, two methods denoted asshowandstoreneed to be available; the kernel
provides the following data structure to keep them together:

<sysfs.h>
struct sysfs_ops {
ssize_t (*show)(struct kobject *, struct attribute *,char *);
ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
};
Free download pdf