Kernel: Have File virtuals take a FileDescriptor& rather than a Process&.

This will allow us to implement different behaviors depending on the role
of the descriptor a File is being accessed through.
This commit is contained in:
Andreas Kling 2019-04-29 13:58:40 +02:00
parent 3761bc3ed7
commit 8cbb7f101f
Notes: sideshowbarker 2024-07-19 14:32:46 +09:00
39 changed files with 156 additions and 155 deletions

View file

@ -23,19 +23,19 @@ Console::~Console()
{
}
bool Console::can_read(Process&) const
bool Console::can_read(FileDescriptor&) const
{
return false;
}
ssize_t Console::read(Process&, byte*, ssize_t)
ssize_t Console::read(FileDescriptor&, byte*, ssize_t)
{
// FIXME: Implement reading from the console.
// Maybe we could use a ring buffer for this device?
return 0;
}
ssize_t Console::write(Process&, const byte* data, ssize_t size)
ssize_t Console::write(FileDescriptor&, const byte* data, ssize_t size)
{
if (!size)
return 0;

View file

@ -19,10 +19,10 @@ public:
virtual ~Console() override;
// ^CharacterDevice
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override { return true; }
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual const char* class_name() const override { return "Console"; }
void set_implementation(ConsoleImplementation* implementation) { m_implementation = implementation; }

View file

@ -103,7 +103,7 @@ KResultOr<Region*> BXVGADevice::mmap(Process& process, LinearAddress preferred_l
return region;
}
int BXVGADevice::ioctl(Process& process, unsigned request, unsigned arg)
int BXVGADevice::ioctl(FileDescriptor&, unsigned request, unsigned arg)
{
switch (request) {
case BXVGA_DEV_IOCTL_SET_Y_OFFSET:
@ -113,7 +113,7 @@ int BXVGADevice::ioctl(Process& process, unsigned request, unsigned arg)
return 0;
case BXVGA_DEV_IOCTL_SET_RESOLUTION: {
auto* resolution = (const BXVGAResolution*)arg;
if (!process.validate_read_typed(resolution))
if (!current->process().validate_read_typed(resolution))
return -EFAULT;
set_resolution(resolution->width, resolution->height);
return 0;
@ -123,22 +123,22 @@ int BXVGADevice::ioctl(Process& process, unsigned request, unsigned arg)
};
}
bool BXVGADevice::can_read(Process&) const
bool BXVGADevice::can_read(FileDescriptor&) const
{
ASSERT_NOT_REACHED();
}
bool BXVGADevice::can_write(Process&) const
bool BXVGADevice::can_write(FileDescriptor&) const
{
ASSERT_NOT_REACHED();
}
ssize_t BXVGADevice::read(Process&, byte*, ssize_t)
ssize_t BXVGADevice::read(FileDescriptor&, byte*, ssize_t)
{
ASSERT_NOT_REACHED();
}
ssize_t BXVGADevice::write(Process&, const byte*, ssize_t)
ssize_t BXVGADevice::write(FileDescriptor&, const byte*, ssize_t)
{
ASSERT_NOT_REACHED();
}

View file

@ -17,7 +17,7 @@ public:
void set_resolution(int width, int height);
void set_y_offset(int);
virtual int ioctl(Process&, unsigned request, unsigned arg) override;
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg) override;
virtual KResultOr<Region*> mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t) override;
size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(dword) * 2; }
@ -25,10 +25,10 @@ public:
private:
virtual const char* class_name() const override { return "BXVGA"; }
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override;
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual bool can_write(FileDescriptor&) const override;
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
void set_register(word index, word value);
dword find_framebuffer_address();

View file

@ -19,7 +19,7 @@ DebugLogDevice::~DebugLogDevice()
{
}
ssize_t DebugLogDevice::write(Process&, const byte* data, ssize_t data_size)
ssize_t DebugLogDevice::write(FileDescriptor&, const byte* data, ssize_t data_size)
{
for (int i = 0; i < data_size; ++i)
IO::out8(0xe9, data[i]);

View file

@ -9,9 +9,9 @@ public:
private:
// ^CharacterDevice
virtual ssize_t read(Process&, byte*, ssize_t) override { return 0; }
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_write(Process&) const override { return true; }
virtual bool can_read(Process&) const override { return true; }
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override { return 0; }
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual bool can_read(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "DebugLogDevice"; }
};

