文件路径:
include/linux/kobject.h
lib/kobject_uevent.c
lib/kobject.c
在我的理解中uevent事件和kobject绑定在一起的
几种kobject能够产生的事件属性
enumkobject_action {
KOBJ_ADD,//添加
KOBJ_REMOVE,//移除
KOBJ_CHANGE,//发生了变化
KOBJ_MOVE,//移动
KOBJ_ONLINE,//存在
KOBJ_OFFLINE,//不在
KOBJ_MAX//最大
};
structkobject {
constchar *name; //本目录的名字
structlist_head entry; //链表
structkobject *parent; //父目录吧。。父亲,可以使用kobj,kset或者sys root
structkset *kset;//顶层
structkobj_type *ktype; //相应的操作
structsysfs_dirent *sd;//sysfs 下的目录名,根据parent设置或者会设置位sysroot下
structkref kref;//引用计数当用kobject_put设置为0时,则调用kobject_cleanup完全释放内存
unsignedint state_initialized:1; //释放被初始化,我的理解是当申请了kobject后记得设为0阿
unsignedint state_in_sysfs:1;//是否在sys下
unsignedint state_add_uevent_sent:1;//是否为增加的action
unsignedint state_remove_uevent_sent:1;//是否为remove的acton
unsignedint uevent_suppress:1;//不发送uevent事件
};
structkobj_type {
void(*release)(struct kobject *kobj);
conststruct sysfs_ops *sysfs_ops;
structattribute **default_attrs;
conststruct kobj_ns_type_operations *(*child_ns_type)(struct kobject*kobj);
constvoid *(*namespace)(struct kobject *kobj);
};
以上是kobject的结构体,那么接下来我来分析下kobject,然后穿插着说一下这个结构体,
那么一开始当然是从kobject_init开始
kobject_init
*This function will properly initialize a kobject such that it canthen
*be passed to the kobject_add() call.
*
*After this function is called, the kobject MUST be cleaned up by acall
*to kobject_put(), not by a call to kfree directly to ensure that allof
*the memory is cleaned up properly.
根据kobject_init的解释,最后释放的时候要掉用kobject_put能够释放所有的内存,然而接下来要掉用的是kobject_add
kobject_add
/**
*kobject_add - the main kobject add function
*@kobj: the kobject to add
*@parent: pointer to the parent of the kobject.
*@fmt: format to name the kobject with.
*
*The kobject name is set and added to the kobject hierarchy in this
*function.
*
*If @parent is set,