fs: add readlink() feature to per-process links
This commit is contained in:
parent
d83b93075c
commit
d91a9114c7
2
fs/vfs.c
2
fs/vfs.c
@ -192,7 +192,7 @@ static int vfs_link_resolve_internal(struct vfs_ioctx *ctx,
|
||||
if (lnk->flags & VN_PER_PROCESS) {
|
||||
_assert(lnk->target_func);
|
||||
// TODO: pass it as an argument instead of ioctx
|
||||
target = lnk->target_func(thread_self, lnk);
|
||||
target = lnk->target_func(thread_self, lnk, NULL, 0);
|
||||
} else {
|
||||
target = lnk->target;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "sys/char/chr.h"
|
||||
#include "fs/ofile.h"
|
||||
#include "fs/node.h"
|
||||
#include "sys/thread.h"
|
||||
#include "fs/vfs.h"
|
||||
#include "sys/string.h"
|
||||
#include "sys/assert.h"
|
||||
@ -570,6 +571,14 @@ ssize_t vfs_readlinkat(struct vfs_ioctx *ctx,
|
||||
}
|
||||
|
||||
if (!node->op || !node->op->readlink) {
|
||||
if ((node->flags & VN_PER_PROCESS) && node->target_func) {
|
||||
if (node->target_func(thread_self, node, buf, lim) != NULL) {
|
||||
return 0;
|
||||
} else {
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
kerror("readlink() not implemented for node\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ struct thread;
|
||||
struct vnode;
|
||||
struct fs;
|
||||
|
||||
typedef struct vnode *(*vnode_link_getter_t) (struct thread *, struct vnode *);
|
||||
typedef struct vnode *(*vnode_link_getter_t) (struct thread *, struct vnode *, char *, size_t);
|
||||
|
||||
enum vnode_type {
|
||||
VN_REG,
|
||||
|
@ -175,13 +175,25 @@ void tty_putc(struct chrdev *tty, int c) {
|
||||
}
|
||||
}
|
||||
|
||||
static struct vnode *tty_link_getter(struct thread *ctx, struct vnode *link) {
|
||||
static struct vnode *tty_link_getter(struct thread *ctx, struct vnode *link, char *buf, size_t len) {
|
||||
struct process *proc;
|
||||
|
||||
if (!(proc = ctx->proc)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
if (proc->ctty) {
|
||||
if (strlen(proc->ctty->name) < len) {
|
||||
strcpy(buf, proc->ctty->name);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
buf[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return proc->ctty;
|
||||
}
|
||||
|
||||
|
11
sys/thread.c
11
sys/thread.c
@ -61,8 +61,17 @@ static int sysfs_proc_ioctx(void *ctx, char *buf, size_t lim) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct vnode *sysfs_proc_self(struct thread *ctx, struct vnode *link) {
|
||||
static struct vnode *sysfs_proc_self(struct thread *ctx, struct vnode *link, char *buf, size_t lim) {
|
||||
_assert(ctx && ctx->proc);
|
||||
struct vnode *res = ctx->proc->fs_entry;
|
||||
|
||||
if (buf && strlen(res->name) < lim) {
|
||||
if (strlen(res->name) < lim) {
|
||||
strcpy(buf, res->name);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return ctx->proc->fs_entry;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user