View file

@ -12,19 +12,19 @@ FullDevice::~FullDevice()
{
}
bool FullDevice::can_read(Process&) const
bool FullDevice::can_read(FileDescriptor&) const
{
return true;
}
ssize_t FullDevice::read(Process&, byte* buffer, ssize_t size)
ssize_t FullDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
{
ssize_t count = min(PAGE_SIZE, size);
memset(buffer, 0, (size_t)count);
return count;
}
ssize_t FullDevice::write(Process&, const byte*, ssize_t size)
ssize_t FullDevice::write(FileDescriptor&, const byte*, ssize_t size)
{
if (size == 0)
return 0;

View file

@ -10,10 +10,10 @@ public:
private:
// ^CharacterDevice
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override { return true; }
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "FullDevice"; }
};

View file

@ -208,12 +208,12 @@ KeyboardDevice::~KeyboardDevice()
{
}
bool KeyboardDevice::can_read(Process&) const
bool KeyboardDevice::can_read(FileDescriptor&) const
{
return !m_queue.is_empty();
}
ssize_t KeyboardDevice::read(Process&, byte* buffer, ssize_t size)
ssize_t KeyboardDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
{
ssize_t nread = 0;
while (nread < size) {
@ -229,7 +229,7 @@ ssize_t KeyboardDevice::read(Process&, byte* buffer, ssize_t size)
return nread;
}
ssize_t KeyboardDevice::write(Process&, const byte*, ssize_t)
ssize_t KeyboardDevice::write(FileDescriptor&, const byte*, ssize_t)
{
return 0;
}

View file

@ -22,10 +22,10 @@ public:
void set_client(KeyboardClient* client) { m_client = client; }
// ^CharacterDevice
virtual ssize_t read(Process&, byte* buffer, ssize_t) override;
virtual bool can_read(Process&) const override;
virtual ssize_t write(Process&, const byte* buffer, ssize_t) override;
virtual bool can_write(Process&) const override { return true; }
virtual ssize_t read(FileDescriptor&, byte* buffer, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual ssize_t write(FileDescriptor&, const byte* buffer, ssize_t) override;
virtual bool can_write(FileDescriptor&) const override { return true; }
private:
// ^IRQHandler

View file

@ -20,17 +20,17 @@ NullDevice::~NullDevice()
{
}
bool NullDevice::can_read(Process&) const
bool NullDevice::can_read(FileDescriptor&) const
{
return true;
}
ssize_t NullDevice::read(Process&, byte*, ssize_t)
ssize_t NullDevice::read(FileDescriptor&, byte*, ssize_t)
{
return 0;
}
ssize_t NullDevice::write(Process&, const byte*, ssize_t buffer_size)
ssize_t NullDevice::write(FileDescriptor&, const byte*, ssize_t buffer_size)
{
return min(PAGE_SIZE, buffer_size);
}

View file

@ -12,10 +12,10 @@ public:
private:
// ^CharacterDevice
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_write(Process&) const override { return true; }
virtual bool can_read(Process&) const override;
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual bool can_read(FileDescriptor&) const override;
virtual const char* class_name() const override { return "NullDevice"; }
};

View file

@ -160,12 +160,12 @@ byte PS2MouseDevice::mouse_read()
return IO::in8(0x60);
}
bool PS2MouseDevice::can_read(Process&) const
bool PS2MouseDevice::can_read(FileDescriptor&) const
{
return !m_queue.is_empty();
}
ssize_t PS2MouseDevice::read(Process&, byte* buffer, ssize_t size)
ssize_t PS2MouseDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
{
ssize_t nread = 0;
while (nread < size) {
@ -181,7 +181,7 @@ ssize_t PS2MouseDevice::read(Process&, byte* buffer, ssize_t size)
return nread;
}
ssize_t PS2MouseDevice::write(Process&, const byte*, ssize_t)
ssize_t PS2MouseDevice::write(FileDescriptor&, const byte*, ssize_t)
{
return 0;
}

View file

@ -13,10 +13,10 @@ public:
static PS2MouseDevice& the();
// ^CharacterDevice
virtual bool can_read(Process&) const override;
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_write(Process&) const override { return true; }
virtual bool can_read(FileDescriptor&) const override;
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual bool can_write(FileDescriptor&) const override { return true; }
private:
// ^IRQHandler

View file

@ -26,12 +26,12 @@ static void mysrand(unsigned seed)
}
#endif
bool RandomDevice::can_read(Process&) const
bool RandomDevice::can_read(FileDescriptor&) const
{
return true;
}
ssize_t RandomDevice::read(Process&, byte* buffer, ssize_t size)
ssize_t RandomDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
{
const int range = 'z' - 'a';
ssize_t nread = min(size, PAGE_SIZE);
@ -42,7 +42,7 @@ ssize_t RandomDevice::read(Process&, byte* buffer, ssize_t size)
return nread;
}
ssize_t RandomDevice::write(Process&, const byte*, ssize_t size)
ssize_t RandomDevice::write(FileDescriptor&, const byte*, ssize_t size)
{
// FIXME: Use input for entropy? I guess that could be a neat feature?
return min(PAGE_SIZE, size);

View file

@ -12,10 +12,10 @@ public:
private:
// ^CharacterDevice
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override { return true; }
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "RandomDevice"; }
};

