kernel: Add support for blocking reads

This commit is contained in:
apio 2023-03-19 11:21:50 +01:00
parent cd00e41f59
commit 41514d9ad2
Signed by: apio
GPG Key ID: B8A7D06E42258954
7 changed files with 33 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -11,5 +11,7 @@ class ConsoleDevice : public Device
Result<usize> write(const u8*, usize, usize) override;
bool blocking() const override;
virtual ~ConsoleDevice() = default;
};

View File

@ -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;
};

View File

@ -17,5 +17,10 @@ class NullDevice : public Device
return 0;
}
bool blocking() const override
{
return false;
}
virtual ~NullDevice() = default;
};

View File

@ -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;

View File

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