api/io: readlinkat

This commit is contained in:
Mark 2020-08-30 12:44:22 +03:00
parent e0f0087ccc
commit 074862b9ee
9 changed files with 59 additions and 5 deletions

View File

@ -59,6 +59,7 @@ void *syscall_table[256] = {
[SYSCALL_NR_UNLINKAT] = sys_unlinkat,
[SYSCALL_NR_READDIR] = sys_readdir,
[SYSCALL_NR_CHMOD] = sys_chmod,
[SYSCALL_NR_READLINKAT] = sys_readlinkat,
[SYSCALL_NR_CHOWN] = sys_chown,
[SYSCALL_NR_MKNOD] = sys_mknod,

View File

@ -122,9 +122,9 @@ int ram_vnode_bset_resize(struct vnode *vn, size_t size) {
_assert(block_start <= block_index);
for (size_t i = block_start; i < block_index; ++i) {
_assert(priv->bpa_l1[l1_index]);
mm_phys_free_page(MM_PHYS(priv->bpa_l1[l1_index]));
priv->bpa_l1[l1_index] = NULL;
_assert(priv->bpa_l1[i]);
mm_phys_free_page(MM_PHYS(priv->bpa_l1[i]));
priv->bpa_l1[i] = NULL;
}
}
// TODO: handle L2

View File

@ -545,6 +545,38 @@ int vfs_fstatat(struct vfs_ioctx *ctx, struct vnode *at, const char *path, struc
return node->op->stat(node, st);
}
ssize_t vfs_readlinkat(struct vfs_ioctx *ctx,
struct vnode *at,
const char *restrict pathname,
char *restrict buf,
size_t lim) {
struct vnode *node;
int res;
_assert(pathname);
_assert(ctx);
_assert(buf);
if (!at) {
at = ctx->cwd_vnode;
}
if ((res = vfs_find(ctx, at, pathname, AT_SYMLINK_NOFOLLOW, &node)) != 0) {
return res;
}
if (node->type != VN_LNK) {
return -EINVAL;
}
if (!node->op || !node->op->readlink) {
kerror("readlink() not implemented for node\n");
return -EINVAL;
}
return node->op->readlink(node, buf, lim);
}
int vfs_ftruncate(struct vfs_ioctx *ctx, struct vnode *node, off_t length) {
_assert(ctx);
_assert(node);

View File

@ -57,7 +57,7 @@ struct vnode_operations {
int (*chmod) (struct vnode *node, mode_t mode);
int (*chown) (struct vnode *node, uid_t uid, gid_t gid);
int (*readlink) (struct vnode *at, char *buf, size_t lim);
ssize_t (*readlink) (struct vnode *at, char *buf, size_t lim);
ssize_t (*read) (struct ofile *fd, void *buf, size_t count);
ssize_t (*write) (struct ofile *fd, const void *buf, size_t count);

View File

@ -46,6 +46,11 @@ int vfs_openat(struct vfs_ioctx *ctx,
struct vnode *at,
const char *path,
int flags, int mode);
ssize_t vfs_readlinkat(struct vfs_ioctx *ctx,
struct vnode *at,
const char *restrict pathname,
char *restrict buf,
size_t lim);
void vfs_close(struct vfs_ioctx *ctx, struct ofile *fd);
int vfs_readdir(struct vfs_ioctx *ctx, struct ofile *fd, struct dirent *ent);
int vfs_unlinkat(struct vfs_ioctx *ctx, struct vnode *at, const char *pathname, int flags);

View File

@ -25,3 +25,4 @@ int sys_chmod(const char *path, mode_t mode);
int sys_chown(const char *path, uid_t uid, gid_t gid);
off_t sys_lseek(int fd, off_t offset, int whence);
int sys_mknod(const char *filename, int mode, unsigned int dev);
ssize_t sys_readlinkat(int dfd, const char *restrict pathname, char *restrict buf, size_t lim);

View File

@ -24,6 +24,7 @@
#define SYSCALL_NR_UNLINKAT 87
#define SYSCALL_NR_READDIR 89
#define SYSCALL_NR_CHMOD 90
#define SYSCALL_NR_READLINKAT 91
#define SYSCALL_NR_CHOWN 92
#define SYSCALL_NR_MKNOD 133

View File

@ -253,6 +253,20 @@ int sys_faccessat(int dfd, const char *pathname, int mode, int flags) {
return vfs_faccessat(get_ioctx(), at, pathname, mode, flags);
}
ssize_t sys_readlinkat(int dfd, const char *restrict pathname, char *restrict buf, size_t lim) {
userptr_check(pathname);
userptr_check(buf);
struct vnode *at;
int res;
if ((res = get_at_vnode(dfd, &at, 0)) != 0) {
return res;
}
return vfs_readlinkat(get_ioctx(), at, pathname, buf, lim);
}
int sys_pipe(int *filedes) {
userptr_check(filedes);
struct process *proc = thread_self->proc;

View File

@ -160,7 +160,7 @@ int sys_waitpid(pid_t pid, int *status, int flags) {
struct process *proc_self = thr->proc;
_assert(proc_self);
struct process *chld;
struct process *chld = NULL;
struct io_notify *notify;
int res;