有人可以说明 linux 设备号的次设备号到底是做什么用的吗?
次要编号由内核使用 准确确定哪个设备是 被提及。
上面的解释只是两个摘要,有人可以说明吗?
The minor number is used by the kernel
to determine exactly which device is
being referred to.
The above explanation is just two abstract, can someone illustrate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
主设备号标识要使用的设备驱动程序,次设备号指示哪个设备。例如,如果您有多个分区,则每个分区都有自己的次要分区:
在这种情况下,次要分区 0 是原始驱动器,次要分区 1 是分区 1,次要分区 2 是分区 2,等等。但是,并非所有设备都使用 0 作为特殊情况。串行设备从 0 开始编号,其中
/dev/tty0
只是系统上的第一个(虚拟)终端设备:无论哪种情况,当打开设备文件时,内核都将使用主要的来确定哪个模块将处理该文件,并将次要函数传递给使用
register_chrdev()struct file_operations
结构的open()
方法代码>.The major number identifies the device driver to use, the minor number indicates which device. If you have multiple partitions, for instance, each gets its own minor:
Minor 0 in this case is the raw drive, minor 1 is partition 1, minor 2 is partition 2, etc. Not all devices use 0 as a special case, however. The serial devices start their numbering at 0, where
/dev/tty0
is just the first (virtual) terminal device on the system:In either event, when the device file is opened the kernel will use the major number to determine which module will handle the file and passes the minor to the
open()
method of thestruct file_operations
structure that was registered withregister_chrdev()
.就像在 C 语言中一样,从 0 开始计数...这可能是驱动程序编写者遵循的一种约定...毕竟 Linux 中的所有内容都基于 C 或某种程度上 C++。它只是一个编号方案...也可以从 0 到 255 之间的任何数字开始命名您的设备,但请小心不要超过次要编号的 255 标记,否则您可能会覆盖下一个可用的主要编号..希望这个答案有帮助
as in the language C ,counting starts from 0 ...it could be a sort of convention followed by driver writers ...after all everything in Linux is based upon C or to some extent C++.Its just a numbering scheme ..You can also start naming your devices from any number between 0 and 255,but please be carefull do not cross the 255 mark for minor numbers else you may overwrite the next available major number..hope this answer helps