mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
create and mkdir funcs
file and directory creation functions for both the vfs and tmpfs
This commit is contained in:
+51
-4
@@ -1,28 +1,75 @@
|
||||
#include <kernel/tmpfs.h>
|
||||
#include <kernel/vfs.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <arch/mmu.h>
|
||||
|
||||
static int tmpfs_mount(dirnode_t** rootptr, vnode_t* device, int mountflags, void* fsinfo){
|
||||
static int tmpfs_mount(dirnode_t* mountpoint, vnode_t* device, int mountflags, void* fsinfo){
|
||||
|
||||
fs_t* desc = alloc(sizeof(fs_t));
|
||||
|
||||
if(!desc)
|
||||
return ENOMEM;
|
||||
|
||||
dirnode_t* root = vfs_newdirnode(desc, NULL);
|
||||
dirnode_t* root = vfs_newdirnode(mountpoint->vnode.name, desc, NULL);
|
||||
|
||||
if(!root){
|
||||
free(desc);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
*rootptr = root;
|
||||
desc->calls = tmpfs_getfuncs();
|
||||
mountpoint->mount = root;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
static int tmpfs_mkdir(dirnode_t* parent, char* name, mode_t mode){
|
||||
|
||||
dirnode_t* node = vfs_newdirnode(name, parent->vnode.fs, NULL);
|
||||
|
||||
if(!node)
|
||||
return ENOMEM;
|
||||
|
||||
if(!hashtable_insert(&parent->children, name, node)){
|
||||
vfs_destroynode(node);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
node->vnode.parent = parent;
|
||||
stat* st = &node->vnode.st;
|
||||
st->st_mode = MAKETYPE(TYPE_DIR) | GETMODE(mode);
|
||||
st->st_blksize = PAGE_SIZE;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int tmpfs_create(dirnode_t* parent, char* name, mode_t mode){
|
||||
|
||||
vnode_t* node = vfs_newnode(name, parent->vnode.fs, NULL);
|
||||
|
||||
if(!node)
|
||||
return ENOMEM;
|
||||
|
||||
if(!hashtable_insert(&parent->children, name, node)){
|
||||
vfs_destroynode(node);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
node->parent = parent;
|
||||
stat* st = &node->st;
|
||||
st->st_mode = MAKETYPE(TYPE_DIR) | GETMODE(mode);
|
||||
st->st_blksize = PAGE_SIZE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static fscalls_t funcs = {
|
||||
tmpfs_mount
|
||||
tmpfs_mount, tmpfs_unmount, tmpfs_open, tmpfs_close, tmpfs_mkdir, tmpfs_create
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user