linux的虚拟文件系统

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值