mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-30 05:58:22 +00:00
add tmpfs writing, vfs node tree dumping and fix some stupid issues
This commit is contained in:
+47
-6
@@ -2,6 +2,8 @@
|
||||
#include <kernel/vfs.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <arch/mmu.h>
|
||||
#include <kernel/pmm.h>
|
||||
#include <string.h>
|
||||
|
||||
static int tmpfs_mount(dirnode_t* mountpoint, vnode_t* device, int mountflags, void* fsinfo){
|
||||
|
||||
@@ -23,6 +25,34 @@ static int tmpfs_mount(dirnode_t* mountpoint, vnode_t* device, int mountflags, v
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tmpfs_write(int* error, vnode_t* node, void* buff, size_t count, size_t offset){
|
||||
|
||||
// TODO use virtual memory
|
||||
|
||||
size_t targetpage = (count + offset) / PAGE_SIZE;
|
||||
|
||||
if(node->st.st_blocks <= targetpage){
|
||||
void* new = pmm_hhdmalloc(targetpage+1);
|
||||
if(!new){
|
||||
*error = ENOMEM;
|
||||
return -1;
|
||||
};
|
||||
memcpy(new, node->fsdata, node->st.st_size);
|
||||
pmm_free(node->fsdata, node->st.st_size / PAGE_SIZE + 1);
|
||||
node->fsdata = new;
|
||||
node->st.st_blocks = targetpage+1;
|
||||
node->st.st_size = count + offset;
|
||||
}
|
||||
|
||||
memcpy(node->fsdata + offset, buff, count);
|
||||
|
||||
if(offset + count > node->st.st_size)
|
||||
node->st.st_size = offset + count;
|
||||
|
||||
*error = 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
static int tmpfs_unmount(fs_t* fs) UNIMPLEMENTED
|
||||
static int tmpfs_open(dirnode_t* parent, char* name) UNIMPLEMENTED
|
||||
static int tmpfs_close(vnode_t* node) UNIMPLEMENTED
|
||||
@@ -49,27 +79,38 @@ static int tmpfs_mkdir(dirnode_t* parent, char* name, mode_t mode){
|
||||
}
|
||||
|
||||
static int tmpfs_create(dirnode_t* parent, char* name, mode_t mode){
|
||||
|
||||
vnode_t* node = vfs_newnode(name, parent->vnode.fs, NULL);
|
||||
|
||||
if(!node)
|
||||
|
||||
// TODO use virtual memory
|
||||
void* firstpage = pmm_hhdmalloc(1);
|
||||
|
||||
if(!firstpage)
|
||||
return ENOMEM;
|
||||
|
||||
vnode_t* node = vfs_newnode(name, parent->vnode.fs, NULL);
|
||||
|
||||
if(!node){
|
||||
pmm_free(firstpage, 1);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
if(!hashtable_insert(&parent->children, name, node)){
|
||||
pmm_free(firstpage, 1);
|
||||
vfs_destroynode(node);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
node->parent = parent;
|
||||
node->fsdata = firstpage;
|
||||
stat* st = &node->st;
|
||||
st->st_mode = MAKETYPE(TYPE_DIR) | GETMODE(mode);
|
||||
st->st_blksize = PAGE_SIZE;
|
||||
st->st_blocks = 1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static fscalls_t funcs = {
|
||||
tmpfs_mount, tmpfs_unmount, tmpfs_open, tmpfs_close, tmpfs_mkdir, tmpfs_create
|
||||
tmpfs_mount, tmpfs_unmount, tmpfs_open, tmpfs_close, tmpfs_mkdir, tmpfs_create, tmpfs_write
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user