Linux设备模型分析之kobject(基于3.10.1内核)
作者:刘昊昱
博客:http://blog.csdn.net/liuhaoyutz
内核版本:3.10.1
一、kobject结构定义
kobject是Linux设备模型的最底层数据结构,它代表一个内核对象。
kobject结构体定义在include/linux/kobject.h文件中:
179/**180 * flush_write_buffer - push buffer to kobject.181 * @dentry: dentry to the attribute182 * @buffer: data buffer for file.183 * @count: number of bytes184 *185 * Get the correct pointers for the kobject and the attribute we're186 * dealing with, then call the store() method for the attribute,187 * passing the buffer that we acquired in fill_write_buffer().188 */189190static int191flush_write_buffer(struct dentry * dentry, struct sysfs_buffer * buffer, size_t count)192{193 struct sysfs_dirent *attr_sd = dentry->d_fsdata;194 struct kobject *kobj = attr_sd->s_parent->s_dir.kobj;195 const struct sysfs_ops * ops = buffer->ops;196 int rc;197198 /* need attr_sd for attr and ops, its parent for kobj */199 if (!sysfs_get_active(attr_sd))200 return -ENODEV;201202 rc = ops->store(kobj, attr_sd->s_attr.attr, buffer->page, count);203204 sysfs_put_active(attr_sd);205206 return rc;207}