login 45b8371173
新增VFS文档,以及修改文档配置 (#209)
* 1.新增vfs设计文档
2.修改文档版权标志为"2022-2023, DragonOS Community"
3.修改电脑版文档页面的宽度为90%

* layout.html末尾加空行
2023-03-25 14:51:16 +08:00

59 lines
3.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:::{note}
本文作者: 龙进
Email: <longjin@DragonOS.org>
:::
# 设计
&emsp;&emsp;VFS的架构设计如下图所示
```text
┌─────────┐
│ │
│ read │
File │ │
│ write │
│ │ │
│ │ ioctl │
│ │ │
│ │ lseek │
│ │ │
│ │ etc.. │
│ └─────────┘
▼ ┌──────────────────────────────────────────────────────────────────────────────┐
MountFS │ Maintain the mount tree and handle the mounting of file systems. │
│ │ In particular, it handles the "crossing file system boundaries" condition │
│ │ while doing "lookup" or "find" operations. │
│ └──────────────────────────────────────────────────────────────────────────────┘
Filesystems: │
▼ ┌────────────────────────────────────────────────────────────────────┐
xxxFSInode │ Implement corresponding operations based on different file systems │
└────────────────────────────────────────────────────────────────────┘
```
## 1. File
&emsp;&emsp;File结构体是VFS中最基本的抽象它代表了一个打开的文件。每当进程打开了一个文件就会创建一个File结构体用于维护该文件的状态信息。
## 2. Traits
&emsp;&emsp;对于每个具体文件系统都需要实现以下的trait
- FileSystem表明某个struct是一个文件系统
- IndexNode 表明某个struct是一个索引节点
&emsp;&emsp;一般情况下FileSystem和IndexNode是一对一的关系也就是一个文件系统对应一种IndexNode。但是对于某些特殊的文件系统比如DevFS根据不同的设备类型会有不同的IndexNode因此FileSystem和IndexNode是一对多的关系。
## 3. MountFS
&emsp;&emsp;挂载文件系统虽然实现了FileSystem和IndexNode这两个trait但它并不是一个“文件系统”而是一种机制用于将不同的文件系统挂载到同一个文件系统树上.
所有的文件系统要挂载到文件系统树上都需要通过MountFS来完成。也就是说挂载树上的每个文件系统结构体的外面都套了一层MountFS结构体。
&emsp;&emsp;对于大部分的操作MountFS都是直接转发给具体的文件系统而不做任何处理。同时为了支持跨文件系统的操作比如在目录树上查找每次lookup操作或者是find操作都会通过MountFSInode的对应方法判断当前inode是否为挂载点并对挂载点进行特殊处理。如果发现操作跨越了具体文件系统的边界MountFS就会将操作转发给下一个文件系统并执行Inode替换。这个功能的实现也是通过在普通的Inode结构体外面套一层MountFSInode结构体来实现的。