The inode Structure
The inode structure is used by the kernel internally to represent files. Therefore, it isdifferent 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.
rule, only two fields of this structure are of interest for writing driver code:
For inodes that represent device files, this field contains the actual device number.
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.
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版本中发生了改变,很多驱动因此不能运行,为了代码的移植性,内核开发者特意加了两个宏iminor,imajor,让我们直接从inode中就可以获得到主次设备号:
unsigned int imajor(struct inode *inode);
instead of manipulating i_rdev directly.
为了避免以后的变更带来的影响,我们最好使用上述的宏来获取主次号,而不是直接对inode结构中的i_rdev进行操作。ldd3.P55