linux的虚拟文件系统

王朝system·作者佚名  2006-05-19
窄屏简体版  字體: |||超大  

from: http://personal.denison.edu/~bressoud/cs372-f05/geekos_project/fsproject.html

Figure 10.1. Overview of the Virtual Filesystem (VFS)

The VFS layer works by dispatching requests for filesystem operations (such as opening, reading, or writing a file) to the appropriate filesystem implementation. The VFS works by defining several abstract datatypes representing mounted filesystem instances, open files, and open directories. Each of these datatypes contains a virtual function table which contains pointers to functions in the filesystem that the object belongs to. For example, File objects created by the GOSFS filesystem have a virtual function table whose Read() entry points to the function GOSFS_Read().

To give you an idea of how VFS works, here is what happens when a user process reads data from an open file in a GOSFS filesystem.

The process calls the Read() in the C library, which generates a software interrupts to notify the kernel that a system call is requested. It passes a file descriptor identifying the open file, the address of the buffer to store the data read from the file, and the number of bytes requested.

The kernel calls the Sys_Read() system call handler function. This function will look at the process's open file list (in User_Context) to find the File object representing the open file. It will also need to allocate a kernel buffer to temporarily hold the data read from the file. It will then call the kernel VFS function Read().

The VFS Read() will find the address of the Read function in the file's virtual function table. Because the file is part of a GOSFS filesystem, this will resolve to the GOSFS_Read() function.

GOSFS_Read() will do whatever work is necessary to read the requested data from the file, at the current file position, copying the data into the kernel buffer created by Sys_Read().

When control returns to Sys_Read(), it will copy the data read from the kernel buffer to the user buffer (using the Copy_To_User() function), and destroy the kernel buffer.

Finally, Sys_Read() will return, and the process will resume execution.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航