fs: binding of pipes to vnodes

This commit is contained in:
Matheus
2024-08-11 13:06:46 -03:00
parent f02a63473f
commit a24be5cbc5
5 changed files with 53 additions and 8 deletions
+15 -3
View File
@@ -10,6 +10,7 @@
#include <logging.h>
#include <util.h>
#include <kernel/vmmcache.h>
#include <kernel/pipefs.h>
#define INODE_ROOT 2
@@ -1052,9 +1053,20 @@ static void freeinode(ext2fs_t *fs, inode_t *inode, int id) {
static int ext2_open(vnode_t **vnodep, int flags, cred_t *cred) {
vnode_t *vnode = *vnodep;
int type = vnode->type;
// TODO these types of files
__assert(type == V_TYPE_REGULAR || type == V_TYPE_DIR || type == V_TYPE_LINK);
return 0;
// TODO device files
__assert(type == V_TYPE_REGULAR || type == V_TYPE_DIR || type == V_TYPE_LINK || type == V_TYPE_FIFO);
int error = 0;
if (type == V_TYPE_FIFO) {
VOP_LOCK(*vnodep);
vnode_t *fifo;
error = pipefs_getbinding(*vnodep, &fifo);
VOP_UNLOCK(*vnodep);
if (error == 0)
*vnodep = fifo;
}
return error;
}
static int ext2_close(vnode_t *vnode, int flags, cred_t *cred) {
+17
View File
@@ -399,3 +399,20 @@ int pipefs_newpipe(vnode_t **nodep) {
return 0;
}
// assumes node is locked upon calling
int pipefs_getbinding(vnode_t *node, vnode_t **pipep) {
__assert(node->type == V_TYPE_FIFO);
if (node->fifobinding) {
*pipep = node->fifobinding;
return 0;
}
int error = pipefs_newpipe(pipep);
if (error)
return error;
node->fifobinding = *pipep;
return error;
}
+15 -4
View File
@@ -13,6 +13,7 @@
#include <arch/cpu.h>
#include <string.h>
#include <kernel/vmmcache.h>
#include <kernel/pipefs.h>
static scache_t *nodecache;
static tmpfsnode_t *newnode(vfs_t *vfs, int type);
@@ -158,18 +159,28 @@ static int tmpfs_open(vnode_t **nodep, int flag, cred_t *cred) {
vnode_t *node = *nodep;
tmpfsnode_t *tmpnode = (tmpfsnode_t *)node;
int error = 0;
if (node->type == V_TYPE_CHDEV || node->type == V_TYPE_BLKDEV) {
vnode_t *devnode;
int err = devfs_getnode(node, tmpnode->attr.rdevmajor, tmpnode->attr.rdevminor, &devnode);
if (err)
return err;
error = devfs_getnode(node, tmpnode->attr.rdevmajor, tmpnode->attr.rdevminor, &devnode);
if (error)
return error;
VOP_RELEASE(node);
VOP_HOLD(devnode);
*nodep = devnode;
}
return 0;
if (node->type == V_TYPE_FIFO) {
VOP_LOCK(*nodep);
vnode_t *fifo;
error = pipefs_getbinding(*nodep, &fifo);
VOP_UNLOCK(*nodep);
if (error == 0)
*nodep = fifo;
}
return error;
}
static int tmpfs_close(vnode_t *node, int flag, cred_t *cred) {
+1
View File
@@ -18,5 +18,6 @@ typedef struct pipenode_t {
void pipefs_init();
int pipefs_newpipe(vnode_t **nodep);
int pipefs_getbinding(vnode_t *node, vnode_t **pipep);
#endif
+5 -1
View File
@@ -78,7 +78,11 @@ typedef struct vnode_t {
int type;
vfs_t *vfs;
vfs_t *vfsmounted;
void *socketbinding;
union {
void *socketbinding;
void *fifobinding;
};
struct page_t *pages;
} vnode_t;