From 276d77cd7cc63c94967331d4864cbae395f0b889 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Jul 2020 23:22:16 +0300 Subject: [PATCH] Add mkdirat(2) --- arch/amd64/syscall.c | 10 +--------- fs/vfs_ops.c | 8 ++++++-- include/fs/vfs.h | 6 +----- include/sys/sys_file.h | 11 +---------- include/user/syscall.h | 10 +--------- sys/sys_file.c | 11 +++++++++-- 6 files changed, 19 insertions(+), 37 deletions(-) diff --git a/arch/amd64/syscall.c b/arch/amd64/syscall.c index 29e3fc6..e5a4003 100644 --- a/arch/amd64/syscall.c +++ b/arch/amd64/syscall.c @@ -41,21 +41,13 @@ void *syscall_table[256] = { // I/O [SYSCALL_NR_READ] = sys_read, [SYSCALL_NR_WRITE] = sys_write, - //[SYSCALL_NR_OPEN] = sys_open, - //SUPERSEDED BY: [SYSCALL_NR_OPENAT] = sys_openat, [SYSCALL_NR_CLOSE] = sys_close, - //[SYSCALL_NR_STAT] = sys_stat, - //[SYSCALL_NR_FSTAT] = sys_fstat, - //[SYSCALL_NR_LSTAT] = sys_lstat, - //SUPERSEDED BY: [SYSCALL_NR_FSTATAT] = sys_fstatat, [SYSCALL_NR_LSEEK] = sys_lseek, [SYSCALL_NR_MMAP] = sys_mmap, [SYSCALL_NR_MUNMAP] = sys_munmap, [SYSCALL_NR_IOCTL] = sys_ioctl, - //[SYSCALL_NR_ACCESS] = sys_access, - //SUPERSEDED BY: [SYSCALL_NR_FACCESSAT] = sys_faccessat, [SYSCALL_NR_PIPE] = sys_pipe, [SYSCALL_NR_SELECT] = sys_select, @@ -63,7 +55,7 @@ void *syscall_table[256] = { [SYSCALL_NR_DUP2] = sys_dup2, [SYSCALL_NR_GETCWD] = sys_getcwd, [SYSCALL_NR_CHDIR] = sys_chdir, - [SYSCALL_NR_MKDIR] = sys_mkdir, + [SYSCALL_NR_MKDIRAT] = sys_mkdirat, [SYSCALL_NR_RMDIR] = sys_rmdir, [SYSCALL_NR_CREAT] = sys_creat, [SYSCALL_NR_UNLINK] = sys_unlink, diff --git a/fs/vfs_ops.c b/fs/vfs_ops.c index 3f967a8..52183c3 100644 --- a/fs/vfs_ops.c +++ b/fs/vfs_ops.c @@ -265,12 +265,16 @@ int vfs_open_vnode(struct vfs_ioctx *ctx, struct ofile *fd, struct vnode *node, return 0; } -int vfs_mkdir(struct vfs_ioctx *ctx, const char *path, mode_t mode) { +int vfs_mkdirat(struct vfs_ioctx *ctx, struct vnode *rel, const char *path, mode_t mode) { char parent_path[PATH_MAX]; const char *filename; int res; struct vnode *at; + if (!rel) { + rel = ctx->cwd_vnode; + } + _assert(ctx); _assert(path); @@ -280,7 +284,7 @@ int vfs_mkdir(struct vfs_ioctx *ctx, const char *path, mode_t mode) { } // Find parent vnode - if ((res = vfs_find(ctx, ctx->cwd_vnode, parent_path, 0, &at)) != 0) { + if ((res = vfs_find(ctx, rel, parent_path, 0, &at)) != 0) { return res; } diff --git a/include/fs/vfs.h b/include/fs/vfs.h index 17b2b4c..d1a5bb0 100644 --- a/include/fs/vfs.h +++ b/include/fs/vfs.h @@ -50,17 +50,13 @@ 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_unlink(struct vfs_ioctx *ctx, const char *path); int vfs_rmdir(struct vfs_ioctx *ctx, const char *path); -int vfs_mkdir(struct vfs_ioctx *ctx, const char *path, mode_t mode); +int vfs_mkdirat(struct vfs_ioctx *ctx, struct vnode *at, const char *path, mode_t mode); int vfs_mknod(struct vfs_ioctx *ctx, const char *path, mode_t mode, struct vnode **nod); int vfs_chmod(struct vfs_ioctx *ctx, const char *path, mode_t mode); int vfs_chown(struct vfs_ioctx *ctx, const char *path, uid_t uid, gid_t gid); int vfs_ioctl(struct vfs_ioctx *ctx, struct ofile *fd, unsigned int cmd, void *arg); -//int vfs_access(struct vfs_ioctx *ctx, const char *path, int accmode); int vfs_faccessat(struct vfs_ioctx *ctx, struct vnode *at, const char *path, int accmode, int flags); -//int vfs_fstat(struct vfs_ioctx *ctx, struct ofile *fd, struct stat *st); -//int vfs_lstat(struct vfs_ioctx *ctx, const char *path, struct stat *st); -//int vfs_stat(struct vfs_ioctx *ctx, const char *path, struct stat *st); int vfs_fstatat(struct vfs_ioctx *ctx, struct vnode *at, const char *path, struct stat *st, int flags); int vfs_access_check(struct vfs_ioctx *ctx, int desm, mode_t mode, uid_t uid, gid_t gid); int vfs_access_node(struct vfs_ioctx *ctx, struct vnode *vn, int mode); diff --git a/include/sys/sys_file.h b/include/sys/sys_file.h index f324133..86b2d59 100644 --- a/include/sys/sys_file.h +++ b/include/sys/sys_file.h @@ -5,25 +5,16 @@ ssize_t sys_read(int fd, void *data, size_t lim); ssize_t sys_write(int fd, const void *data, size_t lim); int sys_creat(const char *pathname, int mode); -int sys_mkdir(const char *pathname, int mode); +int sys_mkdirat(int dfd, const char *pathname, int mode); int sys_unlink(const char *pathname); ssize_t sys_readdir(int fd, struct dirent *ent); int sys_rmdir(const char *pathname); int sys_chdir(const char *filename); int sys_ioctl(int fd, unsigned int cmd, void *arg); -// Kinda incompatible with linux, but who cares as long as it's -// POSIX on the libc side int sys_getcwd(char *buf, size_t lim); -// REMOVED: int sys_open(const char *filename, int flags, int mode); int sys_openat(int dfd, const char *filename, int flags, int mode); void sys_close(int fd); -//int sys_stat(const char *filename, struct stat *st); -//int sys_fstat(int fd, struct stat *st); -//int sys_lstat(const char *filename, struct stat *st); -//SUPERSEDED BY: int sys_fstatat(int dfd, const char *pathname, struct stat *st, int flags); -//int sys_access(const char *path, int mode); -//SUPERSEDED BY: int sys_faccessat(int dfd, const char *pathname, int mode, int flags); int sys_pipe(int *filedes); int sys_select(int n, fd_set *inp, fd_set *outp, fd_set *excp, struct timeval *tv); diff --git a/include/user/syscall.h b/include/user/syscall.h index 1835124..f864296 100644 --- a/include/user/syscall.h +++ b/include/user/syscall.h @@ -2,22 +2,14 @@ #define SYSCALL_NR_READ 0 #define SYSCALL_NR_WRITE 1 -// #define SYSCALL_NR_OPEN 2 -// SUPERSEDED BY: #define SYSCALL_NR_OPENAT 2 #define SYSCALL_NR_CLOSE 3 -//#define SYSCALL_NR_STAT 4 -//#define SYSCALL_NR_FSTAT 5 -//#define SYSCALL_NR_LSTAT 6 -//SUPERSEDED BY: #define SYSCALL_NR_FSTATAT 4 #define SYSCALL_NR_LSEEK 8 #define SYSCALL_NR_MMAP 9 #define SYSCALL_NR_MUNMAP 11 #define SYSCALL_NRX_SBRK 12 #define SYSCALL_NR_IOCTL 16 -//#define SYSCALL_NR_ACCESS 21 -//SUPERSEDED BY: #define SYSCALL_NR_FACCESSAT 21 #define SYSCALL_NR_PIPE 22 #define SYSCALL_NR_SELECT 23 @@ -25,7 +17,7 @@ #define SYSCALL_NR_DUP2 33 #define SYSCALL_NR_GETCWD 79 #define SYSCALL_NR_CHDIR 80 -#define SYSCALL_NR_MKDIR 83 +#define SYSCALL_NR_MKDIRAT 83 #define SYSCALL_NR_RMDIR 84 #define SYSCALL_NR_CREAT 85 #define SYSCALL_NR_UNLINK 87 diff --git a/sys/sys_file.c b/sys/sys_file.c index 104a55a..c094f5f 100644 --- a/sys/sys_file.c +++ b/sys/sys_file.c @@ -80,10 +80,17 @@ int sys_creat(const char *pathname, int mode) { return -EINVAL; } -int sys_mkdir(const char *pathname, int mode) { +int sys_mkdirat(int dfd, const char *pathname, int mode) { userptr_check(pathname); _assert(pathname); - return vfs_mkdir(get_ioctx(), pathname, mode); + struct vnode *at; + int res; + + if ((res = get_at_vnode(dfd, &at, 0)) != 0) { + return res; + } + + return vfs_mkdirat(get_ioctx(), at, pathname, mode); } int sys_unlink(const char *pathname) {