linux的虛擬檔案系統

來源:互聯網
上載者:User
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.

  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.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.