国嵌——内核驱动模型——第二天kobject
2013-11-24 14:32
295 查看
sysfs文件系统:
sysfs被挂载在/sys/目录
block目录:
块设备,里面有属性文件,描述块设备各方面的属性
(loop块设备是使用文件来模拟的)
bus目录:内核中注册的每条总线,如:
ide pci scsi usb pcmcia
每个总线目录内又包含两个子目录:
devices和drivers
class目录:将设备按照功能进行分类,如:/sys/class/net网络
devices目录:包含系统所有的设备
kernel目录:内核中的配置参数
module目录:系统所有模块的信息
firmware目录:系统中的固件
fs目录:描述系统中的文件系统
power目录:系统中电源选项
kobject实现了基本的面向对象管理机制,是构成Linux2.6设备模型的
核心结构。它与sysfs文件系统紧密相连,在内核中注册的每个kobject
对象对应sysfs文件系统中的一个目录。
#include <linux/kobject.h>
struct kobject {
const char *name;//在/sys/目录下生成的文件名字
struct list_head entry;
struct kobject *parent;//指向父对象
struct kset *kset;
struct kobj_type *ktype;
struct sysfs_dirent *sd;
struct kref kref;//对象引用计数
unsigned int state_initialized:1;
unsigned int state_in_sysfs:1;
unsigned int state_add_uevent_sent:1;
unsigned int state_remove_uevent_sent:1;
unsigned int uevent_suppress:1;
};
kobject操作:
void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
int kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...);
int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, struct kobject *parent, const char *fmt, ...);
void kobject_del(struct kobject *kobj);
void kobject_put(struct kobject *kobj);//引用计数-1,为0时调用release释放对象
struct kobject *kobject_get(struct kobject *kobj);//引用计数+1
struct kobj_type {
void (*release)(struct kobject *kobj);//用于释放kobject占用的资源,当kobject引用计数为0时被调用
const struct sysfs_ops *sysfs_ops;
struct attribute **default_attrs;
const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
const void *(*namespace)(struct kobject *kobj);
};
struct attribute {
const char *name;//属性文件名
mode_t mode; //属性的保护位,见<linux/stat.h>
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lock_class_key *key;
struct lock_class_key skey;
#endif
};
struct sysfs_ops {
ssize_t (*show)(struct kobject *kobj, struct attribute *attr,char *buffer);
//当用户读属性文件时,该函数被调用,该函数将属性值存入buffer中返回给用户
ssize_t (*store)(struct kobject *kobj,struct attribute *attr,const char *buffer, size_t count);
//当用户写属性文件时,该函数被调用,用于存储用户传入的属性值
const void *(*namespace)(struct kobject *, const struct attribute *);
};
sysfs被挂载在/sys/目录
block目录:
块设备,里面有属性文件,描述块设备各方面的属性
(loop块设备是使用文件来模拟的)
bus目录:内核中注册的每条总线,如:
ide pci scsi usb pcmcia
每个总线目录内又包含两个子目录:
devices和drivers
class目录:将设备按照功能进行分类,如:/sys/class/net网络
devices目录:包含系统所有的设备
kernel目录:内核中的配置参数
module目录:系统所有模块的信息
firmware目录:系统中的固件
fs目录:描述系统中的文件系统
power目录:系统中电源选项
kobject实现了基本的面向对象管理机制,是构成Linux2.6设备模型的
核心结构。它与sysfs文件系统紧密相连,在内核中注册的每个kobject
对象对应sysfs文件系统中的一个目录。
#include <linux/kobject.h>
struct kobject {
const char *name;//在/sys/目录下生成的文件名字
struct list_head entry;
struct kobject *parent;//指向父对象
struct kset *kset;
struct kobj_type *ktype;
struct sysfs_dirent *sd;
struct kref kref;//对象引用计数
unsigned int state_initialized:1;
unsigned int state_in_sysfs:1;
unsigned int state_add_uevent_sent:1;
unsigned int state_remove_uevent_sent:1;
unsigned int uevent_suppress:1;
};
kobject操作:
void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
int kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...);
int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, struct kobject *parent, const char *fmt, ...);
void kobject_del(struct kobject *kobj);
void kobject_put(struct kobject *kobj);//引用计数-1,为0时调用release释放对象
struct kobject *kobject_get(struct kobject *kobj);//引用计数+1
struct kobj_type {
void (*release)(struct kobject *kobj);//用于释放kobject占用的资源,当kobject引用计数为0时被调用
const struct sysfs_ops *sysfs_ops;
struct attribute **default_attrs;
const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
const void *(*namespace)(struct kobject *kobj);
};
struct attribute {
const char *name;//属性文件名
mode_t mode; //属性的保护位,见<linux/stat.h>
#ifdef CONFIG_DEBUG_LOCK_ALLOC
struct lock_class_key *key;
struct lock_class_key skey;
#endif
};
struct sysfs_ops {
ssize_t (*show)(struct kobject *kobj, struct attribute *attr,char *buffer);
//当用户读属性文件时,该函数被调用,该函数将属性值存入buffer中返回给用户
ssize_t (*store)(struct kobject *kobj,struct attribute *attr,const char *buffer, size_t count);
//当用户写属性文件时,该函数被调用,用于存储用户传入的属性值
const void *(*namespace)(struct kobject *, const struct attribute *);
};
相关文章推荐
- 国嵌——内核驱动——第二天(总线-驱动-设备模型)
- linux内核部件分析(五)——设备驱动模型的基石kobject
- linux内核部件分析(五)——设备驱动模型的基石kobject
- 国嵌——内核驱动——第二天(kset)
- Linux内核部件分析<5> 设备驱动模型的基石kobject
- Linux内核部件分析 设备驱动模型的基石kobject
- linux内核驱动设备模型五之kobject (设备驱动模型的基石)
- linux底层驱动模型之三:kobject应用实例
- 详解Linux2.6内核中基于platform机制的驱动模型(续)
- 详解Linux2.6内核中基于platform机制的驱动模型
- linux驱动内核模型
- Linux 内核--总线设备驱动模型(字符/块/网络设备 && platform设备)
- ldm内核驱动模型
- LINUX设备驱动之设备模型一--kobject
- linux内核部件分析(七)——设备驱动模型之driver
- Linux内核部件分析--设备驱动模型之device
- 内核设备模型从kobject到子系统
- linux内核部件分析之——设备驱动模型之class
- 国嵌内核驱动进阶班-7-2(内核等待队列)
- Linux内核部件分析--设备驱动模型的基石kobject