kernel+libc: Add O_NONBLOCK
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-19 11:25:14 +01:00
parent 41514d9ad2
commit 51f0bdff0e
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 14 additions and 2 deletions

View File

@ -21,7 +21,12 @@ Result<u64> sys_read(Registers*, SyscallArgs args)
if (!descriptor.is_readable()) return err(EBADF); if (!descriptor.is_readable()) return err(EBADF);
while (descriptor.inode->blocking()) { kernel_sleep(10); } while (descriptor.inode->blocking())
{
if (descriptor.should_block()) kernel_sleep(10);
else
return err(EAGAIN);
}
usize nread = TRY(descriptor.inode->read(buf, descriptor.offset, size)); usize nread = TRY(descriptor.inode->read(buf, descriptor.offset, size));

View File

@ -7,7 +7,7 @@
#include <bits/open-flags.h> #include <bits/open-flags.h>
// These flags are needed after open(), the rest only affect open(). // These flags are needed after open(), the rest only affect open().
constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND; constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND | O_NONBLOCK;
Result<u64> sys_open(Registers*, SyscallArgs args) Result<u64> sys_open(Registers*, SyscallArgs args)
{ {

View File

@ -50,6 +50,11 @@ bool FileDescriptor::should_append()
return flags & O_APPEND; return flags & O_APPEND;
} }
bool FileDescriptor::should_block()
{
return flags & O_NONBLOCK;
}
bool FileDescriptor::is_readable() bool FileDescriptor::is_readable()
{ {
return flags & O_RDONLY; return flags & O_RDONLY;

View File

@ -29,6 +29,7 @@ struct FileDescriptor
int flags { 0 }; int flags { 0 };
bool should_append(); bool should_append();
bool should_block();
bool is_writable(); bool is_writable();
bool is_readable(); bool is_readable();
}; };

View File

@ -10,5 +10,6 @@
#define O_CREAT 8 #define O_CREAT 8
#define O_EXCL 16 #define O_EXCL 16
#define O_TRUNC 32 #define O_TRUNC 32
#define O_NONBLOCK 64
#endif #endif