相关疑难解决方法(0)

open如何适用于普通文件和设备驱动程序

目前,我正在学习Linux设备驱动程序.并坚持打开设备文件的工作原理?

到目前为止我所得到的...考虑一个打开普通文件的简单代码..

#incldue<stdio.h>
int main() {
   FILE fp;
   char buffer[20];
   fp = fopen(/home/yoggi/foo.txt, "r");
   fread(buffer, 5, 1, fp);
}
Run Code Online (Sandbox Code Playgroud)

在上面的程序中,fopen(),c-library函数是系统调用open()的包装函数,该实体在VFS层函数中调用sys_open()或file_open().由于linux支持多个文件系统,因此虚拟文件系统将控件转移到实际的文件系统处理程序,以打开该文件.

1) How does virtual file system(VFS) get to know on which file system the 
   underline file resides?
2) How does it then calls the file_open or open function of that particular
   filesystem to open file.
Run Code Online (Sandbox Code Playgroud)

如果设备驱动程序发生类似的事情.假设一个简单的设备驱动程序.

#include <linux/module.h>
// othher includes... 
static dev_t first; // Global variable for the first device number 
static struct …
Run Code Online (Sandbox Code Playgroud)

filesystems operating-system system-calls linux-device-driver linux-kernel

6
推荐指数
1
解决办法
8317
查看次数