View file

@ -11,19 +11,19 @@ ZeroDevice::~ZeroDevice()
{
}
bool ZeroDevice::can_read(Process&) const
bool ZeroDevice::can_read(FileDescriptor&) const
{
return true;
}
ssize_t ZeroDevice::read(Process&, byte* buffer, ssize_t size)
ssize_t ZeroDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
{
ssize_t count = min(PAGE_SIZE, size);
memset(buffer, 0, (size_t)count);
return count;
}
ssize_t ZeroDevice::write(Process&, const byte*, ssize_t size)
ssize_t ZeroDevice::write(FileDescriptor&, const byte*, ssize_t size)
{
return min(PAGE_SIZE, size);
}

View file

@ -10,10 +10,10 @@ public:
private:
// ^CharacterDevice
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override { return true; }
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual const char* class_name() const override { return "ZeroDevice"; }
};

View file

@ -19,7 +19,7 @@ void File::close()
{
}
int File::ioctl(Process&, unsigned, unsigned)
int File::ioctl(FileDescriptor&, unsigned, unsigned)
{
return -ENOTTY;
}

View file

@ -18,12 +18,12 @@ public:
virtual KResultOr<Retained<FileDescriptor>> open(int options);
virtual void close();
virtual bool can_read(Process&) const = 0;
virtual bool can_write(Process&) const = 0;
virtual bool can_read(FileDescriptor&) const = 0;
virtual bool can_write(FileDescriptor&) const = 0;
virtual ssize_t read(Process&, byte*, ssize_t) = 0;
virtual ssize_t write(Process&, const byte*, ssize_t) = 0;
virtual int ioctl(Process&, unsigned request, unsigned arg);
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) = 0;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) = 0;
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg);
virtual KResultOr<Region*> mmap(Process&, LinearAddress preferred_laddr, size_t offset, size_t size);
virtual String absolute_path() const = 0;

View file

