mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
fs: binding of pipes to vnodes
This commit is contained in:
+15
-3
@@ -10,6 +10,7 @@
|
|||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <kernel/vmmcache.h>
|
#include <kernel/vmmcache.h>
|
||||||
|
#include <kernel/pipefs.h>
|
||||||
|
|
||||||
#define INODE_ROOT 2
|
#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) {
|
static int ext2_open(vnode_t **vnodep, int flags, cred_t *cred) {
|
||||||
vnode_t *vnode = *vnodep;
|
vnode_t *vnode = *vnodep;
|
||||||
int type = vnode->type;
|
int type = vnode->type;
|
||||||
// TODO these types of files
|
// TODO device files
|
||||||
__assert(type == V_TYPE_REGULAR || type == V_TYPE_DIR || type == V_TYPE_LINK);
|
__assert(type == V_TYPE_REGULAR || type == V_TYPE_DIR || type == V_TYPE_LINK || type == V_TYPE_FIFO);
|
||||||
return 0;
|
|
||||||
|
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) {
|
static int ext2_close(vnode_t *vnode, int flags, cred_t *cred) {
|
||||||
|
|||||||
@@ -399,3 +399,20 @@ int pipefs_newpipe(vnode_t **nodep) {
|
|||||||
|
|
||||||
return 0;
|
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
@@ -13,6 +13,7 @@
|
|||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <kernel/vmmcache.h>
|
#include <kernel/vmmcache.h>
|
||||||
|
#include <kernel/pipefs.h>
|
||||||
|
|
||||||
static scache_t *nodecache;
|
static scache_t *nodecache;
|
||||||
static tmpfsnode_t *newnode(vfs_t *vfs, int type);
|
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;
|
vnode_t *node = *nodep;
|
||||||
tmpfsnode_t *tmpnode = (tmpfsnode_t *)node;
|
tmpfsnode_t *tmpnode = (tmpfsnode_t *)node;
|
||||||
|
|
||||||
|
int error = 0;
|
||||||
if (node->type == V_TYPE_CHDEV || node->type == V_TYPE_BLKDEV) {
|
if (node->type == V_TYPE_CHDEV || node->type == V_TYPE_BLKDEV) {
|
||||||
vnode_t *devnode;
|
vnode_t *devnode;
|
||||||
int err = devfs_getnode(node, tmpnode->attr.rdevmajor, tmpnode->attr.rdevminor, &devnode);
|
error = devfs_getnode(node, tmpnode->attr.rdevmajor, tmpnode->attr.rdevminor, &devnode);
|
||||||
if (err)
|
if (error)
|
||||||
return err;
|
return error;
|
||||||
|
|
||||||
VOP_RELEASE(node);
|
VOP_RELEASE(node);
|
||||||
VOP_HOLD(devnode);
|
VOP_HOLD(devnode);
|
||||||
*nodep = 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) {
|
static int tmpfs_close(vnode_t *node, int flag, cred_t *cred) {
|
||||||
|
|||||||
@@ -18,5 +18,6 @@ typedef struct pipenode_t {
|
|||||||
|
|
||||||
void pipefs_init();
|
void pipefs_init();
|
||||||
int pipefs_newpipe(vnode_t **nodep);
|
int pipefs_newpipe(vnode_t **nodep);
|
||||||
|
int pipefs_getbinding(vnode_t *node, vnode_t **pipep);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -78,7 +78,11 @@ typedef struct vnode_t {
|
|||||||
int type;
|
int type;
|
||||||
vfs_t *vfs;
|
vfs_t *vfs;
|
||||||
vfs_t *vfsmounted;
|
vfs_t *vfsmounted;
|
||||||
void *socketbinding;
|
union {
|
||||||
|
void *socketbinding;
|
||||||
|
void *fifobinding;
|
||||||
|
};
|
||||||
|
|
||||||
struct page_t *pages;
|
struct page_t *pages;
|
||||||
} vnode_t;
|
} vnode_t;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user