refining vfs
This commit is contained in:
46
kernel/vfs.c
46
kernel/vfs.c
@@ -3,6 +3,8 @@
|
||||
#include <scheduler.h>
|
||||
|
||||
#include <lib/memory.h>
|
||||
#include <lib/string.h>
|
||||
#include <lib/print.h>
|
||||
|
||||
vfs_node_t* root = NULL;
|
||||
|
||||
@@ -19,18 +21,29 @@ vfs_node_t* vfs_create_root() {
|
||||
return root;
|
||||
}
|
||||
|
||||
void mount(vfs_node_t* _mnt, vfs_node_t* _fs) {
|
||||
void vfs_mount(vfs_node_t* _mnt, vfs_node_t* _fs) {
|
||||
if (!_fs || !_mnt || !(_mnt->flags & VFS_DIRECTORY)) return;
|
||||
_mnt->mnt = _fs;
|
||||
}
|
||||
|
||||
static vfs_node_t* lookup(const char* path) {
|
||||
vfs_node_t* vfs_find(const char* path) {
|
||||
if (path[0] != '/') return NULL;
|
||||
vfs_node_t* current = root;
|
||||
|
||||
if (current->mnt) {
|
||||
current = current->mnt;
|
||||
char* sav;
|
||||
|
||||
size_t path_sz = strlen(path) + 1;
|
||||
char* path_cpy = kalloc(path_sz);
|
||||
memset((uint8_t*)path_cpy, 0, path_sz);
|
||||
memcpy(path, path_cpy, path_sz);
|
||||
|
||||
char* tkn = strtok_r(path_cpy, "/", &sav);
|
||||
|
||||
while (tkn != NULL) {
|
||||
kprintf("Found tkn: %s\n");
|
||||
}
|
||||
|
||||
kfree(path_cpy);
|
||||
|
||||
const char* cmp = path + 1;
|
||||
if (*cmp == '\0') return current;
|
||||
@@ -42,8 +55,12 @@ static vfs_node_t* lookup(const char* path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int open(const char* _path, int flags) {
|
||||
vfs_node_t* file = lookup(_path);
|
||||
vfs_node_t* vfs_mkdir(vfs_node_t* parent, const char* name) {
|
||||
vfs_node_t* node = kalloc(sizeof(vfs_node_t));
|
||||
}
|
||||
|
||||
int vfs_open(const char* _path, int flags) {
|
||||
vfs_node_t* file = vfs_find(_path);
|
||||
if (!file) return -1;
|
||||
|
||||
file_t* f = (file_t*)kalloc(sizeof(file_t));
|
||||
@@ -54,7 +71,7 @@ int open(const char* _path, int flags) {
|
||||
return alloc_fd(f);
|
||||
}
|
||||
|
||||
int read(int fd, void* buf, size_t sz) {
|
||||
int vfs_read(int fd, void* buf, size_t sz) {
|
||||
process_t* curr_p = current_task();
|
||||
if (fd < 0 || fd >= MAX_PROCESS_FDS || !curr_p->fd_table[fd]->node) {
|
||||
return -1;
|
||||
@@ -70,18 +87,7 @@ int read(int fd, void* buf, size_t sz) {
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
int fstat(int fd, file_t* dst) {
|
||||
process_t* curr_p = current_task();
|
||||
if (fd < 0 || fd >= MAX_PROCESS_FDS || !curr_p->fd_table[fd]->node) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
file_t* src = curr_p->fd_table[fd];
|
||||
memcpy(src, dst, sizeof(file_t));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fseek(int fd, size_t offset) {
|
||||
int vfs_seek(int fd, size_t offset) {
|
||||
process_t* curr_p = current_task();
|
||||
if (fd < 0 || fd >= MAX_PROCESS_FDS || !curr_p->fd_table[fd]->node) {
|
||||
return 0;
|
||||
@@ -90,7 +96,7 @@ int fseek(int fd, size_t offset) {
|
||||
file_t* file = curr_p->fd_table[fd];
|
||||
file->offset = offset;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int alloc_fd(file_t* f) {
|
||||
process_t* curr_p = current_task();
|
||||
|
||||
Reference in New Issue
Block a user