创建sys目录下的属性节点有三种方式 device_create_file class_create_file driver_create_file 我们常用的是第一个和第二个,这三者的主要区别在第一个参数上,device依赖于device节点,class依赖于class节点(class_create) device_create_file 创建的属性节点在device设备节点对应的路径下,同理device也是 具体使用 class...
1. device_create_file device_create_file会基于device的设备节点路径来创建属性节点,属性可以使用DEVICE_ATTR来创建 函数原型,定义在include/linux/device.h中 创建设备节点intdevice_create_file(structdevice*device,conststructdevice_attribute*entry);删除设备节点voiddevice_remove_file(structdevice*dev,conststructde...
device_registerdevice_add// 其中包含2个关键函数// 将相关信息添加到/sys文件系统中(略)device_create_file// 将相关信息添加到/devtmpfs文件系统中devtmpfs_create_node device_create_file不做详细解析,因为devices本来就是/sys文件系统中的重要概念 关键是devtmpfs_create_node 什么是Devtmpfs 的概念 Devtmpfs lets...
device则是指向struct device_private所属的device。 下面还有一些宏,to_device_private_parent()是从父设备的klist_children上节点,获得相应的device_private。to_device_private_driver()是从驱动的设备链表上节点,获得对应的device_private。to_device_private_bus()是从总线的设备链表上节点,获得对应的device_private...
device_create_file建立属性文件uevent。 bus_add_device函数执行时,由于dev.bus 为&platform_bus_type,因此将建立三个symlink。 /sys/devices/platform/s3c2410-spi.0下建立链接subsystem和bus,他们指向/sys/bus/platform。 /sys/bus/platform/devices/下建立链接s3c2410-spi.0,指向/sys/devices/platform/s3c2410-spi...
当我们调用 device_create() 函数创建一个设备时,它会返回一个指向创建设备的指针,我们可以通过这个指针来获取设备的一些信息,比如设备号、设备类别等。另外,在设备创建成功后,我们需要记得调用 device_create_file() 函数来创建设备的相关文件,比如设备文件和属性文件等,这样用户空间的应用程序才能够访问这个设备。
注意电池设备在probe中已经用platform_device_register(&battery_device),这里的battery_device就是device_create_file的第一个dev。之后,在路径/sys/devices/platform/mt6573-battery中可以看到属性 需要注意的是,DEVICE_ATTR的第二个权限参数比较关键,改成0777或者S_IRWXUGO | S_IRWXUGO,否则上层系统或者apk不能正常...
准备好attr之后,可以通过sysfs_create_file来创建出sysfs文件: intsysfs_create_file(structkobject * kobj,conststructattribute * attr); 同样地,如果需要删除对应的sysfs文件,可以用: voidsysfs_remove_file(structkobject * kobj,conststructattribute * attr); ...
然后再通过device_create_file()或者sysfs_create_file()便来创建上面my_device_test设备文件. 3.使用示例 示例代码如下: 代码语言:javascript 复制 #include<board.h>#include<linux/module.h>#include<linux/init.h>#include<linux/platform_device.h>#include<linux/gpio.h>#include<linux/delay.h>#include<...
const struct file_operations *ops: 文件操作,是字符设备驱动中非常重要的数据结构,在应用程序通过文件系统(VFS)呼叫到设备设备驱动程序中实现的文件操作类函数过程中,ops起着桥梁纽带作用,VFS与文件系统及设备文件之间的接口是file_operations结构体成员函数,这个结构体包含了对文件进行打开、关闭、读写、控制等一系列...