mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 23:18:21 +00:00
file: fd_(set/get)flags()
This commit is contained in:
@@ -84,6 +84,34 @@ file_t *fd_get(int fd) {
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int fd_setflags(int fd, int flags) {
|
||||||
|
int error = 0;
|
||||||
|
proc_t *proc = _cpu()->thread->proc;
|
||||||
|
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||||
|
|
||||||
|
if (proc->fd[fd].file)
|
||||||
|
proc->fd[fd].flags = flags;
|
||||||
|
else
|
||||||
|
error = EBADF;
|
||||||
|
|
||||||
|
MUTEX_RELEASE(&proc->fdmutex);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fd_getflags(int fd, int *flags) {
|
||||||
|
int error = 0;
|
||||||
|
proc_t *proc = _cpu()->thread->proc;
|
||||||
|
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||||
|
|
||||||
|
if (proc->fd[fd].file)
|
||||||
|
*flags = proc->fd[fd].flags;
|
||||||
|
else
|
||||||
|
error = EBADF;
|
||||||
|
|
||||||
|
MUTEX_RELEASE(&proc->fdmutex);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
void fd_release(file_t *file) {
|
void fd_release(file_t *file) {
|
||||||
FILE_RELEASE(file);
|
FILE_RELEASE(file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ int fd_new(int flags, file_t **file, int *fd);
|
|||||||
int fd_close(int fd);
|
int fd_close(int fd);
|
||||||
int fd_dup(int oldfd, int newfd, bool exact, int flags, int *ret);
|
int fd_dup(int oldfd, int newfd, bool exact, int flags, int *ret);
|
||||||
int fd_clone(proc_t *proc);
|
int fd_clone(proc_t *proc);
|
||||||
|
int fd_setflags(int fd, int flags);
|
||||||
|
int fd_getflags(int fd, int *flags);
|
||||||
|
|
||||||
#define FILE_LOCK(x) MUTEX_ACQUIRE(&(x)->mutex, false)
|
#define FILE_LOCK(x) MUTEX_ACQUIRE(&(x)->mutex, false)
|
||||||
#define FILE_UNLOCK(x) MUTEX_RELEASE(&(x)->mutex)
|
#define FILE_UNLOCK(x) MUTEX_RELEASE(&(x)->mutex)
|
||||||
|
|||||||
@@ -42,9 +42,14 @@ syscallret_t syscall_fcntl(context_t *, int fd, int cmd, uint64_t arg) {
|
|||||||
FILE_UNLOCK(file);
|
FILE_UNLOCK(file);
|
||||||
break;
|
break;
|
||||||
case F_SETFD:
|
case F_SETFD:
|
||||||
case F_GETFD: // TODO implement this
|
ret.errno = fd_setflags(fd, arg);
|
||||||
ret.ret = 0;
|
ret.ret = 0;
|
||||||
break;
|
break;
|
||||||
|
case F_GETFD:
|
||||||
|
int flg;
|
||||||
|
ret.errno = fd_getflags(fd, &flg);
|
||||||
|
ret.ret = flg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
ret.errno = EINVAL;
|
ret.errno = EINVAL;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@@ -52,6 +57,8 @@ syscallret_t syscall_fcntl(context_t *, int fd, int cmd, uint64_t arg) {
|
|||||||
ret.errno = 0;
|
ret.errno = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
ret.ret = ret.errno ? -1 : ret.ret;
|
||||||
|
|
||||||
fd_release(file);
|
fd_release(file);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user