@ -81,17 +81,17 @@ void FIFO::detach(Direction direction)
}
}
bool FIFO::can_read(Process&) const
bool FIFO::can_read(FileDescriptor&) const
{
return !m_buffer.is_empty() || !m_writers;
}
bool FIFO::can_write(Process&) const
bool FIFO::can_write(FileDescriptor&) const
{
return m_buffer.bytes_in_write_buffer() < 4096;
}
ssize_t FIFO::read(Process&, byte* buffer, ssize_t size)
ssize_t FIFO::read(FileDescriptor&, byte* buffer, ssize_t size)
{
if (!m_writers && m_buffer.is_empty())
return 0;
@ -105,7 +105,7 @@ ssize_t FIFO::read(Process&, byte* buffer, ssize_t size)
return nread;
}
ssize_t FIFO::write(Process&, const byte* buffer, ssize_t size)
ssize_t FIFO::write(FileDescriptor&, const byte* buffer, ssize_t size)
{
if (!m_readers)
return 0;

View file

@ -26,10 +26,10 @@ public:
private:
// ^File
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual bool can_write(FileDescriptor&) const override;
virtual String absolute_path() const override;
virtual const char* class_name() const override { return "FIFO"; }
virtual bool is_fifo() const override { return true; }

View file

@ -173,10 +173,10 @@ off_t FileDescriptor::seek(off_t offset, int whence)
return m_current_offset;
}
ssize_t FileDescriptor::read(Process& process, byte* buffer, ssize_t count)
ssize_t FileDescriptor::read(byte* buffer, ssize_t count)
{
if (m_file) {
int nread = m_file->read(process, buffer, count);
int nread = m_file->read(*this, buffer, count);
if (!m_file->is_seekable())
m_current_offset += nread;
return nread;
@ -189,10 +189,10 @@ ssize_t FileDescriptor::read(Process& process, byte* buffer, ssize_t count)
return nread;
}
ssize_t FileDescriptor::write(Process& process, const byte* data, ssize_t size)
ssize_t FileDescriptor::write(const byte* data, ssize_t size)
{
if (m_file) {
int nwritten = m_file->write(process, data, size);
int nwritten = m_file->write(*this, data, size);
if (m_file->is_seekable())
m_current_offset += nwritten;
return nwritten;
@ -205,25 +205,25 @@ ssize_t FileDescriptor::write(Process& process, const byte* data, ssize_t size)
return nwritten;
}
bool FileDescriptor::can_write(Process& process)
bool FileDescriptor::can_write()
{
if (m_file)
return m_file->can_write(process);
return m_file->can_write(*this);
if (m_socket)
return m_socket->can_write(m_socket_role);
return true;
}
bool FileDescriptor::can_read(Process& process)
bool FileDescriptor::can_read()
{
if (m_file)
return m_file->can_read(process);
return m_file->can_read(*this);
if (m_socket)
return m_socket->can_read(m_socket_role);
return true;
}
ByteBuffer FileDescriptor::read_entire_file(Process& process)
ByteBuffer FileDescriptor::read_entire_file()
{
// HACK ALERT: (This entire function)
@ -231,7 +231,7 @@ ByteBuffer FileDescriptor::read_entire_file(Process& process)
if (m_file) {
auto buffer = ByteBuffer::create_uninitialized(1024);
ssize_t nread = m_file->read(process, buffer.pointer(), buffer.size());
ssize_t nread = m_file->read(*this, buffer.pointer(), buffer.size());
ASSERT(nread >= 0);
buffer.trim(nread);
return buffer;

View file

@ -30,18 +30,18 @@ public:
int close();
off_t seek(off_t, int whence);
ssize_t read(Process&, byte*, ssize_t);
ssize_t write(Process&, const byte* data, ssize_t);
ssize_t read(byte*, ssize_t);
ssize_t write(const byte* data, ssize_t);
KResult fstat(stat&);
KResult fchmod(mode_t);
bool can_read(Process&);
bool can_write(Process&);
bool can_read();
bool can_write();
ssize_t get_dir_entries(byte* buffer, ssize_t);
ByteBuffer read_entire_file(Process&);
ByteBuffer read_entire_file();
KResultOr<String> absolute_path();

View file

@ -135,7 +135,7 @@ void load_ksyms()
auto result = VFS::the().open("/kernel.map", 0, 0, *VFS::the().root_inode());
ASSERT(!result.is_error());
auto descriptor = result.value();
auto buffer = descriptor->read_entire_file(current->process());
auto buffer = descriptor->read_entire_file();
ASSERT(buffer);
load_ksyms_from_data(buffer);
}

View file

@ -837,14 +837,14 @@ ssize_t Process::sys$write(int fd, const byte* data, ssize_t size)
#ifdef IO_DEBUG
dbgprintf("while %u < %u\n", nwritten, size);
#endif
if (!descriptor->can_write(*this)) {
if (!descriptor->can_write()) {
#ifdef IO_DEBUG
dbgprintf("block write on %d\n", fd);
#endif
current->m_blocked_fd = fd;
current->block(Thread::State::BlockedWrite);
}
ssize_t rc = descriptor->write(*this, (const byte*)data + nwritten, size - nwritten);
ssize_t rc = descriptor->write((const byte*)data + nwritten, size - nwritten);
#ifdef IO_DEBUG
dbgprintf(" -> write returned %d\n", rc);
#endif
@ -863,7 +863,7 @@ ssize_t Process::sys$write(int fd, const byte* data, ssize_t size)
nwritten += rc;
}
} else {
nwritten = descriptor->write(*this, (const byte*)data, size);
nwritten = descriptor->write((const byte*)data, size);
}
if (current->has_unmasked_pending_signals()) {
current->block(Thread::State::BlockedSignal);
@ -888,14 +888,14 @@ ssize_t Process::sys$read(int fd, byte* buffer, ssize_t size)
if (!descriptor)
return -EBADF;
if (descriptor->is_blocking()) {
if (!descriptor->can_read(*this)) {
if (!descriptor->can_read()) {
current->m_blocked_fd = fd;
current->block(Thread::State::BlockedRead);
if (current->m_was_interrupted_while_blocked)
return -EINTR;
}
}
return descriptor->read(*this, buffer, size);
return descriptor->read(buffer, size);
}
int Process::sys$close(int fd)
@ -1014,7 +1014,7 @@ int Process::sys$readlink(const char* path, char* buffer, ssize_t size)
if (!descriptor->metadata().is_symlink())
return -EINVAL;
auto contents = descriptor->read_entire_file(*this);
auto contents = descriptor->read_entire_file();
if (!contents)
return -EIO; // FIXME: Get a more detailed error from VFS.
@ -1540,7 +1540,7 @@ int Process::sys$ioctl(int fd, unsigned request, unsigned arg)
return -EBADF;
if (!descriptor->is_file())
return -ENOTTY;
return descriptor->file()->ioctl(*this, request, arg);
return descriptor->file()->ioctl(*descriptor, request, arg);
}
int Process::sys$getdtablesize()
@ -1755,7 +1755,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
auto* descriptor = file_descriptor(fd);
if (!descriptor)
continue;
if (descriptor->can_read(*this)) {
if (descriptor->can_read()) {
bitmap.set(fd, true);
++markedfds;
}
@ -1769,7 +1769,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
auto* descriptor = file_descriptor(fd);
if (!descriptor)
continue;
if (descriptor->can_write(*this)) {
if (descriptor->can_write()) {
bitmap.set(fd, true);
++markedfds;
}
@ -1807,9 +1807,9 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout)
continue;
}
fds[i].revents = 0;
if (fds[i].events & POLLIN && descriptor->can_read(*this))
if (fds[i].events & POLLIN && descriptor->can_read())
fds[i].revents |= POLLIN;
if (fds[i].events & POLLOUT && descriptor->can_write(*this))
if (fds[i].events & POLLOUT && descriptor->can_write())
fds[i].revents |= POLLOUT;
if (fds[i].revents)

View file

@ -18,7 +18,7 @@ void ProcessTracer::did_syscall(dword function, dword arg1, dword arg2, dword ar
m_calls.enqueue(data);
}
int ProcessTracer::read(Process&, byte* buffer, int buffer_size)
int ProcessTracer::read(FileDescriptor&, byte* buffer, int buffer_size)
{
if (m_calls.is_empty())
return 0;

View file

@ -12,11 +12,11 @@ public:
bool is_dead() const { return m_dead; }
void set_dead() { m_dead = true; }
virtual bool can_read(Process&) const override { return !m_calls.is_empty() || m_dead; }
virtual int read(Process&, byte*, int) override;
virtual bool can_read(FileDescriptor&) const override { return !m_calls.is_empty() || m_dead; }
virtual int read(FileDescriptor&, byte*, int) override;
virtual bool can_write(Process&) const override { return true; }
virtual int write(Process&, const byte*, int) override { return -EIO; }
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual int write(FileDescriptor&, const byte*, int) override { return -EIO; }
virtual String absolute_path() const override;

View file

@ -90,14 +90,14 @@ bool Scheduler::pick_next()
if (thread.state() == Thread::BlockedRead) {
ASSERT(thread.m_blocked_fd != -1);
// FIXME: Block until the amount of data wanted is available.
if (process.m_fds[thread.m_blocked_fd].descriptor->can_read(process))
if (process.m_fds[thread.m_blocked_fd].descriptor->can_read())
thread.unblock();
return IterationDecision::Continue;
}
if (thread.state() == Thread::BlockedWrite) {
ASSERT(thread.m_blocked_fd != -1);
if (process.m_fds[thread.m_blocked_fd].descriptor->can_write(process))
if (process.m_fds[thread.m_blocked_fd].descriptor->can_write())
thread.unblock();
return IterationDecision::Continue;
}
@ -130,13 +130,13 @@ bool Scheduler::pick_next()
}
}
for (int fd : thread.m_select_read_fds) {
if (process.m_fds[fd].descriptor->can_read(process)) {
if (process.m_fds[fd].descriptor->can_read()) {
thread.unblock();
return IterationDecision::Continue;
}
}
for (int fd : thread.m_select_write_fds) {
if (process.m_fds[fd].descriptor->can_write(process)) {
if (process.m_fds[fd].descriptor->can_write()) {
thread.unblock();
return IterationDecision::Continue;
}

View file

@ -73,7 +73,7 @@ String SharedMemory::absolute_path() const
return String::format("shm:%u", this);
}
int SharedMemory::read(Process&, byte* buffer, int buffer_size)
int SharedMemory::read(FileDescriptor&, byte* buffer, int buffer_size)
{
UNUSED_PARAM(buffer);
UNUSED_PARAM(buffer_size);
@ -81,7 +81,7 @@ int SharedMemory::read(Process&, byte* buffer, int buffer_size)
ASSERT_NOT_REACHED();
}
int SharedMemory::write(Process&, const byte* data, int data_size)
int SharedMemory::write(FileDescriptor&, const byte* data, int data_size)
{
UNUSED_PARAM(data);
UNUSED_PARAM(data_size);

View file

@ -24,10 +24,10 @@ public:
private:
// ^File
virtual bool can_read(Process&) const override { return true; }
virtual bool can_write(Process&) const override { return true; }
virtual int read(Process&, byte*, int) override;
virtual int write(Process&, const byte*, int) override;
virtual bool can_read(FileDescriptor&) const override { return true; }
virtual bool can_write(FileDescriptor&) const override { return true; }
virtual int read(FileDescriptor&, byte*, int) override;
virtual int write(FileDescriptor&, const byte*, int) override;
virtual String absolute_path() const override;
virtual const char* class_name() const override { return "SharedMemory"; }
virtual bool is_shared_memory() const override { return true; }

View file

@ -31,14 +31,14 @@ String MasterPTY::pts_name() const
return m_pts_name;
}
ssize_t MasterPTY::read(Process&, byte* buffer, ssize_t size)
ssize_t MasterPTY::read(FileDescriptor&, byte* buffer, ssize_t size)
{
if (!m_slave && m_buffer.is_empty())
return 0;
return m_buffer.read(buffer, size);
}
ssize_t MasterPTY::write(Process&, const byte* buffer, ssize_t size)
ssize_t MasterPTY::write(FileDescriptor&, const byte* buffer, ssize_t size)
{
if (!m_slave)
return -EIO;
@ -46,14 +46,14 @@ ssize_t MasterPTY::write(Process&, const byte* buffer, ssize_t size)
return size;
}
bool MasterPTY::can_read(Process&) const
bool MasterPTY::can_read(FileDescriptor&) const
{
if (!m_slave)
return true;
return !m_buffer.is_empty();
}
bool MasterPTY::can_write(Process&) const
bool MasterPTY::can_write(FileDescriptor&) const
{
return true;
}
@ -96,9 +96,9 @@ void MasterPTY::close()
}
}
int MasterPTY::ioctl(Process& process, unsigned request, unsigned arg)
int MasterPTY::ioctl(FileDescriptor& descriptor, unsigned request, unsigned arg)
{
if (request == TIOCSWINSZ)
return m_slave->ioctl(process, request, arg);
return m_slave->ioctl(descriptor, request, arg);
return -EINVAL;
}

View file

@ -20,13 +20,13 @@ public:
private:
// ^CharacterDevice
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override;
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual bool can_write(FileDescriptor&) const override;
virtual void close() override;
virtual bool is_master_pty() const override { return true; }
virtual int ioctl(Process&, unsigned request, unsigned arg) override;
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg) override;
virtual const char* class_name() const override { return "MasterPTY"; }
RetainPtr<SlavePTY> m_slave;

