static ssize_t disk_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
struct gendisk *disk = to_disk(kobj); struct disk_attribute *disk_attr =
container_of(attr,struct disk_attribute,attr); ssize_t ret = -EIO;
ret = disk_attr->show(disk,page); return ret;
The attribute connected to the sysfs file can be used to infer the containing disk_attribute instance by using the container_of-mechanism; after the kernel has made sure that the attribute possesses a show method, it is called to transfer data from the kernel to userspace and thus from the internal data structures to the sysfs file.
Similar methods are implemented by many other subsystems, but since their code is basically identical to the example shown above, it is unnecessary to consider them in greater detail here. Instead, I will cover the steps leading to a call of the sysfs-specific show and store methods; the connection between subsystem and sysfs is left to the subsystem-specific code.
Continue reading here: Mounting the Filesystem
Was this article helpful?