mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
open syscall: O_EXCL support
This commit is contained in:
@@ -28,6 +28,7 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
|
|||||||
|
|
||||||
ret.errno = dirfd_enter(pathbuf, dirfd, &dirfile, &dirnode);
|
ret.errno = dirfd_enter(pathbuf, dirfd, &dirfile, &dirnode);
|
||||||
|
|
||||||
|
retry_open:
|
||||||
file_t *newfile = NULL;
|
file_t *newfile = NULL;
|
||||||
int newfd;
|
int newfd;
|
||||||
ret.errno = fd_new(flags & O_CLOEXEC, &newfile, &newfd);
|
ret.errno = fd_new(flags & O_CLOEXEC, &newfile, &newfd);
|
||||||
@@ -36,6 +37,10 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
|
|||||||
|
|
||||||
vnode_t *vnode = NULL;
|
vnode_t *vnode = NULL;
|
||||||
ret.errno = vfs_open(dirnode, pathbuf, fileflagstovnodeflags(flags), &vnode);
|
ret.errno = vfs_open(dirnode, pathbuf, fileflagstovnodeflags(flags), &vnode);
|
||||||
|
if (ret.errno == 0 && (flags & O_CREAT) && (flags & O_EXCL)) {
|
||||||
|
ret.errno = EEXIST;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (ret.errno == ENOENT && (flags & O_CREAT)) {
|
if (ret.errno == ENOENT && (flags & O_CREAT)) {
|
||||||
vattr_t attr = {
|
vattr_t attr = {
|
||||||
@@ -45,6 +50,8 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
|
|||||||
};
|
};
|
||||||
|
|
||||||
ret.errno = vfs_create(dirnode, pathbuf, &attr, V_TYPE_REGULAR, &vnode);
|
ret.errno = vfs_create(dirnode, pathbuf, &attr, V_TYPE_REGULAR, &vnode);
|
||||||
|
if (ret.errno == EEXIST && (flags & O_EXCL) == 0)
|
||||||
|
goto retry_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret.errno)
|
if (ret.errno)
|
||||||
|
|||||||
Reference in New Issue
Block a user