字符设备次设备号

5 篇文章 0 订阅

根据LDD3第三章

Traditionally, the major number identifies the driver associated with the device. For example, /dev/null and /dev/zero are both managed by driver 1, whereas virtual consoles and serial terminals are managed by driver 4; similarly, both vcs1 and vcsa1 devices are managed by driver 7. Modern Linux kernels allow multiple drivers to share major numbers, but most devices that you will see are still organized on the one-major-one-driver principle.

主设备号与设备驱动关联。

The minor number is used by the kernel to determine exactly which device is being referred to. Depending on how your driver is written (as we will see below), you can either get a direct pointer to your device from the kernel, or you can use the minor number yourself as an index into a local array of devices. Either way, the kernel itself knows almost nothing about minor numbers beyond the fact that they refer to devices implemented by your driver.

次设备号表示引用哪个设备(因为一个驱动可以对应多个设备)。


以linux-2.6.19代码为例看MTD字符设备驱动代码drivers/mtd/mtdchar.c, 在mtd_open()中,

    /* You can't open the RO devices RW */
    if ((file->f_mode & 2) && (minor & 1))
        return -EACCES;

这里的(minor & 1)说明次设备的最低位的特性。当最低为1时,设备是只读的。例如:主设备号相同时,次设备号分别为0,1的设备是表示同一个设备,不过0是可写的,而1是只读的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值