1、kset介绍
2、相关结构体和api介绍
2.1 struct kset
2.2 kset_create_and_add
kset_create_and_add
kset_create
kset_register
kobject_add_internal
kobject_add_internal
2.3 kset_unregister
kset_unregister
kobject_del
kobject_put
3、实验操作
#include<linux/module.h>
#include<linux/init.h>
#include<linux/kernel.h>
#include<linux/kobject.h>
#include<linux/slab.h>
struct kobject *my_kobject01;
struct kobject *my_kobject02;
struct kset *my_kset;
struct kobj_type mytype;
static int my_kobject_init(void)
{
int ret;
my_kset = kset_create_and_add("my_kset",NULL,NULL);
my_kobject01 = kzalloc(sizeof(struct kobject),GFP_KERNEL);
my_kobject01->kset = my_kset;
ret = kobject_init_and_add(my_kobject01,&mytype,NULL,"%s","my_kobject01");
my_kobject02 = kzalloc(sizeof(struct kobject),GFP_KERNEL);
my_kobject02->kset = my_kset;
ret = kobject_init_and_add(my_kobject02,&mytype,NULL,"%s","my_kobject02");
return 0;
}
static void my_kobject_exit(void)
{
kobject_put(my_kobject01);
kobject_put(my_kobject02);
kset_unregister(my_kset);
}
module_init(my_kobject_init);
module_exit(my_kobject_exit);
MODULE_LICENSE("GPL");
//Makefile
obj-m += kset.o
KDIR := /home/johan/share/rk3588/linux_sdk/kernel
PWD ?= $(shell pwd)
all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.mod.o *.mod.c