Compare commits
2 Commits
cd00e41f59
...
51f0bdff0e
Author | SHA1 | Date | |
---|---|---|---|
51f0bdff0e | |||
41514d9ad2 |
@ -32,6 +32,8 @@ namespace VFS
|
||||
|
||||
virtual Result<void> truncate(usize size) = 0;
|
||||
|
||||
virtual bool blocking() const = 0;
|
||||
|
||||
// Metadata accessors
|
||||
virtual usize size() = 0;
|
||||
|
||||
@ -73,6 +75,11 @@ namespace VFS
|
||||
return err(ENOTDIR);
|
||||
}
|
||||
|
||||
bool blocking() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
InodeType type() const override
|
||||
{
|
||||
return InodeType::RegularFile;
|
||||
|
@ -17,3 +17,8 @@ Result<usize> ConsoleDevice::write(const u8* buf, usize, usize length)
|
||||
TextConsole::write((const char*)buf, length);
|
||||
return length;
|
||||
}
|
||||
|
||||
bool ConsoleDevice::blocking() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -11,5 +11,7 @@ class ConsoleDevice : public Device
|
||||
|
||||
Result<usize> write(const u8*, usize, usize) override;
|
||||
|
||||
bool blocking() const override;
|
||||
|
||||
virtual ~ConsoleDevice() = default;
|
||||
};
|
||||
|
@ -8,5 +8,7 @@ class Device
|
||||
|
||||
virtual Result<usize> write(const u8* buf, usize offset, usize length) = 0;
|
||||
|
||||
virtual bool blocking() const = 0;
|
||||
|
||||
virtual ~Device() = default;
|
||||
};
|
||||
|
@ -17,5 +17,10 @@ class NullDevice : public Device
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool blocking() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual ~NullDevice() = default;
|
||||
};
|
||||
|
@ -134,6 +134,11 @@ namespace TmpFS
|
||||
return err(EINVAL);
|
||||
}
|
||||
|
||||
bool blocking() const override
|
||||
{
|
||||
return m_device->blocking();
|
||||
}
|
||||
|
||||
usize size() override
|
||||
{
|
||||
return 0;
|
||||
@ -196,6 +201,11 @@ namespace TmpFS
|
||||
return err(EISDIR);
|
||||
}
|
||||
|
||||
bool blocking() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
usize size() override
|
||||
{
|
||||
return 0;
|
||||
|
@ -21,6 +21,13 @@ Result<u64> sys_read(Registers*, SyscallArgs args)
|
||||
|
||||
if (!descriptor.is_readable()) return err(EBADF);
|
||||
|
||||
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));
|
||||
|
||||
descriptor.offset += nread;
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <bits/open-flags.h>
|
||||
|
||||
// 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)
|
||||
{
|
||||
|
@ -50,6 +50,11 @@ bool FileDescriptor::should_append()
|
||||
return flags & O_APPEND;
|
||||
}
|
||||
|
||||
bool FileDescriptor::should_block()
|
||||
{
|
||||
return flags & O_NONBLOCK;
|
||||
}
|
||||
|
||||
bool FileDescriptor::is_readable()
|
||||
{
|
||||
return flags & O_RDONLY;
|
||||
|
@ -29,6 +29,7 @@ struct FileDescriptor
|
||||
int flags { 0 };
|
||||
|
||||
bool should_append();
|
||||
bool should_block();
|
||||
bool is_writable();
|
||||
bool is_readable();
|
||||
};
|
||||
|
@ -10,5 +10,6 @@
|
||||
#define O_CREAT 8
|
||||
#define O_EXCL 16
|
||||
#define O_TRUNC 32
|
||||
#define O_NONBLOCK 64
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user