From 0a0d739e98327e5244106931d1fbe1e7a796e35b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 29 Apr 2019 04:55:54 +0200 Subject: Kernel: Make FIFO inherit from File. --- Kernel/FileSystem/FIFO.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'Kernel/FileSystem/FIFO.cpp') diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp index b229c75b76..1bc4a550ac 100644 --- a/Kernel/FileSystem/FIFO.cpp +++ b/Kernel/FileSystem/FIFO.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -27,6 +28,14 @@ Retained FIFO::create(uid_t uid) return adopt(*new FIFO(uid)); } +Retained FIFO::open_direction(FIFO::Direction direction) +{ + auto descriptor = FileDescriptor::create(this); + attach(direction); + descriptor->set_fifo_direction({ }, direction); + return descriptor; +} + FIFO::FIFO(uid_t uid) : m_uid(uid) { @@ -40,7 +49,7 @@ FIFO::~FIFO() all_fifos().resource().remove(this); } -void FIFO::open(Direction direction) +void FIFO::attach(Direction direction) { if (direction == Reader) { ++m_readers; @@ -55,7 +64,7 @@ void FIFO::open(Direction direction) } } -void FIFO::close(Direction direction) +void FIFO::detach(Direction direction) { if (direction == Reader) { #ifdef FIFO_DEBUG @@ -72,17 +81,17 @@ void FIFO::close(Direction direction) } } -bool FIFO::can_read() const +bool FIFO::can_read(Process&) const { return !m_buffer.is_empty() || !m_writers; } -bool FIFO::can_write() const +bool FIFO::can_write(Process&) const { return m_buffer.bytes_in_write_buffer() < 4096; } -ssize_t FIFO::read(byte* buffer, ssize_t size) +ssize_t FIFO::read(Process&, byte* buffer, ssize_t size) { if (!m_writers && m_buffer.is_empty()) return 0; @@ -96,7 +105,7 @@ ssize_t FIFO::read(byte* buffer, ssize_t size) return nread; } -ssize_t FIFO::write(const byte* buffer, ssize_t size) +ssize_t FIFO::write(Process&, const byte* buffer, ssize_t size) { if (!m_readers) return 0; @@ -105,3 +114,8 @@ ssize_t FIFO::write(const byte* buffer, ssize_t size) #endif return m_buffer.write(buffer, size); } + +String FIFO::absolute_path() const +{ + return String::format("fifo:%u", this); +} -- cgit v1.2.3