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:

  1. MAJOR(dev_t dev);
  2. MINOR(dev_t dev);

  Instead, use the following codes to make a dev_t:

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

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

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

  1. 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. grunt--自动化任务快速上手

    这篇文章将带领你用Grunt来提速和优化网站开发的流程.首先我们会简短介绍Grunt的功能,然后我们直接上手,介绍如何用Grunt的不同插件来替你完成网站项目开发中的很多繁冗工作. 接着我们会创建一个 ...

  2. Javaweb开发中URL路径的使用

    看到博客园孤傲苍狼的web系列文章中有关于URL路径的使用文章后,感觉自己对URL的使用清楚了很多,自己再对着动手写一遍以加深记忆. JavaWeb开发中常看到URL以"/"开头, ...

  3. MySql开启远程访问(Linux)

    Linux服务器上安装了MySql数据库服务器之后,在远程访问出现了61错误.经检查后,发现需要在MySql配置文件中取消绑定IP.具体做法如下: 打开my.cnf配置文件.连接到服务器之后,在终端中 ...

  4. 如何使用jconsole(英文)

    http://docs.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html

  5. 有关C语言学习的调查

    有关C语言学习的调查 1.Q:你是怎么学习C语言的?(作业,实验,教材,其他),与你的高超技能相比,C语言的学习有什么经验和教训? A:之间在暑假的之后自己有买了一本C PRIME PLUS 来看基本 ...

  6. 面试题-JDBC

    1.什么是JDBC? JDBC是允许用户在不同数据库之间做选择的一个抽象层.JDBC允许开发者用JAVA写数据库应用程序,而不需要关心底层特定数据库的细节. 2.解释下驱动(Driver)在JDBC中 ...

  7. Win10下Mysql5.7.13,解压版安装流程

    一.环境变量配置 1.将下载好的压宿包解压到安装目录,我的安装目录就是:D:\DevelopmentTool\Mysql5.7.13\mysql-5.7.13-winx64 2.鼠标选择计算机右键,点 ...

  8. AndroidStudio0.5.2 BUG 导致 menu 菜单键崩溃

    郁闷了半天,今天发现一点击手机 menu 键应用就崩溃了,记得之前都是好好的,调试了半天代码还是搞不定,于是网上google了一番,发现仅国外有一两篇文章有提到类似问题,据说是 0.5.2 版本的 B ...

  9. Python_Selenium2Library源码分析

    I. Introduction Selenium2Library是robot framework中主流的测试网页功能的库, 它的本质是对webdriver的二次封装, 以适应robot框架. 百度上一 ...

  10. 《Intel汇编第5版》 汇编逆转字符串

    一.逆转字符串 逆转一个字符串可以利用栈这个数据结果,顺次读取所有元素压栈,再出栈所有元素即可逆序 二.push和pop指令 三.pushfd和popfd 四.pushad和popad 五.代码以及结 ...