Skip to content

Commit

Permalink
✨ 155 虚拟文件系统
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenBaby committed Jul 22, 2023
1 parent 0409c4f commit 56cc799
Show file tree
Hide file tree
Showing 25 changed files with 2,556 additions and 2,040 deletions.
34 changes: 34 additions & 0 deletions docs/11 文件系统/155 虚拟文件系统.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 虚拟文件系统

定义和重构虚拟文件系统:

```c++
typedef struct fs_op_t
{
int (*mkfs)(dev_t dev, int args);

int (*super)(dev_t dev, super_t *super);

int (*open)(inode_t *dir, char *name, int flags, int mode, inode_t **result);
void (*close)(inode_t *inode);

int (*read)(inode_t *inode, char *data, int len, off_t offset);
int (*write)(inode_t *inode, char *data, int len, off_t offset);
int (*truncate)(inode_t *inode);

int (*stat)(inode_t *inode, stat_t *stat);
int (*permission)(inode_t *inode, int mask);

int (*namei)(inode_t *dir, char *name, char **next, inode_t **result);
int (*mkdir)(inode_t *dir, char *name, int mode);
int (*rmdir)(inode_t *dir, char *name);
int (*link)(inode_t *odir, char *oldname, inode_t *ndir, char *newname);
int (*unlink)(inode_t *dir, char *name);
int (*mknod)(inode_t *dir, char *name, int mode, int dev);
int (*readdir)(inode_t *inode, dentry_t *entry, size_t count, off_t offset);
} fs_op_t;
```
## 参考
- <https://github.com/ringgaard/sanos>
4 changes: 2 additions & 2 deletions src/builtin/ls.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void reckon_size(int *size, char *qualifer)
int main(int argc, char const *argv[], char const *envp[])
{
fd_t fd = open(".", O_RDONLY, 0);
if (fd == EOF)
if (fd < EOK)
return EOF;

bool list = false;
Expand All @@ -110,7 +110,7 @@ int main(int argc, char const *argv[], char const *envp[])
while (true)
{
int len = readdir(fd, &entry, 1);
if (len == EOF)
if (len < EOK)
break;
if (!entry.nr)
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/builtin/osh.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void builtin_exec(int argc, char *argv[])

stat_t statbuf;
sprintf(name, "/bin/%s.out", argv[i]);
if (stat(name, &statbuf) == EOF)
if (stat(name, &statbuf) < EOK)
{
printf("osh: command not found: %s\n", argv[i]);
return;
Expand Down
204 changes: 0 additions & 204 deletions src/fs/bmap.c

This file was deleted.

13 changes: 5 additions & 8 deletions src/fs/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ void dev_init()
// 第一个虚拟磁盘作为 /dev 文件系统
device = device_find(DEV_RAMDISK, 0);
assert(device);
devmkfs(device->dev, 0);
fs_get_op(FS_TYPE_MINIX)->mkfs(device->dev, 0);

super_block_t *sb = read_super(device->dev);
sb->iroot = iget(device->dev, 1);
sb->imount = namei("/dev");
sb->imount->mount = device->dev;
super_t *super = read_super(device->dev);
assert(super->iroot);
super->imount = namei("/dev");
super->imount->mount = device->dev;

device = device_find(DEV_CONSOLE, 0);
mknod("/dev/console", IFCHR | 0200, device->dev);
Expand Down Expand Up @@ -108,21 +108,18 @@ void dev_init()
file = &file_table[STDIN_FILENO];
inode = namei("/dev/stdin");
file->inode = inode;
file->mode = inode->desc->mode;
file->flags = O_RDONLY;
file->offset = 0;

file = &file_table[STDOUT_FILENO];
inode = namei("/dev/stdout");
file->inode = inode;
file->mode = inode->desc->mode;
file->flags = O_WRONLY;
file->offset = 0;

file = &file_table[STDERR_FILENO];
inode = namei("/dev/stderr");
file->inode = inode;
file->mode = inode->desc->mode;
file->flags = O_WRONLY;
file->offset = 0;
}
Loading

0 comments on commit 56cc799

Please sign in to comment.