mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-28 21:28:21 +00:00
syscalls: linkat
This commit is contained in:
@@ -3,10 +3,41 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <arch/context.h>
|
||||
#include <kernel/vfs.h>
|
||||
#include <kernel/file.h>
|
||||
#include <kernel/scheduler.h>
|
||||
|
||||
typedef struct {
|
||||
uint64_t ret;
|
||||
uint64_t errno;
|
||||
} syscallret_t;
|
||||
|
||||
static inline int dirfd_enter(char *path, int dirfd, file_t **file, vnode_t **dirnode) {
|
||||
if (*path == '/') {
|
||||
*dirnode = sched_getroot();
|
||||
} else if (dirfd == AT_FDCWD) {
|
||||
*dirnode = sched_getcwd();
|
||||
} else {
|
||||
*file = fd_get(dirfd);
|
||||
if (file == NULL) {
|
||||
return EBADF;
|
||||
}
|
||||
|
||||
*dirnode = (*file)->vnode;
|
||||
|
||||
if ((*dirnode)->type != V_TYPE_DIR) {
|
||||
fd_release(*file);
|
||||
return ENOTDIR;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void dirfd_leave(vnode_t *dirnode, file_t *file) {
|
||||
if (file)
|
||||
fd_release(file);
|
||||
else
|
||||
VOP_RELEASE(dirnode);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user