ableos-vfs/README.md

93 lines
2.4 KiB
Markdown
Raw Normal View History

2023-07-12 19:48:49 +00:00
# AbleOS VFS
2023-07-12 05:35:06 +00:00
2023-07-12 19:48:49 +00:00
## Public API
```
// reads the whole file
pub fn read(file: FileHandle) -> Vec<u8>
2023-07-12 22:33:41 +00:00
// reads up to 4096 bytes of the file
pub fn read_block(file: FileHandle) -> Vec<u8>
2023-07-12 19:48:49 +00:00
// overwrites the contents of the file
pub fn write(file: FileHandle, data: Vec<u8>)
2023-07-12 22:33:41 +00:00
// writes 4096 bytes to the file
pub fn write_block(file: FileHandle, data: Vec<u8>)
2023-07-12 19:48:49 +00:00
// opens a file for reading and writing
pub fn open(path: Path)
// closes the file
pub fn close(file: FileHandle)
// deletes a file
pub fn delete(path: Path)
```
Opening a file opens it using the corresponding filesystem. Multiple processes can open the same file in any mode, and the file only leaves the FS cache when no process has it open anymore.
## Minimal FS API
```
trait FileIO {
// reads the whole file
pub fn read(path: Path) -> Vec<u8>
// overwrites the file contents
pub fn write(path: Path, data: Vec<u8>)
// opens a file for reading and writing
pub fn open(path: Path)
// closes a file, removing it from the cache
pub fn close(path: Path)
// deletes a file
pub fn delete(path: Path)
}
```
All filesystems must expose at least these functions in order to work with the VFS.
## Structure
2023-07-12 22:33:41 +00:00
### Mount Point
2023-07-12 19:48:49 +00:00
```
path_len: u64
path: [u8; <path_len>]
entries: u64
addr: u64
```
2023-07-12 22:33:41 +00:00
There is one of these for each mount point, stored sequentially within the root directory it belongs to. The list ends when it finds a `path_len` of 0
2023-07-12 19:48:49 +00:00
2023-07-12 22:33:41 +00:00
### Inode
2023-07-12 19:48:49 +00:00
```
2023-07-12 22:33:41 +00:00
next: u64
flags: u8
2023-07-13 03:20:18 +00:00
size: u64
2023-07-12 19:48:49 +00:00
addr: u64
2023-07-13 03:20:18 +00:00
name_len: u64
name: [u8; <name_len>]
2023-07-12 19:48:49 +00:00
```
2023-07-13 03:20:18 +00:00
There can be many of these in a mount point, and they can be nested within eachother. If this is the last entry in the parent, `next` will refer to this inode, otherwise it will be the address of the next inode under the parent. `addr` is the address of the first member of this inode if it's a directory. `size` specifies the number of inodes within a directory, or the number of bytes in a file
2023-07-12 22:33:41 +00:00
#### Flags
2023-07-12 23:38:17 +00:00
2023-07-12 22:33:41 +00:00
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
| NA | NA | NA | NA | NA | NA | dir | mnt |
`dir` is set if the inode is a directory, or unset if it's a file.
`mnt` is set if the inode is a mount point
#### create_inode
1. traverse the path until we reach the last element or a nonexistent directory
2. if any path elements are mount points, request the filesystem belonging to it to create the item and if it succeeds create the inode