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的更多相关文章

  1. 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 ...

  2. char device

    /** * alloc_chrdev_region() - register a range of char device numbers * @dev: output parameter for f ...

  3. Linux MTD (Memory Technology Device) subsystem analysis -For Atheros char device

    Linux MTD (Memory Technology Device) subsystem analysis For Atheros char device 读了Linux MTD 源代码分析 对这 ...

  4. <<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 ...

  5. linux内核头文件 cdev.h 解析

    遇到一个内核API--cdev_init 就找到这里来了. #ifndef _LINUX_CDEV_H #define _LINUX_CDEV_H #include <linux/kobject ...

  6. ldd3 编写scull尝试

    快速参考: #include <linux/types.h> dev_t dev_t is the type used to represent device numbers within ...

  7. Class create, device create, device create file (转)

    来自:http://www.hovercool.com/en/Class_create,_device_create,_device_create_file 开始写Linux设备驱动程序的时候,很多时 ...

  8. Class create, device create, device create file【转】

    来自:http://www.hovercool.com/en/Class_create,_device_create,_device_create_file 开始写Linux设备驱动程序的时候,很多时 ...

  9. 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?”  ...

随机推荐

  1. Nodejs --我自己的学习笔记

    对于Nodejs,相信客官并不陌生,网上却已众说纷纭,有人说是一个平台,有人说是服务器JavaScript,有人说一个框架… 之前亦有过研究,多怀可远观而不可亵玩也.高效率,I/O操作,异步编程,以及 ...

  2. .Net程序员学用Oracle系列(8):触发器、任务、序列、连接

    <.Net程序员学用Oracle系列:导航目录> 本文大纲 1.触发器 1.1.创建触发器 1.2.禁用触发器 & 启用触发器 & 删除触发器 2.任务 2.1.DBMS_ ...

  3. Node.js学习笔记(二):模块

    模块是 Node.js 应用程序的基本组成部分,文件和模块是一一对应的.一个 Node.js 文件就是一个模块,这个文件可能是 JavaScript 代码.JSON 或者编译过的 C/C++ 扩展. ...

  4. linux上安装mysql及简单的使用

    1. 安装mysql sudo apt-get update sudo apt-get install mysql-server sudo apt-get install python-mysqldb ...

  5. IMG图片垂直居中的问题

    之前老是碰到图片文字位置调整的问题,图片不按自己的要求变化,后来发现其实很简单. <P><img src="" style="vertical-alig ...

  6. AR/VR行业是否会像智能手机一样的飞速崛起

    从硬件和内容两方面来看,VR(虚拟现实)应该会比AR(增强现实)率先普及大众.当然,这是建立在解决无线化.眩晕.便携等问题之后的事儿,内容上不用担心,照现在这个发展速度-- 说到"风口&qu ...

  7. Http中的Get/Post方法

    这篇文章源自http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.html Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是G ...

  8. 我喜欢的快捷键 webstorm

    1.打开设置  ctrl+alt+s 2.重命名 rename  ctrl+r

  9. 【ARM】S5PV210芯片中的BL0的作用

    S5PV210芯片中的BL0的作用:(1)关闭看门狗:(2)清除指令寄存器:(3)初始化栈区域:(4)初始化堆区域:(5)初始化块设备复制功能:(6)初始化PLL和设置系统时钟:(7)拷贝BL1到片内 ...

  10. 【Android】策略模式封装百度地图路线规划模块

    百度地图的Demo里有个路线规划的功能,但是,这个功能和Activity耦合性太高,所以需要单独抽离出路径规划功能,进行"解耦". 注:由于项目原因,本文只针对驾车路线规划进行封装 ...