Char device registration
The kernel uses structures of type struct cdev to represent char devices internally. Include <linux/cdev.h> so that you can use the following structures functions.
struct cdev *cdev_alloc(void); //allocate a cdev void cdev_init(struct cdev *cdev, struct file_operations *fops); //initialize it int cdev_add(sturct cdev *cdev, dev_t num, unsigned int count); //add it to kernel void cdev_del(struct cdev *dev); //remove it
Example of setuping a cdev(scull):
static void scull_setup_cdev(struct scull_dev *dev, int index) { int err, devno = MKDEV(scull_major, scull_minor + index); cdev_init(&dev->cdev, &scull_fops); dev->cdev.owner = THIS_MODULE; dev->cdev.ops = &scull_fops; err = cdev_add (&dev->cdev, devno, ); /* Fail gracefully if need be */ if (err) printk(KERN_NOTICE "Error %d adding scull%d", err, index); }
The older way to register and unregister a cdev is with:
int register_chrdev(unsigned int major, const char *name, struct file_operations *fops); int unregister_chrdev(unsigned int major, const char *name);
Char device registration的更多相关文章
- Is an MTD device a block device or a char device?
转:http://www.linux-mtd.infradead.org/faq/general.html#L_mtd_what Note, you can find Ukranian transla ...
- char device
/** * alloc_chrdev_region() - register a range of char device numbers * @dev: output parameter for f ...
- Linux MTD (Memory Technology Device) subsystem analysis -For Atheros char device
Linux MTD (Memory Technology Device) subsystem analysis For Atheros char device 读了Linux MTD 源代码分析 对这 ...
- <<linux device driver,third edition>> Chapter 3:Char Drivers
The Internal Representation of Device Numbers Within the kernel,the dev_t type(defined in linux/type ...
- linux内核头文件 cdev.h 解析
遇到一个内核API--cdev_init 就找到这里来了. #ifndef _LINUX_CDEV_H #define _LINUX_CDEV_H #include <linux/kobject ...
- ldd3 编写scull尝试
快速参考: #include <linux/types.h> dev_t dev_t is the type used to represent device numbers within ...
- Class create, device create, device create file (转)
来自:http://www.hovercool.com/en/Class_create,_device_create,_device_create_file 开始写Linux设备驱动程序的时候,很多时 ...
- Class create, device create, device create file【转】
来自:http://www.hovercool.com/en/Class_create,_device_create,_device_create_file 开始写Linux设备驱动程序的时候,很多时 ...
- Writing device drivers in Linux: A brief tutorial
“Do you pine for the nice days of Minix-1.1, when men were men and wrote their own device drivers?” ...
随机推荐
- ICSharpCode.TextEditor如何自定义代码折叠和高亮
ICSharpCode.TextEditor 是一款非常不错的.NET代码编辑控件,内置了多种高亮语言支持,同时完美支持中文,非常赞!先来看一下运行效果: 1 项目结构 这里需要注意lib文件夹下导入 ...
- C#中的文件操作1
1. 文件操作常用相关类 a)File //操作文件,静态类,对文件整体操作.拷贝.删除.剪切等. b)Directory //操作目录(文件夹),静态类 c)Di ...
- Url以.(点)结尾,在使用httpwebrequest读取的时候,微软会有一个bug……
解决方法在此,不重复做赘述,传送门:http://stackoverflow.com/questions/856885/httpwebrequest-to-url-with-dot-at-the-en ...
- 【原创】NSURLSession HTTPS Mutual Authentication
1.引入<NSURLSessionDelegate>协议 2.登录验证请求 -(void)authenticate { NSURL *url = [NSURL URLWithString: ...
- 【JS学习笔记】函数传参
比如仅仅改变背景的颜色 函数传参:参数就是占位符. 那么在什么时候用传参呢?函数里定不下来的东西. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1 ...
- python虚拟环境的使用
一. 安装 sudo apt-get install python-virtualenv 二. 创建环境 sudo virtualenv Myenv 创建完全隔离的Python环境,实质是创建了一个文 ...
- C++ unordered_map 在key为string类型和char*类型时测试时间性能差异
测试系统liunx centos6.5 代码如下 #include <string.h> #include <sstream> #include <list> #i ...
- 自定义连接池java.lang.ClassCastException: com.sun.proxy.$Proxy4 cannot be cast to java.sql.Connection
原因:Connection.getInterfaces() 与数据库驱动有关,数据库驱动不同 Connection.getInterfaces() 的结果也就不同,Connection.getInte ...
- java-读取属性文件
Property类: public static Properties loadLocalProperties(String fileName) { Properties property = new ...
- mysql数据库主从搭建
一.最近一直在学习mysql的东西,刚好看到mysql如何搭建主从数据库,搜集了很多资料后大致了解了mysql主从复置的原理.以下是我的理解: 举例master为主数据库,slave为从数据库. sl ...