我正在学习字符设备驱动程序编程。我有一些疑问,希望在这里澄清它们:-
(a) “设备文件与主设备号和次设备号相关联。同样在我们的驱动程序模块中,我们定义了一个 cdev 对象,其 fops 字段根据我们的功能定义,主设备号和次设备号相同。”
1. I want to know what exactly happens when a function is called on the device file.
Here is what I think. Suppose, I make a file called mydevfile using mknod(). Now
when I call open(mydevfile, O_RDWR), the kernel is searched for a cdev object with
same minor and major number. When found, the cdev 's fops is searched for function
for open() (say dev_open()). It is written that the dev_open() should have first
argument inode* and second argument file*. My question is how are these parameters
passed to the dev_open() function?
2. I learnt that inode is associated with a file on disk. Which file is it associated
with here? Also inode has a pointer to corresponding cdev. Now if we have already
got the cdev by searching major and minor number from mydevfile, why do we need
inode? W
3. What does the file*(i.e. the second argument) point to in this case?
你可以自由地以你喜欢的方式解释这一点,但如果你能用一个例子来解释它,我更愿意。谢谢!