sockets: initial impl

This commit is contained in:
Matheus
2022-10-18 00:01:06 -03:00
parent e0953cd1b0
commit 4522b6c2da
14 changed files with 745 additions and 5 deletions
+22 -1
View File
@@ -161,8 +161,29 @@ static int tmpfs_chmod(vnode_t* node, mode_t mode){
return 0;
}
static int tmpfs_mksocket(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;
}
stat* st = &node->st;
st->st_mode = MAKETYPE(TYPE_SOCKET) | mode;
st->st_blksize = PAGE_SIZE;
st->st_ino = parent->vnode.fs->data++;
return 0;
}
static fscalls_t funcs = {
tmpfs_mount, tmpfs_unmount, tmpfs_open, tmpfs_close, tmpfs_mkdir, tmpfs_create, tmpfs_write, tmpfs_read, tmpfs_getdirent, tmpfs_chmod
tmpfs_mount, tmpfs_unmount, tmpfs_open, tmpfs_close, tmpfs_mkdir, tmpfs_create, tmpfs_write, tmpfs_read, tmpfs_getdirent, tmpfs_chmod, tmpfs_mksocket
};
+37 -2
View File
@@ -206,6 +206,7 @@ int vfs_getdirent(dirnode_t* node, dent_t* buff, size_t count, uintmax_t offset,
return err;
}
int vfs_open(vnode_t** buff, dirnode_t* ref, char* path){
vnode_t* node;
@@ -258,8 +259,43 @@ int vfs_create(dirnode_t* ref, char* path, mode_t mode){
return 0;
}
int vfs_mkdir(dirnode_t* ref, char* path, mode_t mode){
int vfs_mksocket(dirnode_t* ref, char* path, mode_t mode){
dirnode_t* parent = NULL;
dirnode_t* buff = NULL;
char name[512];
spinlock_acquire(&lock);
int result = vfs_resolvepath(&buff, &parent, ref, path, name);
if(buff){
spinlock_release(&lock);
return EEXIST;
}
if(!parent){
spinlock_release(&lock);
return result;
}
if(!parent->vnode.fs->calls->mksocket){
spinlock_release(&lock);
return ENOSYS;
}
result = parent->vnode.fs->calls->mksocket(parent, name, mode);
spinlock_release(&lock);
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;
@@ -279,7 +315,6 @@ int vfs_mkdir(dirnode_t* ref, char* path, mode_t mode){
return result;
}
result = parent->vnode.fs->calls->mkdir(parent, name, mode);
spinlock_release(&lock);