新增VFS文档,以及修改文档配置 (#209)

* 1.新增vfs设计文档
2.修改文档版权标志为"2022-2023, DragonOS Community"
3.修改电脑版文档页面的宽度为90%

* layout.html末尾加空行
This commit is contained in:
login 2023-03-25 14:51:16 +08:00 committed by GitHub
parent 73c607aadd
commit 45b8371173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 176 additions and 18 deletions

8
docs/_templates/layout.html vendored Normal file
View File

@ -0,0 +1,8 @@
{% extends "!layout.html" %}
{% block footer %} {{ super() }}
<style>
.wy-nav-content { max-width: 90%; }
</style>
{% endblock %}

View File

@ -18,8 +18,8 @@
# -- Project information -----------------------------------------------------
project = 'DragonOS'
copyright = '2022, fslongjin'
author = 'fslongjin'
copyright = '2022-2023, DragonOS Community'
author = 'longjin'
# The full version, including alpha/beta/rc tags
release = 'dev'

View File

@ -146,7 +146,7 @@ sudo chown $USR /dev/kvm
&emsp;&emsp;假设您的计算机上已经安装了git您可以通过以下命令获得DragonOS的最新的源代码
```shell
git clone https://github.com/fslongjin/DragonOS
git clone https://github.com/DragonOS-Community/DragonOS
cd DragonOS
```

View File

@ -9,5 +9,6 @@ todo: 由于文件系统模块重构文档暂时不可用预计在2023年4
:maxdepth: 1
:caption: 目录
overview
vfs/index

View File

@ -0,0 +1,93 @@
:::{note}
本文作者: 龙进
Email: <longjin@DragonOS.org>
:::
# 概述
&emsp;&emsp;在本文中我们将介绍DragonOS文件系统的架构设计。
## 总览
&emsp;&emsp;如下图所示DragonOS的文件系统相关的机制主要包括以下几个部分
- 系统调用接口
- 虚拟文件系统
- 文件抽象File
- 挂载文件系统MountFS
- 具体的文件系统
```text
┌─────────────────────────────────────────────────┐
│ │
Syscall: │ sys_open, sys_read, sys_write, sys_close, │
│ │
│ sys_lseek, etc.. │
│ │
└───────────────────────┬─────────────────────────┘
VFS: ┌──────▼─────┐
│ │
│ File │
│ │
└──────┬─────┘
┌────────▼────────┐
│ │
│ MountFS │
│ │
└────┬────────────┘
Filesystems: ┌─────────────┼─────────────┬────────────┐
│ │ │ │
┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼────┐ ┌─────▼─────┐
│ │ │ │ │ │ │ │
│ FAT │ │ DevFS │ │ ProcFS │ │ RamFS │
│ │ │ │ │ │ │ │
└───────────┘ └───────────┘ └──────────┘ └───────────┘
```
## 系统调用接口
&emsp;&emsp;DragonOS的文件系统相关的系统调用接口主要包括以下几个
- `sys_open`:打开文件
- `sys_read`:读取文件
- `sys_write`:写入文件
- `sys_close`:关闭文件
- `sys_lseek`:定位文件指针
- `sys_mkdir`:创建目录
- `sys_unlink_at`:删除文件或目录(通过参数`flag`区分到底是删除文件还是目录)
- `sys_ioctl`:控制设备 (未实现)
- `sys_fstat`:获取文件状态(未实现)
- `sys_fsync`:同步文件(未实现)
- `sys_ftruncate`:截断文件(未实现)
- `sys_fchmod`:修改文件权限(未实现)
- 其他系统调用接口(未实现)
&emsp;&emsp;关于接口的具体含义,可以参考 [DragonOS系统调用接口](../../syscall_api/index.rst)。
## 虚拟文件系统VFS
&emsp;&emsp;VFS是DragonOS文件系统的核心它提供了一套统一的文件系统接口使得DragonOS可以支持多种不同的文件系统。VFS的主要功能包括
- 提供统一的文件系统接口
- 提供文件系统的挂载和卸载机制MountFS
- 提供文件抽象File
- 提供文件系统的抽象FileSystem
- 提供IndexNode抽象
- 提供文件系统的缓存、同步机制(尚未实现)
&emsp;&emsp;关于VFS的详细介绍请见[DragonOS虚拟文件系统](vfs/index.rst)。
## 具体的文件系统
&emsp;&emsp;DragonOS目前支持的文件系统包括
- FAT文件系统FAT12、FAT16、FAT32
- DevFS
- ProcFS
- RamFS

View File

@ -1,4 +1 @@
# VFS API文档

View File

@ -0,0 +1,58 @@
:::{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结构体来实现的。

View File

@ -4,10 +4,20 @@ VFS虚拟文件系统
在DragonOS中VFS作为适配器遮住了具体文件系统之间的差异对外提供统一的文件操作接口抽象。
VFS是DragonOS文件系统的核心它提供了一套统一的文件系统接口使得DragonOS可以支持多种不同的文件系统。VFS的主要功能包括
- 提供统一的文件系统接口
- 提供文件系统的挂载和卸载机制MountFS
- 提供文件抽象File
- 提供文件系统的抽象FileSystem
- 提供IndexNode抽象
- 提供文件系统的缓存、同步机制(尚未实现)
.. toctree::
:maxdepth: 1
:caption: 目录
overview
design
api

View File

@ -1,11 +0,0 @@
# DragonOS虚拟文件系统概述
## 简介
&emsp;&emsp;DragonOS的虚拟文件系统是内核中的一层适配器为用户程序或者是系统程序提供了通用的文件系统接口。同时对内核中的不同文件系统提供了统一的抽象。各种具体的文件系统可以挂载到VFS的框架之中。
&emsp;&emsp;与VFS相关的系统调用有open(), read(), write(), create()等。
## **TODO**
&emsp;&emsp;VFS的设计与实现讲解

View File

@ -1,3 +1,5 @@
.. _syscall_api:
系统调用API
====================================