The major nuber is the driver associated with the device, while the minor number is used by the kernel to determine which device is being referrd to. You can use the minor number as an index into a local array of devices.

  Use dev_t type to hold device number with the help of MACROS defined in <linux/kdev_t.h>. You can obtain major or minor numbers with the following codes:

 MAJOR(dev_t dev);
 MINOR(dev_t dev);

  Instead, use the following codes to make a dev_t:

 MKDEV(int major, int minor);

  Before setting up a char device, your driver need to obtain a device number to work with using register_chrdev_region declared in <linux/fs.h>:

 int register_chrdev_region(dev_t first, unsigned int coung, char *name);

  "Here, first is the beginning device number of the range you would like to allocate.The minor number portion of first is often 0, but there is no requirement to that effect. count is the total number of contiguous device numbers you are requesting.Note that, if count is large, the range you request could spill over to the next major number; but everything will still work properly as long as the number range your equest is available. Finally, name is the name of the device that should be associatedwith this number range; it will appear in /proc/devices and sysfs."

  However, if you have no idea about which number you want, use alloc_chrdev_region to gain a device number:

 int alloc_chrdev_region(dev_t *dev, unsigned in firstminor, unsigned int count, char *name);

  If successfully completed, dev, as an output-only para, will hold the first number in the allocated range. firstminor should be the requested first minor number to use, always 0.

  When device numbers are no longer used, remember to free them with:

 void unregister_chrdev_region(dev_t first, unsigned int count);

Major and minor numbers的更多相关文章

  1. 主次设备号 Device Major and Minor Numbers

    对于一个设备文件而言真正重要的标志是它的主次设备号(major and minor device numbers).如果我们用ls命令列出/dev下的一个设备: frank@under:~$ ls - ...

  2. Python 主、次(major,minor)版本号获取

    Python  主.次(major,minor)版本号获取 import sys sys.version_info sys.version_info.major sys.version_info.mi ...

  3. 识别 Linux上的设备(磁盘)类型

    1. Linux 上的设备 (device) Linux 操作系统中,各种设备驱动(device driver)通过设备控制器(device controller)来管理各种设备(device),其关 ...

  4. Linux /proc、/dev Principle

    目录 . /proc简介 . 内核机制相关 . 进程信息 . 硬件设备相关 . 系统信息 . /dev简介 . 内存相关 1. /proc简介 在linux的根目录下有一个/proc目录,/proc文 ...

  5. What a version number means

    http://stackoverflow.com/questions/3768261/best-practices-guidance-for-maintaining-assembly-version- ...

  6. iOS LLDB调试器

    随着Xcode 5的发布,LLDB调试器已经取代了GDB,成为了Xcode工程中默认的调试器.它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能.LLDB为Xcode提供了底层调试环 ...

  7. RFC 2616

    Network Working Group R. Fielding Request for Comments: 2616 UC Irvine Obsoletes: 2068 J. Gettys Cat ...

  8. Queueing in the Linux Network Stack !!!!!!!!!!!!!!!

    https://www.coverfire.com/articles/queueing-in-the-linux-network-stack/ Queueing in the Linux Networ ...

  9. Introduction the naive“scull” 《linux设备驱动》 学习笔记

    Introduction the naive "scull" 首先.什么是scull? scull (Simple Character Utility for Loading Lo ...

随机推荐

  1. 关于js关闭浏览器技术细谈

    前言:前端时间做项目遇到一个js的问题,需要使用js关闭浏览器,在原有js代码是有这样功能的, 代码如下 window.close(); 但是呢,chrome,firefox等中有时候会不起作用. 后 ...

  2. [翻译]Webpack解惑

    本文译自Webpack - The Confusing Parts,原文需FQ. Webpack现在是React应用程序标配的模块打包器,我估计Angular2和其他框架的用户也在大规模使用.我第一次 ...

  3. 手机无须ROOT不用修改hosts即可在本地测试安卓、苹果APP和H5应用

    开发手机APP和 H5 应用经常需要在本地和线上环境分开测试,一般想到的操作都是修改hosts,我也一直这么干的,但手机上修改hosts是需要 ROOT权限的,这样太过麻烦,还有变砖头的风险,而且有些 ...

  4. Bucket Sort - leetcode [桶排序]

    桶排序(Bucket sort)或所谓的箱排序,是一个排序算法,工作的原理是将数组分到有限数量的桶里.每个桶再个别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序).桶排序是鸽巢排序 ...

  5. [MFC美化] Skin++使用详解-使用方法及注意事项

    主要分为以下几个方面: 1.Skin++使用方法 2.使用中注意事项 一. Skin++使用方法 SkinPPWTL.dll.SkinPPWTL.lib.SkinPPWTL.h ,将三个文件及相应皮肤 ...

  6. android 实现与服务器的长链接 方式

    http://blog.csdn.net/coffeeco/article/details/13276437  这边文章主要看服务端,使用tomcat7以上实现服务端的接收消息以及消息发送 http: ...

  7. Tiny6410之UART裸机驱动

    UART简介: UART(Universal Asynchronous Receiver and Transmitter)通用异步收发器(异步串行通信口),是一种通用的数据通信协议,它包括了RS232 ...

  8. laravel 添加第三方扩展库

    确定需要安装的位置 common.php测试代码 打开cmd 跳转到项目根目录下运行命令 composer install 打开文件 vender/composer/autoload_classmap ...

  9. dwr推送技术深入研究

    DWR 工作原理: 是通过动态把 Java 类生成为 Javascript.它的代码就像 Ajax 一样,你感觉调用就像发生在浏览器端,但是实际上代码调用发生在服务器端,DWR 负责数据的传递和转换. ...

  10. iScroll 下 a 标签失效

    遇到个莫名其妙的问题,iScroll 下的 a 标签点击没有反应了,不管怎么调整 z-index 都无效果,很是无语. 查找半天后找到解决方法: $(function(){ new IScroll(' ...