class,device,DEVICE_ATTR和sysfs
来源:互联网 发布:手机编写javascript 编辑:程序博客网 时间:2024/06/07 00:13
从linux内核2.6的某个版本之后,devfs不复存在,udev成为devfs的替代。udev是应用层的东东,不要试图在内核的配置选项里找到它;在驱动初始化的代码里调用class_create为该设备创建一个class,再为每个设备调用 class_device_create创建对应的设备。大致用法如下:1. struct class *myclass = class_create(THIS_MODULE, “my_device_driver”); //在/sys/class/ 下创建“my_device_driver”类目录 2. struce device *my_dev =device_create(myclass, NULL, MKDEV(major_num, 0), NULL, “my_device”); //这样的module被加载时,udev daemon就会自动在/dev/和/sys/class/my_device_driver/下创建my_device设备文件。 linux2.6的写法是:class_device_create(); 3. device_create_file(my_dev, &dev_attr_emmc_checksum_done); //在/sys/class/my_device_driver/my_device/下创建属性文件?/* * device_create_file -create sysfs attribute file for device. * @dev: device. * @attr: device attribute descriptor. */ 4. dev_attr_emmc_checksum_done 是用DEVICE_ATTR宏来定义的。static DEVICE_ATTR(emmc_checksum_pass, S_IRUGO | S_IWUSR | S_IWGRP,\ emmc_checksum_pass_show, emmc_checksum_pass_store);当通过adb shell来运行cat命令时会调用show函数,通过echo命令会调用store函数。 -------------------------------------------------linux-2.6.22/include/linux/device.hstruct class *class_create(struct module *owner, const char *name) class_create -create a struct class structure @owner: pointer to the module that is to "own" this struct class @name: pointer to a string for the name of this class.在/sys/class/下创建类目录class_device_create() -------------------------------------------------linux-2.6.22/include/linux/device.hstruct class_device *class_device_create(struct class *cls, struct class_device *parent, dev_t devt, struct device *device, const char *fmt, ...) class_device_create -creates a class device and registers it with sysfs @cls: pointer to the struct class that this device should be registered to. @parent: pointer to the parent struct class_device of this new device, if any. @devt: the dev_t for the char device to be added. @device: a pointer to a struct device that is assiociated with this class device. @fmt: string for the class device's name在linux 3.4中该函数换成了device_create()structdevice*device_create(struct class *class, struct device *parent, dev_t devt, void *drvdata, const char *fmt, ...)
0 0
- class,device,DEVICE_ATTR和sysfs
- DEVICE_ATTR 和 sysfs 的东西 -- sysfs_create_group
- DEVICE_ATTR 和 sysfs 的东西 -- sysfs_create_group
- DEVICE_ATTR 和 sysfs 的东西 -- sysfs_create_group
- DEVICE_ATTR 和 sysfs 的东西(转)
- DEVICE_ATTR 和 sysfs 的东西 -- sysfs_create_group
- DEVICE_ATTR 和 sysfs 的东西 -- sysfs_create_group
- kernel debug方法之DEVICE_ATTR 和 sysfs
- sysfs接口函数DEVICE_ATTR和sysfs_create_group
- DEVICE_ATTR 和 sysfs 的东西 -- sysfs_create_group
- sysfs接口函数DEVICE_ATTR和sysfs_create_group
- DEVICE_ATTR() 与 sysfs接口
- DEVICE_ATTR() 与 sysfs接口
- sysfs的uevent及DEVICE_ATTR
- sysfs接口函数的建立 DEVICE_ATTR
- linux文件系统的系统分析--(十三)sysfs和设备模型--Device
- DEVICE_ATTR和SENSOR_DEVICE_ATTR
- sysfs 文件系统 通过设备属性访问硬件(DEVICE_ATTR, LINUX)
- --面向对象第二部分-内部类、异常--java学习日记6(基础知识)
- 如何解决InstallWizardForVS2010.js无法安装
- alpha和hidden的区别
- 2014年7月16日
- MYSQL--事务处理
- class,device,DEVICE_ATTR和sysfs
- 随机访问文件 自身具备读写 的RandomAccessFile
- c++、java CRC16算法
- [Unity3D]场景间切换与数据传递(以及物体删除技巧)
- C++ Primer Plus第六版 第六章 编程练习答案
- String,StringBuffer与StringBuilder的区别??
- SSH連現時出現「WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!」解決辦法
- IOS学习笔记37——ViewController生命周期详解
- iOS 类别和扩展(Categories和Extensions)