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?” ...
随机推荐
- Css3新特性应用之过渡与动画
目录 背景与边框第一部分 背景与边框第二部分 形状 视觉效果 字体排印 用户体验 结构与布局 过渡与动画 源码下载 一.缓动效果 学习和利用贝塞尔曲线,默认支持ease,ease-in,ease-ou ...
- 【C#】Switch datatype between object and byte[]
This sample shows how to turn object to byte[], as well as turn byte[] to object. So,I can turn any ...
- java初学者
决心开始从头学习java,并且每天记录自己的学习进度与学习成果,用于分享和促进. 鉴于是新手,并且之前也没有任何发文的经历,可能更多的是根据自己已有的知识容量基础之上进行的深化,太基础的看一遍就能会的 ...
- 使用KindEditor富文本编辑器,点击批量上传按钮没有选择图片按钮
问题:批量上传没有选择图片按钮
- Apache2.2下载及安装
php5.5 + apache2.4 安装配置图文步骤 http://wenku.baidu.com/link?url=8OHaJATVBHP5QrD-J2pTkmBOjY-ZG5cDngKMz7wl ...
- oracle建表的时候同时创建主键,外键,注释,约束,索引
--主键create table emp (id number constraint id_pr primary key ,name1 varchar(8));create table emp9 (i ...
- 啥数据类型set补充、深浅拷贝与函数
#s1 = {1,2,3,1} """ s2 = ([2,5,6]) print(s1) s1.add(5) #添加元素"5" print(s1) s ...
- openstack私有云布署实践【11.3 计算nova - compute节点-nova用户免密登录(用于云主机冷迁移+扩展云主机大小)】
云主机迁移+扩展云主机大小 ,官方说它依赖nova用户之间的免密登录.确保每个resion区域的compute节点服务器他们可以相互SSH免密 compute1-7 他们相互SSH免密 k ...
- Java的URL来下载网页源码
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; impor ...
- jQuery Validate【强大的表单验证】
一.引入菜鸟教程提供的 1.14.0 版本下载地址:http://static.runoob.com/download/jquery-validation-1.14.0.zip <script ...