1/**2* struct class - device classes3* @name: Name of the class.4* @owner: The module owner.5* @class_attrs: Default attributes of this class.6* @dev_attrs: Default attributes of the devices belong to the class.
virtual int open(struct inode *inode, struct file *file) { … } virtual int release(struct inode *inode, struct file *file) { … } virtual ssize_t read(struct file *filep, char __user *buf, size_t count, loff_t *f_pos) { … } virtual ssize_t write(struct file *filep, cons...
内核中定义了struct class结构体,一个struct class结构体类型变量对应一个类,内核同时提供了class_create()函数,可以用它来创建一个类,这个类存放于sysfs下面,一旦创建了这个类,再调用device_create()函数在/dev目录下创建相应的设备节点。这样,加载模块的时候,用户空间中的udev会自动响应device_create()函数,去/sysf...
为class结构中的struct subsys_private类型的指针(cp)分配空间,并初始化其中的字段,包括cp->subsys.kobj.kset、cp->subsys.kobj.ktype等等 调用kset_register,注册该class(回忆“Linux设备模型(6)_Bus”中的描述,一个class就是一个子系统,因此注册class也是注册子系统)。该过程结束后,在/sys/class/目录下,就会创...
1 class结构体介绍 内核中定义了struct class结构体,顾名思义,一个struct class结构体类型变量对应一个类,内核同时提供了class_create(…)函数,可以用它来创建一个类,这个类存放于sysfs下面,一旦创建 好了这个类,再调用device_create(…)函数来在/dev目录下创建相应的设备节点。这样,加载模块的时候,用户空间中的...
; struct class_interface就是之前被串在class->p->class_interface上的类接口的结构。用于描述设备类对外的一种接口。node就是class->p->class_interfa 22、ce链表上的节点。class是指向所属class的指针。add_dev()是在有设备添加到所属class时调用的函数。当然,如果class_interface比设备更晚添加到class,也会...
#include<linux/module.h>#include<linux/kernel.h>#include<linux/ctype.h>#include<linux/device.h>#include<linux/cdev.h>// GPIO 硬件相关宏定义#defineMYGPIO_HW_ENABLE// 设备名称#defineMYGPIO_NAME"mygpio"// 一共有4个 GPIO 口#defineMYGPIO_NUMBER4// 设备类staticstructclass*gpio_class;// 用...
//定义一个名字为my_device_test的设备属性文件struct file_operations mytest_ops={.owner=THIS_MODULE,};staticint major;staticstructclass*cls;staticintmytest_init(void){struct device*mydev;major=register_chrdev(0,"mytest",&mytest_ops);cls=class_create(THIS_MODULE,"mytest_class");mydev=device...
struct class *class_create(struct module *owner, const char *name); class_create 一共有两个参数,参数 owner 一般为 THIS_MODULE,参数 name 是类名字。设备类名对应 /sys/class 目录的子目录名。返回值是个指向结构体 class 的指针,也就是创建的类。 卸载驱动程序的时候需要删除掉类,类删除函数为 class...
staticstructclass*hello_class; staticstructcdev*hello_cdev; staticinthello_open(structinode*inode,structfile*flp) { return0; } staticinthello_close(structinode*inode,structfile*flp) { return0; } staticstructfile_operationshello_fops={ .owner=THIS_MODULE, ...