diff --git a/sortix/descriptor.cpp b/sortix/descriptor.cpp index aac0a154..db916848 100644 --- a/sortix/descriptor.cpp +++ b/sortix/descriptor.cpp @@ -31,7 +31,6 @@ #include #include #include -#include // DEBUG #include #include #include @@ -50,7 +49,7 @@ const int ACCESS_FLAGS = O_READ | O_WRITE | O_EXEC | O_SEARCH; const int OPEN_FLAGS = O_CREAT | O_DIRECTORY | O_EXCL | O_TRUNC; // Flags that only make sense for descriptors. -const int DESCRIPTOR_FLAGS = O_APPEND; +const int DESCRIPTOR_FLAGS = O_APPEND | O_NONBLOCK; bool LinkInodeInDir(ioctx_t* ctx, Ref dir, const char* name, Ref inode) @@ -218,6 +217,7 @@ ssize_t Descriptor::read(ioctx_t* ctx, uint8_t* buf, size_t count) return errno = EPERM, -1; if ( !count ) { return 0; } if ( (size_t) SSIZE_MAX < count ) { count = SSIZE_MAX; } + ctx->dflags = dflags; if ( !IsSeekable() ) return vnode->read(ctx, buf, count); // TODO: Locking here only allows one task to read/write at once. @@ -235,6 +235,7 @@ ssize_t Descriptor::pread(ioctx_t* ctx, uint8_t* buf, size_t count, off_t off) if ( off < 0 ) { errno = EINVAL; return -1; } if ( !count ) { return 0; } if ( SSIZE_MAX < count ) { count = SSIZE_MAX; } + ctx->dflags = dflags; return vnode->pread(ctx, buf, count, off); } @@ -244,6 +245,7 @@ ssize_t Descriptor::write(ioctx_t* ctx, const uint8_t* buf, size_t count) return errno = EPERM, -1; if ( !count ) { return 0; } if ( SSIZE_MAX < count ) { count = SSIZE_MAX; } + ctx->dflags = dflags; if ( !IsSeekable() ) return vnode->write(ctx, buf, count); // TODO: Locking here only allows one task to read/write at once. @@ -265,6 +267,7 @@ ssize_t Descriptor::pwrite(ioctx_t* ctx, const uint8_t* buf, size_t count, off_t if ( off < 0 ) { errno = EINVAL; return -1; } if ( !count ) { return 0; } if ( SSIZE_MAX < count ) { count = SSIZE_MAX; } + ctx->dflags = dflags; return vnode->pwrite(ctx, buf, count, off); } diff --git a/sortix/include/sortix/fcntl.h b/sortix/include/sortix/fcntl.h index 50b4722d..b28baa2c 100644 --- a/sortix/include/sortix/fcntl.h +++ b/sortix/include/sortix/fcntl.h @@ -22,8 +22,8 @@ *******************************************************************************/ -#ifndef SORTIX_FCNTL_H -#define SORTIX_FCNTL_H +#ifndef INCLUDE_SORTIX_FCNTL_H +#define INCLUDE_SORTIX_FCNTL_H #include @@ -42,6 +42,7 @@ __BEGIN_DECLS #define O_TRUNC (1<<8) #define O_CLOFORK (1<<9) #define O_SEARCH (1<<10) +#define O_NONBLOCK (1<<11) // TODO: O_NOFOLLOW. #define FD_CLOEXEC (1<<0) diff --git a/sortix/include/sortix/kernel/ioctx.h b/sortix/include/sortix/kernel/ioctx.h index e3fd03a5..45fc160a 100644 --- a/sortix/include/sortix/kernel/ioctx.h +++ b/sortix/include/sortix/kernel/ioctx.h @@ -37,6 +37,7 @@ struct ioctx_struct gid_t gid, auth_gid; bool (*copy_to_dest)(void* dest, const void* src, size_t n); bool (*copy_from_src)(void* dest, const void* src, size_t n); + int dflags; }; typedef struct ioctx_struct ioctx_t; diff --git a/sortix/ioctx.cpp b/sortix/ioctx.cpp index 92691f97..3d1e5751 100644 --- a/sortix/ioctx.cpp +++ b/sortix/ioctx.cpp @@ -38,6 +38,7 @@ void SetupUserIOCtx(ioctx_t* ctx) ctx->gid = ctx->auth_gid = process->gid; ctx->copy_to_dest = CopyToUser; ctx->copy_from_src = CopyFromUser; + ctx->dflags = 0; } void SetupKernelIOCtx(ioctx_t* ctx) @@ -48,6 +49,7 @@ void SetupKernelIOCtx(ioctx_t* ctx) ctx->gid = ctx->auth_gid = process->gid; ctx->copy_to_dest = CopyToKernel; ctx->copy_from_src = CopyFromKernel; + ctx->dflags = 0; } } // namespace Sortix