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. &lt;&lt;linux device driver,third edition&gt;&gt; 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. Ajax异步调用Controller的Return JsonResult生成下拉列表

    @using System.Web.Optimization; @{ Layout = null; } <!DOCTYPE html> <html> <head> ...

  2. Android—LayoutInflater学习笔记

    LayoutInflater的的主要用处:使用LayoutInflater来载入界面,类似于findViewById()在Activity中加载Widget组件一样.区别在于与LayoutInflat ...

  3. Web前端面试题目汇总

    以下是收集一些面试中经常会遇到的经典面试题以及自己面试过程中有一些未解决的问题,通过对知识的整理以及经验的总结,重新巩固自身的前端基础知识,如有错误或更好的答案,欢迎指正,水平有限,望各位不吝指教.: ...

  4. 【Netty学习】 ChannelHandler 改动及影响

    channelHandler 在Netty 4.x版本有了相当大的改动 http://netty.io/wiki/new-and-noteworthy.html   官网的更新改进说明. 以下节选官网 ...

  5. 理解squid的正向和反向代理

    1.相同点: 访问的走向都是:客户端 -> 代理服务器 ->真实服务器 ->代理服务器->客户端 2.不同点:正向代理语义上更侧重于,让代理服务器去帮忙请求某个网址.让代理服务 ...

  6. T450设置插入USB鼠标时自动禁用触摸板

    刚入手T450,打字时经常碰到触摸板,很是恼火,于是求助万能的度娘,找了卡饭基佬的教程,实测可行,大家可以试试.<win7下如何设置插入USB鼠标时自动禁用触摸板>,地址:www.kafa ...

  7. IC开短路测试(open_short_test),编程器测试接触不良、开短路

    http://kitebee.meibu.com/forum.php?mod=viewthread&tid=69654&extra=page%3D5 IC开短路测试(open_shor ...

  8. ROM签名脚本[原创]

    下面的代码是bash脚本来的.需要保存为*.sh后序. # !/bin/bash #usage: signapk.sh [-hs] [zipfile-unsigned | update.zip] #A ...

  9. 大牛的IT经验,方法【跟,帮】

    学习方法一:实践,应用,坚持. [swoole-韩天峰] 我最开始工作也是在2家小公司,后来加入腾讯阿里,主要原因还是我坚持学习基础知识,从而得到了这个机会.有几个方面的基础知识,我建议每一位PHP程 ...

  10. nginx 目录讲解