mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
create and mkdir funcs
file and directory creation functions for both the vfs and tmpfs
This commit is contained in:
+67
-16
@@ -14,6 +14,50 @@ static inline dirnode_t* mountpoint(dirnode_t* node){
|
||||
return ret;
|
||||
}
|
||||
|
||||
int vfs_create(dirnode_t* ref, char* path, mode_t mode){
|
||||
|
||||
dirnode_t* parent = NULL;
|
||||
dirnode_t* buff = NULL;
|
||||
|
||||
char name[512];
|
||||
|
||||
int result = vfs_resolvepath(&buff, &parent, ref, path, name);
|
||||
|
||||
if(!parent)
|
||||
return result;
|
||||
|
||||
if(buff)
|
||||
return EEXIST;
|
||||
|
||||
result = parent->vnode.fs->calls->create(parent, name, NULL);
|
||||
|
||||
if(result) return result;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vfs_mkdir(dirnode_t* ref, char* path, mode_t mode){
|
||||
|
||||
dirnode_t* parent = NULL;
|
||||
dirnode_t* buff = NULL;
|
||||
|
||||
char name[512];
|
||||
|
||||
int result = vfs_resolvepath(&buff, &parent, ref, path, name);
|
||||
|
||||
if(!parent)
|
||||
return result;
|
||||
|
||||
if(buff)
|
||||
return EEXIST;
|
||||
|
||||
result = parent->vnode.fs->calls->mkdir(parent, name, NULL);
|
||||
|
||||
if(result) return result;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vfs_mount(dirnode_t* ref, char* device, char* mountpoint, char* fs, int mountflags, void* fsinfo){
|
||||
|
||||
fscalls_t* fscalls = hashtable_get(&fsfuncs, fs);
|
||||
@@ -23,11 +67,12 @@ int vfs_mount(dirnode_t* ref, char* device, char* mountpoint, char* fs, int moun
|
||||
|
||||
vnode_t* dev = NULL;
|
||||
dirnode_t* mountdir = ref;
|
||||
dirnode_t* parent;
|
||||
|
||||
if(device){
|
||||
dev = ref;
|
||||
if(*device){
|
||||
int result = vfs_resolvepath(&dev, ref, device);
|
||||
int result = vfs_resolvepath(&dev, &parent, ref, device, NULL);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
@@ -35,7 +80,7 @@ int vfs_mount(dirnode_t* ref, char* device, char* mountpoint, char* fs, int moun
|
||||
}
|
||||
|
||||
|
||||
int result = vfs_resolvepath(&mountdir, ref, mountpoint);
|
||||
int result = vfs_resolvepath(&mountdir, &parent, ref, mountpoint, NULL);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
@@ -43,16 +88,9 @@ int vfs_mount(dirnode_t* ref, char* device, char* mountpoint, char* fs, int moun
|
||||
if(GETTYPE(mountdir->vnode.st.st_mode) != TYPE_DIR)
|
||||
return ENOTDIR;
|
||||
|
||||
dirnode_t* mount;
|
||||
|
||||
result = fscalls->mount(&mount, dev, mountflags, fsinfo);
|
||||
result = fscalls->mount(mountdir, dev, mountflags, fsinfo);
|
||||
|
||||
if(result)
|
||||
return result;
|
||||
|
||||
mountdir->mount = mount;
|
||||
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
vnode_t* vfs_newnode(char* name, fs_t* fs, void* fsdata){
|
||||
@@ -100,7 +138,7 @@ dirnode_t* vfs_newdirnode(char* name, fs_t* fs, void* fsdata){
|
||||
|
||||
}
|
||||
|
||||
int vfs_resolvepath(vnode_t** result, dirnode_t* ref, char *path){
|
||||
int vfs_resolvepath(vnode_t** result, dirnode_t** resultparent, dirnode_t* ref, char *path, char* namebuff){
|
||||
|
||||
dirnode_t* iterator = ref;
|
||||
char name[512];
|
||||
@@ -114,10 +152,13 @@ int vfs_resolvepath(vnode_t** result, dirnode_t* ref, char *path){
|
||||
|
||||
size_t offset = 0;
|
||||
|
||||
while(path[nameoffset] == '/')
|
||||
++nameoffset;
|
||||
|
||||
while(path[nameoffset] && path[nameoffset] != '/')
|
||||
name[offset++] = path[nameoffset++];
|
||||
|
||||
if(path[nameoffset] == '/')
|
||||
|
||||
while(path[nameoffset] == '/')
|
||||
++nameoffset;
|
||||
|
||||
name[offset] = 0;
|
||||
@@ -132,14 +173,20 @@ int vfs_resolvepath(vnode_t** result, dirnode_t* ref, char *path){
|
||||
iterator = mountpoint(iterator);
|
||||
|
||||
// now try to get the right child
|
||||
|
||||
|
||||
vnode_t* child = hashtable_get(&iterator->children, name);
|
||||
|
||||
if(!child){
|
||||
// open it
|
||||
int status = iterator->vnode.fs->calls->open(iterator, name);
|
||||
if(status)
|
||||
if(status){
|
||||
if(!path[nameoffset]){
|
||||
if(namebuff)
|
||||
strcpy(namebuff, name);
|
||||
*resultparent = iterator;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
child = hashtable_get(&iterator->children, name);
|
||||
|
||||
@@ -148,7 +195,11 @@ int vfs_resolvepath(vnode_t** result, dirnode_t* ref, char *path){
|
||||
iterator = (dirnode_t*)child;
|
||||
|
||||
}
|
||||
|
||||
if(namebuff)
|
||||
strcpy(namebuff, name);
|
||||
|
||||
*resultparent = iterator->vnode.parent;
|
||||
*result = (vnode_t*)iterator;
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user