建议直接从inode 获取设备号

The inode Structure

The inode structure is used by the kernel internally to represent files. Therefore, it is
different from the file structure that represents an open file descriptor. There can be
numerous file structures representing multiple open descriptors on a single file, but

they all point to a single inode structure.


The inode structure contains a great deal of information about the file. As a general

rule, only two fields of this structure are of interest for writing driver code:


dev_t i_rdev;

For inodes that represent device files, this field contains the actual device number.


struct cdev *i_cdev;
struct cdev is the kernel’s internal structure that represents char devices; this
field contains a pointer to that structure when the inode refers to a char device

file.


The type of i_rdev changed over the course of the 2.5 development series, breaking a

lot of drivers. As a way of encouraging more portable programming, the kernel developers have added two macros that can be used to obtain the major and minor number from an inode:

i_rdev的类型在2.5版本中发生了改变,很多驱动因此不能运行,为了代码的移植性,内核开发者特意加了两个宏iminorimajor,让我们直接从inode中就可以获得到主次设备号:


unsigned int iminor(struct inode *inode); /* #include <linux/fs.h> */

unsigned int imajor(struct inode *inode);


In the interest of not being caught by the next change, these macros should be used

instead of manipulating i_rdev directly.

为了避免以后的变更带来的影响,我们最好使用上述的宏来获取主次号,而不是直接对inode结构中的i_rdev进行操作。ldd3.P55


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值