View file

@ -16,10 +16,10 @@ public:
// ^CharacterDevice
virtual KResultOr<Retained<FileDescriptor>> open(int options) override;
virtual ssize_t read(Process&, byte*, ssize_t) override { return 0; }
virtual ssize_t write(Process&, const byte*, ssize_t) override { return 0; }
virtual bool can_read(Process&) const override { return true; }
virtual bool can_write(Process&) const override { return true; }
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override { return 0; }
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override { return 0; }
virtual bool can_read(FileDescriptor&) const override { return true; }
virtual bool can_write(FileDescriptor&) const override { return true; }
void notify_master_destroyed(Badge<MasterPTY>, unsigned index);

View file

@ -41,23 +41,23 @@ ssize_t SlavePTY::on_tty_write(const byte* data, ssize_t size)
return m_master->on_slave_write(data, size);
}
bool SlavePTY::can_write(Process&) const
bool SlavePTY::can_write(FileDescriptor&) const
{
return m_master->can_write_from_slave();
}
bool SlavePTY::can_read(Process& process) const
bool SlavePTY::can_read(FileDescriptor& descriptor) const
{
if (m_master->is_closed())
return true;
return TTY::can_read(process);
return TTY::can_read(descriptor);
}
ssize_t SlavePTY::read(Process& process, byte* buffer, ssize_t size)
ssize_t SlavePTY::read(FileDescriptor& descriptor, byte* buffer, ssize_t size)
{
if (m_master->is_closed())
return 0;
return TTY::read(process, buffer, size);
return TTY::read(descriptor, buffer, size);
}
void SlavePTY::close()

