fs: add ramfs
This commit is contained in:
parent
a7c526d2a6
commit
750ffa2e16
13 changed files with 355 additions and 55 deletions
87
fs/vfs/vfs.c
87
fs/vfs/vfs.c
|
|
@ -1,44 +1,87 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include "lib/rbtree.h"
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/slab.h>
|
||||
|
||||
#include <lib/list.h>
|
||||
#include <lib/string.h>
|
||||
#include <fs/vfs.h>
|
||||
|
||||
static fs_t root_fs = {0};
|
||||
#include <lib/errno.h>
|
||||
|
||||
void vfs_mount(inode_t *mount_point, fs_t *fs_to_mount)
|
||||
static fs_t *root_fs = NULL;
|
||||
|
||||
static list_t fs_type_list = {0};
|
||||
|
||||
int vfs_mount(inode_t *mount_point, fs_t *fs_to_mount)
|
||||
{
|
||||
if (!mount_point) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void vfs_close_inode(inode_t *inode)
|
||||
{
|
||||
list_item_t *entry = inode->dentries.head;
|
||||
while (entry) {
|
||||
dirent_t *dirent = entry->ptr;
|
||||
|
||||
if (dirent->inode) {
|
||||
vfs_close_inode(dirent->inode);
|
||||
if (root_fs) {
|
||||
return -EBUSY;
|
||||
} else {
|
||||
root_fs = fs_to_mount;
|
||||
}
|
||||
|
||||
inode_free(inode);
|
||||
|
||||
entry = entry->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vfs_open_inode(const char *path)
|
||||
static int iter_inode_dirent(inode_t *ino, const char *name, inode_t **out)
|
||||
{
|
||||
fs_t *fs = ino->fs;
|
||||
dirent_t *d = inode_find_dirent(ino, name);
|
||||
if (d) {
|
||||
if (d->inode)
|
||||
*out = d->inode;
|
||||
else
|
||||
return fs->fs_ops.open_inode(fs, d->ino_num, out);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vfs_get_inode(const char *path, inode_t *ret)
|
||||
{
|
||||
inode_t *ino = root_fs->root_inode;
|
||||
|
||||
char name[512] = {0};
|
||||
|
||||
char c;
|
||||
int i = 0;
|
||||
while (i < 256 && ino) {
|
||||
c = *path++;
|
||||
if (c == '/' || c == '\0') {
|
||||
name[i] = 0;
|
||||
i = 0;
|
||||
|
||||
int res = iter_inode_dirent(ino, name, &ino);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
if (c == '\0')
|
||||
break;
|
||||
} else {
|
||||
name[i] = c;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
void vfs_register(struct fs_type *fs)
|
||||
{
|
||||
struct fs_type *ins = kalloc(sizeof(*fs), ALLOC_KERN);
|
||||
memcpy(ins, fs, sizeof(*fs));
|
||||
list_insert(&fs_type_list, ins);
|
||||
}
|
||||
|
||||
void vfs_init()
|
||||
{
|
||||
void inode_init();
|
||||
inode_init();
|
||||
memset(&root_fs, 0, sizeof(root_fs));
|
||||
root_fs = kalloc(sizeof(fs_t), ALLOC_KERN);
|
||||
memset(root_fs, 0, sizeof(*root_fs));
|
||||
|
||||
list_create(&fs_type_list);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue