From 5e75f5c428d2df43e808067b0e436349da978cd2 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 4 Mar 2012 21:36:40 +0100 Subject: [PATCH] Added fcntl(3) with FD_GET and FD_SET. --- libmaxsi/include/fcntl.h | 5 +---- libmaxsi/io.cpp | 6 ++++++ sortix/fcntl.h | 3 +++ sortix/filesystem.cpp | 16 ++++++++++++++++ sortix/syscallnum.h | 3 ++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/libmaxsi/include/fcntl.h b/libmaxsi/include/fcntl.h index 0208afdc..f225766c 100644 --- a/libmaxsi/include/fcntl.h +++ b/libmaxsi/include/fcntl.h @@ -36,8 +36,6 @@ __BEGIN_DECLS /* TODO: F_* missing here */ -/* TODO: FD_CLOEXEC missing here */ - /* TODO: F_RDLCK, F_UNLCK, F_WRLCK missing here */ /* TODO: AT_FDCWD missing here */ @@ -61,11 +59,10 @@ struct _flock typedef struct _flock flock; -/* TODO: These are not implemented in libmaxsi/sortix yet. */ +int fcntl(int fd, int cmd, ...); int open(const char* path, int oflag, ...); #if defined(__SORTIX_SHOW_UNIMPLEMENTED) int creat(const char* path, mode_t mode); -int fcntl(int fd, int cmd, ...); int openat(int fd, const char* path, int oflag, ...); #endif diff --git a/libmaxsi/io.cpp b/libmaxsi/io.cpp index e3e03223..6de6fdd8 100644 --- a/libmaxsi/io.cpp +++ b/libmaxsi/io.cpp @@ -57,6 +57,7 @@ namespace Maxsi DEFN_SYSCALL2(int, SysFTruncate, SYSCALL_FTRUNCATE, int, off_t); DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*); DEFN_SYSCALL2(int, SysFStat, SYSCALL_FSTAT, int, struct stat*); + DEFN_SYSCALL3(int, SysFCntl, SYSCALL_FCNTL, int, int, unsigned long); size_t Print(const char* string) { @@ -293,6 +294,11 @@ namespace Maxsi return SysFStat(fd, st); } + extern "C" int fcntl(int fd, int cmd, unsigned long arg) + { + return SysFCntl(fd, cmd, arg); + } + // TODO: This is a hacky implementation of a stupid function. char* mktemp(char* templ) { diff --git a/sortix/fcntl.h b/sortix/fcntl.h index b615196f..fab9e3a0 100644 --- a/sortix/fcntl.h +++ b/sortix/fcntl.h @@ -46,6 +46,9 @@ __BEGIN_DECLS #define FD_CLOEXEC (1<<0) #define FD_CLOFORK (1<<1) +#define F_SETFD 0 +#define F_GETFD 1 + __END_DECLS #endif diff --git a/sortix/filesystem.cpp b/sortix/filesystem.cpp index d148b786..e16b2d84 100644 --- a/sortix/filesystem.cpp +++ b/sortix/filesystem.cpp @@ -130,6 +130,21 @@ namespace Sortix return -1; } + int SysFCntl(int fd, int cmd, unsigned long arg) + { + Process* process = CurrentProcess(); + DescriptorTable* descs = &(process->descriptors); + Device* dev = descs->Get(fd); + if ( !dev ) { Error::Set(EBADF); return -1; } + switch ( cmd ) + { + case F_GETFD: return descs->GetFlags(fd); + case F_SETFD: descs->SetFlags(fd, (int) arg); return 0; + } + Error::Set(EINVAL); + return 1; + } + void Init() { Syscall::Register(SYSCALL_OPEN, (void*) SysOpen); @@ -140,6 +155,7 @@ namespace Sortix Syscall::Register(SYSCALL_FTRUNCATE, (void*) SysFTruncate); Syscall::Register(SYSCALL_STAT, (void*) SysStat); Syscall::Register(SYSCALL_FSTAT, (void*) SysFStat); + Syscall::Register(SYSCALL_FCNTL, (void*) SysFCntl); } } diff --git a/sortix/syscallnum.h b/sortix/syscallnum.h index 382d2dc5..a59b8dbf 100644 --- a/sortix/syscallnum.h +++ b/sortix/syscallnum.h @@ -70,7 +70,8 @@ #define SYSCALL_GETTERMMODE 43 #define SYSCALL_STAT 44 #define SYSCALL_FSTAT 45 -#define SYSCALL_MAX_NUM 46 /* index of highest constant + 1 */ +#define SYSCALL_FCNTL 46 +#define SYSCALL_MAX_NUM 47 /* index of highest constant + 1 */ #endif