Major and minor numbers
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的更多相关文章
- 主次设备号 Device Major and Minor Numbers
对于一个设备文件而言真正重要的标志是它的主次设备号(major and minor device numbers).如果我们用ls命令列出/dev下的一个设备: frank@under:~$ ls - ...
- Python 主、次(major,minor)版本号获取
Python 主.次(major,minor)版本号获取 import sys sys.version_info sys.version_info.major sys.version_info.mi ...
- 识别 Linux上的设备(磁盘)类型
1. Linux 上的设备 (device) Linux 操作系统中,各种设备驱动(device driver)通过设备控制器(device controller)来管理各种设备(device),其关 ...
- Linux /proc、/dev Principle
目录 . /proc简介 . 内核机制相关 . 进程信息 . 硬件设备相关 . 系统信息 . /dev简介 . 内存相关 1. /proc简介 在linux的根目录下有一个/proc目录,/proc文 ...
- What a version number means
http://stackoverflow.com/questions/3768261/best-practices-guidance-for-maintaining-assembly-version- ...
- iOS LLDB调试器
随着Xcode 5的发布,LLDB调试器已经取代了GDB,成为了Xcode工程中默认的调试器.它与LLVM编译器一起,带给我们更丰富的流程控制和数据检测的调试功能.LLDB为Xcode提供了底层调试环 ...
- RFC 2616
Network Working Group R. Fielding Request for Comments: 2616 UC Irvine Obsoletes: 2068 J. Gettys Cat ...
- Queueing in the Linux Network Stack !!!!!!!!!!!!!!!
https://www.coverfire.com/articles/queueing-in-the-linux-network-stack/ Queueing in the Linux Networ ...
- Introduction the naive“scull” 《linux设备驱动》 学习笔记
Introduction the naive "scull" 首先.什么是scull? scull (Simple Character Utility for Loading Lo ...
随机推荐
- ***网Web前端开发规范(初稿)
这几天一直在梳理关于前端方面的开发规范,现在暂时梳理了HTML的开发规范,暂且放置于此! 规范目的: 使开发流程更加规范化 文件命名规范:(需审批) 1.项目命名 全部采用小写方式, 以下划线分隔. ...
- quagga源码分析--路由信息处理zebra-rib
对于各个协议生成的路由信息的处理属于quagga中非常重要的一个功能,如何在内核进行路由增加,更新,删除是一个复杂的过程. quagga在thread任务调度中加入了一种工作队列,work_queue ...
- Fiddler捕获抓取 App端数据包
最近项目设计到App抓包,所以采用Fiddler工具来采集获取APP数据包,但是fiddler对有些app是无法捕获到数据包的,以下是我的处理方法: 1. 我默认代理端口使用的是自定义的端口而不是默认 ...
- ubuntu 服务版安装简易说明
安装基本环境 1.ubuntu 下载 下载地址:http://releases.ubuntu.com/14.04.4/ 2.安装virtualBox 直接在软件管家中下载即可 3.安装ubuntu 注 ...
- less学习:基础语法总结
一. less是什么 Less 是一门 CSS 预处理语言,它扩充了 CSS 语言,增加了诸如变量.混合(mixin).函数等功能,让 CSS 更易维护.方便制作主题.扩充. 注意1):less使用. ...
- SQL server Cannot find one or more
最近刚安装完sqlserver,新鲜感还没过,却出现了一大堆错误,令人头疼,其中有一个错误:在启动Microsoft SQL Server Management Studio时,出现如下错误提示,程序 ...
- 国内首家MR头显公司于CES惊艳亮相
在刚刚过去的CES2017大会上,我们看到了许多较为优秀的VR产品,而在这里面,有一家名不见经传的中国公司易瞳发布了一款兼具VR和AR功能的头显VMG-MARK.它的外观与联想VR和骁龙VR820等产 ...
- C# 三角形外心和外接圆半径计算方法
在网上找了好久,想找一个现成的方法来用,折腾半天发现没有一个好用的,最后迫不得已自己写了一个,需要的同学可以直接拿去用, private void GetTriangleExcenterRadius( ...
- AJAX应用的五个步骤
1.建立xmlHttpRequest对象 if(window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); if(xmlHttp.ov ...
- 使用python之环境管理
情景1:不同python版本的管理 同一电脑上的多个python版本之前的管理,为了突出问题的普遍存在,下面是有人在segmentfault上提的问题. 摘自:http://segmentfaul ...