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?” ...
随机推荐
- [jstips]向数组中插入一个元素
向现有数组中插入一个元素是经常会见到的一个需求.你可以: 使用push将元素插入到数组的尾部: 使用unshift将元素插入到数组的头部: 使用splice将元素插入到数组的中间: 上面那些方法都是常 ...
- 年末整理git和svn的使用心得
实习加毕业工作也一年多了,用过svn 也用过git,现在也是两种版本管理工具交替不同的项目再用. 趁年末放假之际,来梳理下. 对于SVN常用命令: .svn cp svn-trunk地址 svn-br ...
- 办理西蒙弗雷泽大学(本科)学历认证『微信171922772』SFU学位证成绩单使馆认证Simon Fraser University
办理西蒙弗雷泽大学(本科)学历认证『微信171922772』SFU学位证成绩单使馆认证Simon Fraser University Q.微信:171922772办理教育部国外学历学位认证海外大学毕业 ...
- Ubuntu 16.04 Django安装和配置
之前有安装和配置过,换了台电脑,再安装和配置,忽然发现差不多都忘记了,这里记录下已备之后查阅. sudo apt-get install python-pip sudo apt-get install ...
- mysql vachar
--本文在CSDN文章的基础加以补充 一. varchar存储规则: 4.0版本以下,varchar(20),指的是20字节,如果存放UTF8汉字时,只能存6个(每个汉字3字节) 5.0版本以上,va ...
- ubuntu下update-alternatives命令的使用
在ubuntu系统中,update-alternatives是专门维护系统命令链接符的工具,其可以对某个工具的多个软件版本进行管理,通过它可以很方便的设置系统默认使用哪个命令的哪个软件版本. 在命令行 ...
- Information:java: javacTask: 源发行版 1.8 需要目标发行版 1.8
1,Project Structure里确认两个地方:Project sdk以及project language level 2,Project Structure->Modules里Sourc ...
- 9款.net反编译的必备神器
编辑来给大家盘点下.net的反编译工具: 1.Reflector Reflector是最为流行的.Net反编译工具.Reflector是由微软员工Lutz Roeder编写的免费程序.Reflecto ...
- 拒绝深坑!记录找了多半天时间的C++编译失败的错误
采用新的源码,和原来的服务改动也不是很大,但是拒绝深坑啊,找了半天以为是源码的问题,结果倒好原来是环境的问题,还是要感谢一个神一样的人物的帮助 编译的时候一直出现undefined reference ...
- linux upstart启动配置
程序名.conf放在/etcc/init/目录下# 注释 description "your-server" author "xxx" start on run ...