Add mkdirat(2)

This commit is contained in:
Mark
2020-07-26 23:22:16 +03:00
parent 3b1ca6b978
commit 276d77cd7c
6 changed files with 19 additions and 37 deletions
+1 -9
View File
@@ -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,
+6 -2
View File
@@ -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;
}
+1 -5
View File
@@ -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);
+1 -10
View File
@@ -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);
+1 -9
View File
@@ -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
+9 -2
View File
@@ -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) {