mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Add O_NONBLOCK.
This commit is contained in:
parent
ed5f14878d
commit
1052f2c47a
4 changed files with 11 additions and 4 deletions
|
@ -31,7 +31,6 @@
|
|||
#include <sortix/kernel/descriptor.h>
|
||||
#include <sortix/kernel/fsfunc.h>
|
||||
#include <sortix/kernel/string.h>
|
||||
#include <sortix/kernel/copy.h> // DEBUG
|
||||
#include <sortix/dirent.h>
|
||||
#include <sortix/fcntl.h>
|
||||
#include <sortix/seek.h>
|
||||
|
@ -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<Descriptor> dir, const char* name,
|
||||
Ref<Inode> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef SORTIX_FCNTL_H
|
||||
#define SORTIX_FCNTL_H
|
||||
#ifndef INCLUDE_SORTIX_FCNTL_H
|
||||
#define INCLUDE_SORTIX_FCNTL_H
|
||||
|
||||
#include <features.h>
|
||||
|
||||
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue