当前位置: 技术问答>linux和unix
Open函数的inode疑问
来源: 互联网 发布时间:2016-03-22
本文导语: 我们来看open函数的定义:int i2cdev_open (struct inode *inode, struct file *file) 但实际我们在使用open函数时并不会填入inode参数,只需填如file参数就行了。 为什么会这样呢??? | Linux内部有映射...
我们来看open函数的定义:int i2cdev_open (struct inode *inode, struct file *file)
但实际我们在使用open函数时并不会填入inode参数,只需填如file参数就行了。
为什么会这样呢???
但实际我们在使用open函数时并不会填入inode参数,只需填如file参数就行了。
为什么会这样呢???
|
Linux内部有映射表,根据file参数找到对应的设备,根据对应的设备驱动程序,然后就可以找到inode.你可以看Linux源码,比如open
|
实际情况是这样的:
open(char * path, ...) will call do_open(char * path, ..) which assumes almost the same format as open.
The the first thing do_open does is to call "open_namei(char * path, ..., &inode, ...)", this is in namei.c
Then by using the inode pointer returned from "open_namei()", "do_open" will call inode->i_op->open() to actually open the file. The pointer can point to ext2_open if your file is on an EXT2 File System.
open(char * path, ...) will call do_open(char * path, ..) which assumes almost the same format as open.
The the first thing do_open does is to call "open_namei(char * path, ..., &inode, ...)", this is in namei.c
Then by using the inode pointer returned from "open_namei()", "do_open" will call inode->i_op->open() to actually open the file. The pointer can point to ext2_open if your file is on an EXT2 File System.