mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: make the *at syscalls use the dirfd_enter and dirfd_leave functions
This commit is contained in:
@@ -23,24 +23,9 @@ syscallret_t syscall_faccessat(context_t *, int dirfd, const char *upath, int mo
|
||||
|
||||
vnode_t *dirnode = NULL;
|
||||
file_t *file = NULL;
|
||||
if (*path == '/') {
|
||||
dirnode = sched_getroot();
|
||||
} else if (dirfd == AT_FDCWD) {
|
||||
dirnode = sched_getcwd();
|
||||
} else {
|
||||
file = fd_get(dirfd);
|
||||
if (file == NULL) {
|
||||
ret.errno = EBADF;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dirnode = file->vnode;
|
||||
|
||||
if (dirnode->type != V_TYPE_DIR) {
|
||||
ret.errno = ENOTDIR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
vnode_t *node = NULL;
|
||||
ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0);
|
||||
@@ -54,10 +39,8 @@ syscallret_t syscall_faccessat(context_t *, int dirfd, const char *upath, int mo
|
||||
if (node)
|
||||
VOP_RELEASE(node);
|
||||
|
||||
if (file)
|
||||
fd_release(file);
|
||||
else
|
||||
VOP_RELEASE(dirnode);
|
||||
if (dirnode)
|
||||
dirfd_leave(dirnode, file);
|
||||
|
||||
free(path);
|
||||
|
||||
|
||||
@@ -21,24 +21,9 @@ syscallret_t syscall_mkdirat(context_t *, int dirfd, const char *upath, mode_t m
|
||||
|
||||
vnode_t *dirnode = NULL;
|
||||
file_t *file = NULL;
|
||||
if (*path == '/') {
|
||||
dirnode = sched_getroot();
|
||||
} else if (dirfd == AT_FDCWD) {
|
||||
dirnode = sched_getcwd();
|
||||
} else {
|
||||
file = fd_get(dirfd);
|
||||
if (file == NULL) {
|
||||
ret.errno = EBADF;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dirnode = file->vnode;
|
||||
|
||||
if (dirnode->type != V_TYPE_DIR) {
|
||||
ret.errno = ENOTDIR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
vattr_t attr = {
|
||||
.mode = mode,
|
||||
@@ -51,10 +36,8 @@ syscallret_t syscall_mkdirat(context_t *, int dirfd, const char *upath, mode_t m
|
||||
|
||||
cleanup:
|
||||
|
||||
if (file)
|
||||
fd_release(file);
|
||||
else
|
||||
VOP_RELEASE(dirnode);
|
||||
if (dirnode)
|
||||
dirfd_leave(dirnode, file);
|
||||
|
||||
free(path);
|
||||
|
||||
|
||||
@@ -15,31 +15,13 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
|
||||
++flags;
|
||||
|
||||
vnode_t *dirnode = NULL;
|
||||
file_t *dirfile;
|
||||
file_t *dirfile = NULL;
|
||||
|
||||
size_t pathsize = strlen(path); // TODO u_strlen
|
||||
char *pathbuf = alloc(pathsize + 1);
|
||||
strcpy(pathbuf, path); // TODO u_strcpy
|
||||
|
||||
if (*pathbuf == '/') {
|
||||
dirnode = sched_getroot();
|
||||
dirfile = NULL;
|
||||
} else if (dirfd == AT_FDCWD) {
|
||||
dirnode = sched_getcwd();
|
||||
dirfile = NULL;
|
||||
} else {
|
||||
dirfile = fd_get(dirfd);
|
||||
if (dirfile == NULL) {
|
||||
ret.errno = EBADF;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dirnode = dirfile->vnode;
|
||||
if (dirnode->type != V_TYPE_DIR) {
|
||||
ret.errno = ENOTDIR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
ret.errno = dirfd_enter(pathbuf, dirfd, &dirfile, &dirnode);
|
||||
|
||||
// TODO pass CLOEXEC to fd
|
||||
file_t *newfile = NULL;
|
||||
@@ -96,11 +78,8 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
|
||||
if (pathbuf)
|
||||
free(pathbuf);
|
||||
|
||||
if (dirfile) {
|
||||
fd_release(dirfile);
|
||||
} else if (dirnode){
|
||||
VOP_RELEASE(dirnode);
|
||||
}
|
||||
if (dirnode)
|
||||
dirfd_leave(dirnode, dirfile);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ syscallret_t syscall_readlinkat(context_t *, int dirfd, const char *upath, char
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
char *path = alloc(strlen(upath + 1));
|
||||
|
||||
char *path = alloc(strlen(upath) + 1);
|
||||
if (path == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
return ret;
|
||||
|
||||
@@ -68,24 +68,9 @@ syscallret_t syscall_fstatat(context_t *ctx, int dirfd, char *upath, stat_t *ust
|
||||
|
||||
vnode_t *dirnode = NULL;
|
||||
file_t *file = NULL;
|
||||
if (*path == '/') {
|
||||
dirnode = sched_getroot();
|
||||
} else if (dirfd == AT_FDCWD) {
|
||||
dirnode = sched_getcwd();
|
||||
} else {
|
||||
file = fd_get(dirfd);
|
||||
if (file == NULL) {
|
||||
ret.errno = EBADF;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dirnode = file->vnode;
|
||||
|
||||
if (dirnode->type != V_TYPE_DIR) {
|
||||
ret.errno = ENOTDIR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
vnode_t *node = NULL;
|
||||
ret.errno = vfs_lookup(&node, dirnode, path, NULL, flags & AT_SYMLINK_NOFOLLOW ? VFS_LOOKUP_NOLINK : 0);
|
||||
@@ -105,10 +90,8 @@ syscallret_t syscall_fstatat(context_t *ctx, int dirfd, char *upath, stat_t *ust
|
||||
if (node)
|
||||
VOP_RELEASE(node);
|
||||
|
||||
if (file)
|
||||
fd_release(file);
|
||||
else
|
||||
VOP_RELEASE(dirnode);
|
||||
if (dirnode)
|
||||
dirfd_leave(dirnode, file);
|
||||
|
||||
free(path);
|
||||
|
||||
|
||||
@@ -31,24 +31,9 @@ syscallret_t syscall_unlinkat(context_t *, int dirfd, const char *upath, int fla
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (*path == '/') {
|
||||
dirnode = sched_getroot();
|
||||
} else if (dirfd == AT_FDCWD) {
|
||||
dirnode = sched_getcwd();
|
||||
} else {
|
||||
file = fd_get(dirfd);
|
||||
if (file == NULL) {
|
||||
ret.errno = EBADF;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dirnode = file->vnode;
|
||||
|
||||
if (dirnode->type != V_TYPE_DIR) {
|
||||
ret.errno = ENOTDIR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
|
||||
if (ret.errno)
|
||||
goto cleanup;
|
||||
|
||||
// TODO rmdir flag
|
||||
|
||||
@@ -67,10 +52,8 @@ syscallret_t syscall_unlinkat(context_t *, int dirfd, const char *upath, int fla
|
||||
if (node)
|
||||
VOP_RELEASE(node);
|
||||
|
||||
if (file)
|
||||
fd_release(file);
|
||||
else
|
||||
VOP_RELEASE(dirnode);
|
||||
if (dirnode)
|
||||
dirfd_leave(dirnode, file);
|
||||
|
||||
free(path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user