View file

@ -21,9 +21,9 @@ private:
virtual ssize_t on_tty_write(const byte*, ssize_t) override;
// ^CharacterDevice
virtual bool can_read(Process&) const override;
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual bool can_write(Process&) const override;
virtual bool can_read(FileDescriptor&) const override;
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual bool can_write(FileDescriptor&) const override;
virtual const char* class_name() const override { return "SlavePTY"; }
virtual void close() override;

View file

@ -24,12 +24,12 @@ void TTY::set_default_termios()
memcpy(m_termios.c_cc, default_cc, sizeof(default_cc));
}
ssize_t TTY::read(Process&, byte* buffer, ssize_t size)
ssize_t TTY::read(FileDescriptor&, byte* buffer, ssize_t size)
{
return m_buffer.read(buffer, size);
}
ssize_t TTY::write(Process&, const byte* buffer, ssize_t size)
ssize_t TTY::write(FileDescriptor&, const byte* buffer, ssize_t size)
{
#ifdef TTY_DEBUG
dbgprintf("TTY::write {%u} ", size);
@ -42,12 +42,12 @@ ssize_t TTY::write(Process&, const byte* buffer, ssize_t size)
return size;
}
bool TTY::can_read(Process&) const
bool TTY::can_read(FileDescriptor&) const
{
return !m_buffer.is_empty();
}
bool TTY::can_write(Process&) const
bool TTY::can_write(FileDescriptor&) const
{
return true;
}
@ -106,8 +106,9 @@ void TTY::set_termios(const termios& t)
);
}
int TTY::ioctl(Process& process, unsigned request, unsigned arg)
int TTY::ioctl(FileDescriptor&, unsigned request, unsigned arg)
{
auto& process = current->process();
pid_t pgid;
termios* tp;
winsize* ws;

View file

@ -10,11 +10,11 @@ class TTY : public CharacterDevice {
public:
virtual ~TTY() override;
virtual ssize_t read(Process&, byte*, ssize_t) override;
virtual ssize_t write(Process&, const byte*, ssize_t) override;
virtual bool can_read(Process&) const override;
virtual bool can_write(Process&) const override;
virtual int ioctl(Process&, unsigned request, unsigned arg) override final;
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
virtual bool can_read(FileDescriptor&) const override;
virtual bool can_write(FileDescriptor&) const override;
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg) override final;
virtual String absolute_path() const override { return tty_name(); }
virtual String tty_name() const = 0;

View file

@ -12,7 +12,7 @@ static void console_putch(char*&, char ch)
IO::out8(0xe9, ch);
return;
}
Console::the().write(current->process(), (byte*)&ch, 1);
Console::the().put_char(ch);
}
int kprintf(const char* fmt, ...)