现在的位置: 首页 > 综合 > 正文

linux的虚拟文件系统

2013年08月01日 ⁄ 综合 ⁄ 共 1763字 ⁄ 字号 评论关闭
from: http://personal.denison.edu/~bressoud/cs372-f05/geekos_project/fsproject.html

Figure 10.1. Overview of the Virtual Filesystem (VFS)

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.

  1. 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.

  2. 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().

  3. 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.

  4. 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().

  5. 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.

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

抱歉!评论已关闭.