Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


ssize_t (*show)(struct gendisk *, char *);
ssize_t (*store)(struct gendisk *, const char *, size_t);
};

Some attributes are attached to all objects represented by the genhd subsystem, so the kernel creates a
collection of instances ofdisk_attributeas follows:


block/genhd.c
static struct disk_attribute disk_attr_uevent = {
.attr = {.name = "uevent", .mode = S_IWUSR },
.store = disk_uevent_store
};
static struct disk_attribute disk_attr_dev = {
.attr = {.name = "dev", .mode = S_IRUGO },
.show = disk_dev_read
};
...
static struct disk_attribute disk_attr_stat = {
.attr = {.name = "stat", .mode = S_IRUGO },
.show = disk_stats_read
};

static struct attribute * default_attrs[] = {
&disk_attr_uevent.attr,
&disk_attr_dev.attr,
&disk_attr_range.attr,
...
&disk_attr_stat.attr,
...
NULL,
};

The connection between the attribute-specificshow/storemethods and theshow/storemethods in
sysfs_opsis made by the following structure:


block/genhd.c
static struct sysfs_ops disk_sysfs_ops = {
.show = &disk_attr_show,
.store = &disk_attr_store,
};

Without getting into any details about their implementation, note that both methods are provided with
anattributeinstance when called by sysfs, transform this instance into adisk_attribute,andcallthe
show/storemethod associated with the specific attributes that does the low-level, subsystem-specific
work.


Finally, the only thing that needs to be considered is how the set of default attributes is connected with
allkobjectsbelonging to the genhd subsystem. For this, akobj_typeis used:


block/genhd.c
static struct kobj_type ktype_block = {
.release = disk_release,
.sysfs_ops = &disk_sysfs_ops,
.default_attrs = default_attrs,
};
Free download pdf