mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:58:13 +00:00
Kernel: Rename FileDescriptor to FileDescription.
After reading a bunch of POSIX specs, I've learned that a file descriptor is the number that refers to a file description, not the description itself. So this patch renames FileDescriptor to FileDescription, and Process now has FileDescription* file_description(int fd).
This commit is contained in:
parent
69a6ce90df
commit
08cd75ac4b
70 changed files with 373 additions and 373 deletions
|
@ -23,19 +23,19 @@ Console::~Console()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Console::can_read(FileDescriptor&) const
|
bool Console::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Console::read(FileDescriptor&, byte*, ssize_t)
|
ssize_t Console::read(FileDescription&, byte*, ssize_t)
|
||||||
{
|
{
|
||||||
// FIXME: Implement reading from the console.
|
// FIXME: Implement reading from the console.
|
||||||
// Maybe we could use a ring buffer for this device?
|
// Maybe we could use a ring buffer for this device?
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Console::write(FileDescriptor&, const byte* data, ssize_t size)
|
ssize_t Console::write(FileDescription&, const byte* data, ssize_t size)
|
||||||
{
|
{
|
||||||
if (!size)
|
if (!size)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -19,10 +19,10 @@ public:
|
||||||
virtual ~Console() override;
|
virtual ~Console() override;
|
||||||
|
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual const char* class_name() const override { return "Console"; }
|
virtual const char* class_name() const override { return "Console"; }
|
||||||
|
|
||||||
void set_implementation(ConsoleImplementation* implementation) { m_implementation = implementation; }
|
void set_implementation(ConsoleImplementation* implementation) { m_implementation = implementation; }
|
||||||
|
|
|
@ -84,7 +84,7 @@ dword BXVGADevice::find_framebuffer_address()
|
||||||
return framebuffer_address;
|
return framebuffer_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Region*> BXVGADevice::mmap(Process& process, FileDescriptor&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot)
|
KResultOr<Region*> BXVGADevice::mmap(Process& process, FileDescription&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot)
|
||||||
{
|
{
|
||||||
ASSERT(offset == 0);
|
ASSERT(offset == 0);
|
||||||
ASSERT(size == framebuffer_size_in_bytes());
|
ASSERT(size == framebuffer_size_in_bytes());
|
||||||
|
@ -104,7 +104,7 @@ KResultOr<Region*> BXVGADevice::mmap(Process& process, FileDescriptor&, LinearAd
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BXVGADevice::ioctl(FileDescriptor&, unsigned request, unsigned arg)
|
int BXVGADevice::ioctl(FileDescription&, unsigned request, unsigned arg)
|
||||||
{
|
{
|
||||||
switch (request) {
|
switch (request) {
|
||||||
case BXVGA_DEV_IOCTL_SET_Y_OFFSET:
|
case BXVGA_DEV_IOCTL_SET_Y_OFFSET:
|
||||||
|
@ -124,22 +124,22 @@ int BXVGADevice::ioctl(FileDescriptor&, unsigned request, unsigned arg)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BXVGADevice::can_read(FileDescriptor&) const
|
bool BXVGADevice::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BXVGADevice::can_write(FileDescriptor&) const
|
bool BXVGADevice::can_write(FileDescription&) const
|
||||||
{
|
{
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t BXVGADevice::read(FileDescriptor&, byte*, ssize_t)
|
ssize_t BXVGADevice::read(FileDescription&, byte*, ssize_t)
|
||||||
{
|
{
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t BXVGADevice::write(FileDescriptor&, const byte*, ssize_t)
|
ssize_t BXVGADevice::write(FileDescription&, const byte*, ssize_t)
|
||||||
{
|
{
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,18 +17,18 @@ public:
|
||||||
void set_resolution(int width, int height);
|
void set_resolution(int width, int height);
|
||||||
void set_y_offset(int);
|
void set_y_offset(int);
|
||||||
|
|
||||||
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg) override;
|
virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override;
|
||||||
virtual KResultOr<Region*> mmap(Process&, FileDescriptor&, LinearAddress preferred_laddr, size_t offset, size_t, int prot) override;
|
virtual KResultOr<Region*> mmap(Process&, FileDescription&, LinearAddress preferred_laddr, size_t offset, size_t, int prot) override;
|
||||||
|
|
||||||
size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(dword) * 2; }
|
size_t framebuffer_size_in_bytes() const { return m_framebuffer_size.area() * sizeof(dword) * 2; }
|
||||||
Size framebuffer_size() const { return m_framebuffer_size; }
|
Size framebuffer_size() const { return m_framebuffer_size; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual const char* class_name() const override { return "BXVGA"; }
|
virtual const char* class_name() const override { return "BXVGA"; }
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual bool can_write(FileDescriptor&) const override;
|
virtual bool can_write(FileDescription&) const override;
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
|
|
||||||
void set_register(word index, word value);
|
void set_register(word index, word value);
|
||||||
dword find_framebuffer_address();
|
dword find_framebuffer_address();
|
||||||
|
|
|
@ -19,7 +19,7 @@ DebugLogDevice::~DebugLogDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t DebugLogDevice::write(FileDescriptor&, const byte* data, ssize_t data_size)
|
ssize_t DebugLogDevice::write(FileDescription&, const byte* data, ssize_t data_size)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < data_size; ++i)
|
for (int i = 0; i < data_size; ++i)
|
||||||
IO::out8(0xe9, data[i]);
|
IO::out8(0xe9, data[i]);
|
||||||
|
|
|
@ -9,9 +9,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override { return 0; }
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override { return 0; }
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
virtual bool can_read(FileDescriptor&) const override { return true; }
|
virtual bool can_read(FileDescription&) const override { return true; }
|
||||||
virtual const char* class_name() const override { return "DebugLogDevice"; }
|
virtual const char* class_name() const override { return "DebugLogDevice"; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@ Device::~Device()
|
||||||
VFS::the().unregister_device({}, *this);
|
VFS::the().unregister_device({}, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
String Device::absolute_path(const FileDescriptor&) const
|
String Device::absolute_path(const FileDescription&) const
|
||||||
{
|
{
|
||||||
return String::format("device:%u,%u (%s)", m_major, m_minor, class_name());
|
return String::format("device:%u,%u (%s)", m_major, m_minor, class_name());
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
unsigned major() const { return m_major; }
|
unsigned major() const { return m_major; }
|
||||||
unsigned minor() const { return m_minor; }
|
unsigned minor() const { return m_minor; }
|
||||||
|
|
||||||
virtual String absolute_path(const FileDescriptor&) const override;
|
virtual String absolute_path(const FileDescription&) const override;
|
||||||
|
|
||||||
uid_t uid() const { return m_uid; }
|
uid_t uid() const { return m_uid; }
|
||||||
uid_t gid() const { return m_gid; }
|
uid_t gid() const { return m_gid; }
|
||||||
|
|
|
@ -12,19 +12,19 @@ FullDevice::~FullDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FullDevice::can_read(FileDescriptor&) const
|
bool FullDevice::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FullDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
|
ssize_t FullDevice::read(FileDescription&, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
ssize_t count = min(PAGE_SIZE, size);
|
ssize_t count = min(PAGE_SIZE, size);
|
||||||
memset(buffer, 0, (size_t)count);
|
memset(buffer, 0, (size_t)count);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FullDevice::write(FileDescriptor&, const byte*, ssize_t size)
|
ssize_t FullDevice::write(FileDescription&, const byte*, ssize_t size)
|
||||||
{
|
{
|
||||||
if (size == 0)
|
if (size == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -10,9 +10,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
virtual const char* class_name() const override { return "FullDevice"; }
|
virtual const char* class_name() const override { return "FullDevice"; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -208,12 +208,12 @@ KeyboardDevice::~KeyboardDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool KeyboardDevice::can_read(FileDescriptor&) const
|
bool KeyboardDevice::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return !m_queue.is_empty();
|
return !m_queue.is_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t KeyboardDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
|
ssize_t KeyboardDevice::read(FileDescription&, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
ssize_t nread = 0;
|
ssize_t nread = 0;
|
||||||
while (nread < size) {
|
while (nread < size) {
|
||||||
|
@ -229,7 +229,7 @@ ssize_t KeyboardDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t KeyboardDevice::write(FileDescriptor&, const byte*, ssize_t)
|
ssize_t KeyboardDevice::write(FileDescription&, const byte*, ssize_t)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ public:
|
||||||
void set_client(KeyboardClient* client) { m_client = client; }
|
void set_client(KeyboardClient* client) { m_client = client; }
|
||||||
|
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual ssize_t read(FileDescriptor&, byte* buffer, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte* buffer, ssize_t) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte* buffer, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte* buffer, ssize_t) override;
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^IRQHandler
|
// ^IRQHandler
|
||||||
|
|
|
@ -20,17 +20,17 @@ NullDevice::~NullDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NullDevice::can_read(FileDescriptor&) const
|
bool NullDevice::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t NullDevice::read(FileDescriptor&, byte*, ssize_t)
|
ssize_t NullDevice::read(FileDescription&, byte*, ssize_t)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t NullDevice::write(FileDescriptor&, const byte*, ssize_t buffer_size)
|
ssize_t NullDevice::write(FileDescription&, const byte*, ssize_t buffer_size)
|
||||||
{
|
{
|
||||||
return min(PAGE_SIZE, buffer_size);
|
return min(PAGE_SIZE, buffer_size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual const char* class_name() const override { return "NullDevice"; }
|
virtual const char* class_name() const override { return "NullDevice"; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -218,12 +218,12 @@ byte PS2MouseDevice::mouse_read()
|
||||||
return IO::in8(0x60);
|
return IO::in8(0x60);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PS2MouseDevice::can_read(FileDescriptor&) const
|
bool PS2MouseDevice::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return !m_queue.is_empty();
|
return !m_queue.is_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t PS2MouseDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
|
ssize_t PS2MouseDevice::read(FileDescription&, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
ssize_t nread = 0;
|
ssize_t nread = 0;
|
||||||
while (nread < size) {
|
while (nread < size) {
|
||||||
|
@ -239,7 +239,7 @@ ssize_t PS2MouseDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t PS2MouseDevice::write(FileDescriptor&, const byte*, ssize_t)
|
ssize_t PS2MouseDevice::write(FileDescription&, const byte*, ssize_t)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,10 @@ public:
|
||||||
static PS2MouseDevice& the();
|
static PS2MouseDevice& the();
|
||||||
|
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^IRQHandler
|
// ^IRQHandler
|
||||||
|
|
|
@ -26,12 +26,12 @@ static void mysrand(unsigned seed)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool RandomDevice::can_read(FileDescriptor&) const
|
bool RandomDevice::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t RandomDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
|
ssize_t RandomDevice::read(FileDescription&, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
const int range = 'z' - 'a';
|
const int range = 'z' - 'a';
|
||||||
ssize_t nread = min(size, PAGE_SIZE);
|
ssize_t nread = min(size, PAGE_SIZE);
|
||||||
|
@ -42,7 +42,7 @@ ssize_t RandomDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t RandomDevice::write(FileDescriptor&, const byte*, ssize_t size)
|
ssize_t RandomDevice::write(FileDescription&, const byte*, ssize_t size)
|
||||||
{
|
{
|
||||||
// FIXME: Use input for entropy? I guess that could be a neat feature?
|
// FIXME: Use input for entropy? I guess that could be a neat feature?
|
||||||
return min(PAGE_SIZE, size);
|
return min(PAGE_SIZE, size);
|
||||||
|
|
|
@ -12,9 +12,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
virtual const char* class_name() const override { return "RandomDevice"; }
|
virtual const char* class_name() const override { return "RandomDevice"; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,19 +11,19 @@ ZeroDevice::~ZeroDevice()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZeroDevice::can_read(FileDescriptor&) const
|
bool ZeroDevice::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ZeroDevice::read(FileDescriptor&, byte* buffer, ssize_t size)
|
ssize_t ZeroDevice::read(FileDescription&, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
ssize_t count = min(PAGE_SIZE, size);
|
ssize_t count = min(PAGE_SIZE, size);
|
||||||
memset(buffer, 0, (size_t)count);
|
memset(buffer, 0, (size_t)count);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ZeroDevice::write(FileDescriptor&, const byte*, ssize_t size)
|
ssize_t ZeroDevice::write(FileDescription&, const byte*, ssize_t size)
|
||||||
{
|
{
|
||||||
return min(PAGE_SIZE, size);
|
return min(PAGE_SIZE, size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
virtual const char* class_name() const override { return "ZeroDevice"; }
|
virtual const char* class_name() const override { return "ZeroDevice"; }
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <Kernel/File.h>
|
#include <Kernel/File.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
|
|
||||||
File::File()
|
File::File()
|
||||||
{
|
{
|
||||||
|
@ -9,22 +9,22 @@ File::~File()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Retained<FileDescriptor>> File::open(int options)
|
KResultOr<Retained<FileDescription>> File::open(int options)
|
||||||
{
|
{
|
||||||
UNUSED_PARAM(options);
|
UNUSED_PARAM(options);
|
||||||
return FileDescriptor::create(this);
|
return FileDescription::create(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void File::close()
|
void File::close()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int File::ioctl(FileDescriptor&, unsigned, unsigned)
|
int File::ioctl(FileDescription&, unsigned, unsigned)
|
||||||
{
|
{
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Region*> File::mmap(Process&, FileDescriptor&, LinearAddress, size_t, size_t, int)
|
KResultOr<Region*> File::mmap(Process&, FileDescription&, LinearAddress, size_t, size_t, int)
|
||||||
{
|
{
|
||||||
return KResult(-ENODEV);
|
return KResult(-ENODEV);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
#include <Kernel/LinearAddress.h>
|
#include <Kernel/LinearAddress.h>
|
||||||
#include <Kernel/UnixTypes.h>
|
#include <Kernel/UnixTypes.h>
|
||||||
|
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
class Process;
|
class Process;
|
||||||
class Region;
|
class Region;
|
||||||
|
|
||||||
// File is the base class for anything that can be referenced by a FileDescriptor.
|
// File is the base class for anything that can be referenced by a FileDescription.
|
||||||
//
|
//
|
||||||
// The most important functions in File are:
|
// The most important functions in File are:
|
||||||
//
|
//
|
||||||
|
@ -43,18 +43,18 @@ class File : public Retainable<File> {
|
||||||
public:
|
public:
|
||||||
virtual ~File();
|
virtual ~File();
|
||||||
|
|
||||||
virtual KResultOr<Retained<FileDescriptor>> open(int options);
|
virtual KResultOr<Retained<FileDescription>> open(int options);
|
||||||
virtual void close();
|
virtual void close();
|
||||||
|
|
||||||
virtual bool can_read(FileDescriptor&) const = 0;
|
virtual bool can_read(FileDescription&) const = 0;
|
||||||
virtual bool can_write(FileDescriptor&) const = 0;
|
virtual bool can_write(FileDescription&) const = 0;
|
||||||
|
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) = 0;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) = 0;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) = 0;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) = 0;
|
||||||
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg);
|
virtual int ioctl(FileDescription&, unsigned request, unsigned arg);
|
||||||
virtual KResultOr<Region*> mmap(Process&, FileDescriptor&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot);
|
virtual KResultOr<Region*> mmap(Process&, FileDescription&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot);
|
||||||
|
|
||||||
virtual String absolute_path(const FileDescriptor&) const = 0;
|
virtual String absolute_path(const FileDescription&) const = 0;
|
||||||
|
|
||||||
virtual KResult truncate(off_t) { return KResult(-EINVAL); }
|
virtual KResult truncate(off_t) { return KResult(-EINVAL); }
|
||||||
|
|
||||||
|
|
|
@ -479,7 +479,7 @@ RetainPtr<Inode> Ext2FS::get_inode(InodeIdentifier inode) const
|
||||||
return new_inode;
|
return new_inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor*) const
|
ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription*) const
|
||||||
{
|
{
|
||||||
Locker inode_locker(m_lock);
|
Locker inode_locker(m_lock);
|
||||||
ASSERT(offset >= 0);
|
ASSERT(offset >= 0);
|
||||||
|
@ -585,7 +585,7 @@ bool Ext2FSInode::resize(qword new_size)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data, FileDescriptor*)
|
ssize_t Ext2FSInode::write_bytes(off_t offset, ssize_t count, const byte* data, FileDescription*)
|
||||||
{
|
{
|
||||||
ASSERT(offset >= 0);
|
ASSERT(offset >= 0);
|
||||||
ASSERT(count >= 0);
|
ASSERT(count >= 0);
|
||||||
|
|
|
@ -25,12 +25,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^Inode
|
// ^Inode
|
||||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override;
|
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override;
|
||||||
virtual InodeMetadata metadata() const override;
|
virtual InodeMetadata metadata() const override;
|
||||||
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
||||||
virtual InodeIdentifier lookup(StringView name) override;
|
virtual InodeIdentifier lookup(StringView name) override;
|
||||||
virtual void flush_metadata() override;
|
virtual void flush_metadata() override;
|
||||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescriptor*) override;
|
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescription*) override;
|
||||||
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
||||||
virtual KResult remove_child(const String& name) override;
|
virtual KResult remove_child(const String& name) override;
|
||||||
virtual int set_atime(time_t) override;
|
virtual int set_atime(time_t) override;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <Kernel/FileSystem/FIFO.h>
|
#include <Kernel/FileSystem/FIFO.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/Lock.h>
|
#include <Kernel/Lock.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
#include <Kernel/Thread.h>
|
#include <Kernel/Thread.h>
|
||||||
|
@ -30,9 +30,9 @@ Retained<FIFO> FIFO::create(uid_t uid)
|
||||||
return adopt(*new FIFO(uid));
|
return adopt(*new FIFO(uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
Retained<FileDescriptor> FIFO::open_direction(FIFO::Direction direction)
|
Retained<FileDescription> FIFO::open_direction(FIFO::Direction direction)
|
||||||
{
|
{
|
||||||
auto descriptor = FileDescriptor::create(this);
|
auto descriptor = FileDescription::create(this);
|
||||||
attach(direction);
|
attach(direction);
|
||||||
descriptor->set_fifo_direction({ }, direction);
|
descriptor->set_fifo_direction({ }, direction);
|
||||||
return descriptor;
|
return descriptor;
|
||||||
|
@ -83,17 +83,17 @@ void FIFO::detach(Direction direction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FIFO::can_read(FileDescriptor&) const
|
bool FIFO::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return !m_buffer.is_empty() || !m_writers;
|
return !m_buffer.is_empty() || !m_writers;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FIFO::can_write(FileDescriptor&) const
|
bool FIFO::can_write(FileDescription&) const
|
||||||
{
|
{
|
||||||
return m_buffer.bytes_in_write_buffer() < 4096 || !m_readers;
|
return m_buffer.bytes_in_write_buffer() < 4096 || !m_readers;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FIFO::read(FileDescriptor&, byte* buffer, ssize_t size)
|
ssize_t FIFO::read(FileDescription&, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
if (!m_writers && m_buffer.is_empty())
|
if (!m_writers && m_buffer.is_empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -107,7 +107,7 @@ ssize_t FIFO::read(FileDescriptor&, byte* buffer, ssize_t size)
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FIFO::write(FileDescriptor&, const byte* buffer, ssize_t size)
|
ssize_t FIFO::write(FileDescription&, const byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
if (!m_readers) {
|
if (!m_readers) {
|
||||||
current->process().send_signal(SIGPIPE, ¤t->process());
|
current->process().send_signal(SIGPIPE, ¤t->process());
|
||||||
|
@ -119,7 +119,7 @@ ssize_t FIFO::write(FileDescriptor&, const byte* buffer, ssize_t size)
|
||||||
return m_buffer.write(buffer, size);
|
return m_buffer.write(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
String FIFO::absolute_path(const FileDescriptor&) const
|
String FIFO::absolute_path(const FileDescription&) const
|
||||||
{
|
{
|
||||||
return String::format("fifo:%u", this);
|
return String::format("fifo:%u", this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <Kernel/File.h>
|
#include <Kernel/File.h>
|
||||||
#include <Kernel/UnixTypes.h>
|
#include <Kernel/UnixTypes.h>
|
||||||
|
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
|
|
||||||
class FIFO final : public File {
|
class FIFO final : public File {
|
||||||
public:
|
public:
|
||||||
|
@ -22,18 +22,18 @@ public:
|
||||||
|
|
||||||
uid_t uid() const { return m_uid; }
|
uid_t uid() const { return m_uid; }
|
||||||
|
|
||||||
Retained<FileDescriptor> open_direction(Direction);
|
Retained<FileDescription> open_direction(Direction);
|
||||||
|
|
||||||
void attach(Direction);
|
void attach(Direction);
|
||||||
void detach(Direction);
|
void detach(Direction);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^File
|
// ^File
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual bool can_write(FileDescriptor&) const override;
|
virtual bool can_write(FileDescription&) const override;
|
||||||
virtual String absolute_path(const FileDescriptor&) const override;
|
virtual String absolute_path(const FileDescription&) const override;
|
||||||
virtual const char* class_name() const override { return "FIFO"; }
|
virtual const char* class_name() const override { return "FIFO"; }
|
||||||
virtual bool is_fifo() const override { return true; }
|
virtual bool is_fifo() const override { return true; }
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <Kernel/Devices/CharacterDevice.h>
|
#include <Kernel/Devices/CharacterDevice.h>
|
||||||
#include <Kernel/FileSystem/Custody.h>
|
#include <Kernel/FileSystem/Custody.h>
|
||||||
#include <Kernel/FileSystem/FIFO.h>
|
#include <Kernel/FileSystem/FIFO.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/FileSystem/FileSystem.h>
|
#include <Kernel/FileSystem/FileSystem.h>
|
||||||
#include <Kernel/FileSystem/InodeFile.h>
|
#include <Kernel/FileSystem/InodeFile.h>
|
||||||
#include <Kernel/Net/Socket.h>
|
#include <Kernel/Net/Socket.h>
|
||||||
|
@ -15,19 +15,19 @@
|
||||||
#include <Kernel/VM/MemoryManager.h>
|
#include <Kernel/VM/MemoryManager.h>
|
||||||
#include <LibC/errno_numbers.h>
|
#include <LibC/errno_numbers.h>
|
||||||
|
|
||||||
Retained<FileDescriptor> FileDescriptor::create(RetainPtr<Custody>&& custody)
|
Retained<FileDescription> FileDescription::create(RetainPtr<Custody>&& custody)
|
||||||
{
|
{
|
||||||
auto descriptor = adopt(*new FileDescriptor(InodeFile::create(custody->inode())));
|
auto descriptor = adopt(*new FileDescription(InodeFile::create(custody->inode())));
|
||||||
descriptor->m_custody = move(custody);
|
descriptor->m_custody = move(custody);
|
||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
Retained<FileDescriptor> FileDescriptor::create(RetainPtr<File>&& file, SocketRole role)
|
Retained<FileDescription> FileDescription::create(RetainPtr<File>&& file, SocketRole role)
|
||||||
{
|
{
|
||||||
return adopt(*new FileDescriptor(move(file), role));
|
return adopt(*new FileDescription(move(file), role));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescriptor::FileDescriptor(RetainPtr<File>&& file, SocketRole role)
|
FileDescription::FileDescription(RetainPtr<File>&& file, SocketRole role)
|
||||||
: m_file(move(file))
|
: m_file(move(file))
|
||||||
{
|
{
|
||||||
if (m_file->is_inode())
|
if (m_file->is_inode())
|
||||||
|
@ -35,7 +35,7 @@ FileDescriptor::FileDescriptor(RetainPtr<File>&& file, SocketRole role)
|
||||||
set_socket_role(role);
|
set_socket_role(role);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescriptor::~FileDescriptor()
|
FileDescription::~FileDescription()
|
||||||
{
|
{
|
||||||
if (is_socket())
|
if (is_socket())
|
||||||
socket()->detach(*this);
|
socket()->detach(*this);
|
||||||
|
@ -46,7 +46,7 @@ FileDescriptor::~FileDescriptor()
|
||||||
m_inode = nullptr;
|
m_inode = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDescriptor::set_socket_role(SocketRole role)
|
void FileDescription::set_socket_role(SocketRole role)
|
||||||
{
|
{
|
||||||
if (role == m_socket_role)
|
if (role == m_socket_role)
|
||||||
return;
|
return;
|
||||||
|
@ -58,13 +58,13 @@ void FileDescriptor::set_socket_role(SocketRole role)
|
||||||
socket()->attach(*this);
|
socket()->attach(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Retained<FileDescriptor> FileDescriptor::clone()
|
Retained<FileDescription> FileDescription::clone()
|
||||||
{
|
{
|
||||||
RetainPtr<FileDescriptor> descriptor;
|
RetainPtr<FileDescription> descriptor;
|
||||||
if (is_fifo()) {
|
if (is_fifo()) {
|
||||||
descriptor = fifo()->open_direction(m_fifo_direction);
|
descriptor = fifo()->open_direction(m_fifo_direction);
|
||||||
} else {
|
} else {
|
||||||
descriptor = FileDescriptor::create(m_file.copy_ref(), m_socket_role);
|
descriptor = FileDescription::create(m_file.copy_ref(), m_socket_role);
|
||||||
descriptor->m_custody = m_custody.copy_ref();
|
descriptor->m_custody = m_custody.copy_ref();
|
||||||
descriptor->m_inode = m_inode.copy_ref();
|
descriptor->m_inode = m_inode.copy_ref();
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ Retained<FileDescriptor> FileDescriptor::clone()
|
||||||
return *descriptor;
|
return *descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult FileDescriptor::fstat(stat& buffer)
|
KResult FileDescription::fstat(stat& buffer)
|
||||||
{
|
{
|
||||||
ASSERT(!is_fifo());
|
ASSERT(!is_fifo());
|
||||||
if (!m_inode)
|
if (!m_inode)
|
||||||
|
@ -84,14 +84,14 @@ KResult FileDescriptor::fstat(stat& buffer)
|
||||||
return metadata().stat(buffer);
|
return metadata().stat(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult FileDescriptor::fchmod(mode_t mode)
|
KResult FileDescription::fchmod(mode_t mode)
|
||||||
{
|
{
|
||||||
if (!m_inode)
|
if (!m_inode)
|
||||||
return KResult(-EBADF);
|
return KResult(-EBADF);
|
||||||
return VFS::the().chmod(*m_inode, mode);
|
return VFS::the().chmod(*m_inode, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t FileDescriptor::seek(off_t offset, int whence)
|
off_t FileDescription::seek(off_t offset, int whence)
|
||||||
{
|
{
|
||||||
if (!m_file->is_seekable())
|
if (!m_file->is_seekable())
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -127,7 +127,7 @@ off_t FileDescriptor::seek(off_t offset, int whence)
|
||||||
return m_current_offset;
|
return m_current_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FileDescriptor::read(byte* buffer, ssize_t count)
|
ssize_t FileDescription::read(byte* buffer, ssize_t count)
|
||||||
{
|
{
|
||||||
int nread = m_file->read(*this, buffer, count);
|
int nread = m_file->read(*this, buffer, count);
|
||||||
if (m_file->is_seekable())
|
if (m_file->is_seekable())
|
||||||
|
@ -135,7 +135,7 @@ ssize_t FileDescriptor::read(byte* buffer, ssize_t count)
|
||||||
return nread;
|
return nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FileDescriptor::write(const byte* data, ssize_t size)
|
ssize_t FileDescription::write(const byte* data, ssize_t size)
|
||||||
{
|
{
|
||||||
int nwritten = m_file->write(*this, data, size);
|
int nwritten = m_file->write(*this, data, size);
|
||||||
if (m_file->is_seekable())
|
if (m_file->is_seekable())
|
||||||
|
@ -143,17 +143,17 @@ ssize_t FileDescriptor::write(const byte* data, ssize_t size)
|
||||||
return nwritten;
|
return nwritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::can_write()
|
bool FileDescription::can_write()
|
||||||
{
|
{
|
||||||
return m_file->can_write(*this);
|
return m_file->can_write(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::can_read()
|
bool FileDescription::can_read()
|
||||||
{
|
{
|
||||||
return m_file->can_read(*this);
|
return m_file->can_read(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer FileDescriptor::read_entire_file()
|
ByteBuffer FileDescription::read_entire_file()
|
||||||
{
|
{
|
||||||
// HACK ALERT: (This entire function)
|
// HACK ALERT: (This entire function)
|
||||||
ASSERT(m_file->is_inode());
|
ASSERT(m_file->is_inode());
|
||||||
|
@ -161,13 +161,13 @@ ByteBuffer FileDescriptor::read_entire_file()
|
||||||
return m_inode->read_entire(this);
|
return m_inode->read_entire(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::is_directory() const
|
bool FileDescription::is_directory() const
|
||||||
{
|
{
|
||||||
ASSERT(!is_fifo());
|
ASSERT(!is_fifo());
|
||||||
return metadata().is_directory();
|
return metadata().is_directory();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FileDescriptor::get_dir_entries(byte* buffer, ssize_t size)
|
ssize_t FileDescription::get_dir_entries(byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
auto metadata = this->metadata();
|
auto metadata = this->metadata();
|
||||||
if (!metadata.is_valid())
|
if (!metadata.is_valid())
|
||||||
|
@ -195,137 +195,137 @@ ssize_t FileDescriptor::get_dir_entries(byte* buffer, ssize_t size)
|
||||||
return stream.offset();
|
return stream.offset();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::is_device() const
|
bool FileDescription::is_device() const
|
||||||
{
|
{
|
||||||
return m_file->is_device();
|
return m_file->is_device();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::is_tty() const
|
bool FileDescription::is_tty() const
|
||||||
{
|
{
|
||||||
return m_file->is_tty();
|
return m_file->is_tty();
|
||||||
}
|
}
|
||||||
|
|
||||||
const TTY* FileDescriptor::tty() const
|
const TTY* FileDescription::tty() const
|
||||||
{
|
{
|
||||||
if (!is_tty())
|
if (!is_tty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<const TTY*>(m_file.ptr());
|
return static_cast<const TTY*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
TTY* FileDescriptor::tty()
|
TTY* FileDescription::tty()
|
||||||
{
|
{
|
||||||
if (!is_tty())
|
if (!is_tty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<TTY*>(m_file.ptr());
|
return static_cast<TTY*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::is_master_pty() const
|
bool FileDescription::is_master_pty() const
|
||||||
{
|
{
|
||||||
return m_file->is_master_pty();
|
return m_file->is_master_pty();
|
||||||
}
|
}
|
||||||
|
|
||||||
const MasterPTY* FileDescriptor::master_pty() const
|
const MasterPTY* FileDescription::master_pty() const
|
||||||
{
|
{
|
||||||
if (!is_master_pty())
|
if (!is_master_pty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<const MasterPTY*>(m_file.ptr());
|
return static_cast<const MasterPTY*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
MasterPTY* FileDescriptor::master_pty()
|
MasterPTY* FileDescription::master_pty()
|
||||||
{
|
{
|
||||||
if (!is_master_pty())
|
if (!is_master_pty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<MasterPTY*>(m_file.ptr());
|
return static_cast<MasterPTY*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileDescriptor::close()
|
int FileDescription::close()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
String FileDescriptor::absolute_path() const
|
String FileDescription::absolute_path() const
|
||||||
{
|
{
|
||||||
if (m_custody)
|
if (m_custody)
|
||||||
return m_custody->absolute_path();
|
return m_custody->absolute_path();
|
||||||
dbgprintf("FileDescriptor::absolute_path() for FD without custody, File type: %s\n", m_file->class_name());
|
dbgprintf("FileDescription::absolute_path() for FD without custody, File type: %s\n", m_file->class_name());
|
||||||
return m_file->absolute_path(*this);
|
return m_file->absolute_path(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
InodeMetadata FileDescriptor::metadata() const
|
InodeMetadata FileDescription::metadata() const
|
||||||
{
|
{
|
||||||
if (m_inode)
|
if (m_inode)
|
||||||
return m_inode->metadata();
|
return m_inode->metadata();
|
||||||
return { };
|
return { };
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Region*> FileDescriptor::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot)
|
KResultOr<Region*> FileDescription::mmap(Process& process, LinearAddress laddr, size_t offset, size_t size, int prot)
|
||||||
{
|
{
|
||||||
return m_file->mmap(process, *this, laddr, offset, size, prot);
|
return m_file->mmap(process, *this, laddr, offset, size, prot);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult FileDescriptor::truncate(off_t length)
|
KResult FileDescription::truncate(off_t length)
|
||||||
{
|
{
|
||||||
return m_file->truncate(length);
|
return m_file->truncate(length);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::is_shared_memory() const
|
bool FileDescription::is_shared_memory() const
|
||||||
{
|
{
|
||||||
return m_file->is_shared_memory();
|
return m_file->is_shared_memory();
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedMemory* FileDescriptor::shared_memory()
|
SharedMemory* FileDescription::shared_memory()
|
||||||
{
|
{
|
||||||
if (!is_shared_memory())
|
if (!is_shared_memory())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<SharedMemory*>(m_file.ptr());
|
return static_cast<SharedMemory*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
const SharedMemory* FileDescriptor::shared_memory() const
|
const SharedMemory* FileDescription::shared_memory() const
|
||||||
{
|
{
|
||||||
if (!is_shared_memory())
|
if (!is_shared_memory())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<const SharedMemory*>(m_file.ptr());
|
return static_cast<const SharedMemory*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::is_fifo() const
|
bool FileDescription::is_fifo() const
|
||||||
{
|
{
|
||||||
return m_file->is_fifo();
|
return m_file->is_fifo();
|
||||||
}
|
}
|
||||||
|
|
||||||
FIFO* FileDescriptor::fifo()
|
FIFO* FileDescription::fifo()
|
||||||
{
|
{
|
||||||
if (!is_fifo())
|
if (!is_fifo())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<FIFO*>(m_file.ptr());
|
return static_cast<FIFO*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileDescriptor::is_socket() const
|
bool FileDescription::is_socket() const
|
||||||
{
|
{
|
||||||
return m_file->is_socket();
|
return m_file->is_socket();
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket* FileDescriptor::socket()
|
Socket* FileDescription::socket()
|
||||||
{
|
{
|
||||||
if (!is_socket())
|
if (!is_socket())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<Socket*>(m_file.ptr());
|
return static_cast<Socket*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
const Socket* FileDescriptor::socket() const
|
const Socket* FileDescription::socket() const
|
||||||
{
|
{
|
||||||
if (!is_socket())
|
if (!is_socket())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return static_cast<const Socket*>(m_file.ptr());
|
return static_cast<const Socket*>(m_file.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDescriptor::set_file_flags(dword flags)
|
void FileDescription::set_file_flags(dword flags)
|
||||||
{
|
{
|
||||||
m_is_blocking = !(flags & O_NONBLOCK);
|
m_is_blocking = !(flags & O_NONBLOCK);
|
||||||
m_should_append = flags & O_APPEND;
|
m_should_append = flags & O_APPEND;
|
||||||
m_file_flags = flags;
|
m_file_flags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult FileDescriptor::chown(uid_t uid, gid_t gid)
|
KResult FileDescription::chown(uid_t uid, gid_t gid)
|
||||||
{
|
{
|
||||||
if (!m_inode)
|
if (!m_inode)
|
||||||
return KResult(-EINVAL);
|
return KResult(-EINVAL);
|
|
@ -19,13 +19,13 @@ class Region;
|
||||||
class CharacterDevice;
|
class CharacterDevice;
|
||||||
class SharedMemory;
|
class SharedMemory;
|
||||||
|
|
||||||
class FileDescriptor : public Retainable<FileDescriptor> {
|
class FileDescription : public Retainable<FileDescription> {
|
||||||
public:
|
public:
|
||||||
static Retained<FileDescriptor> create(RetainPtr<Custody>&&);
|
static Retained<FileDescription> create(RetainPtr<Custody>&&);
|
||||||
static Retained<FileDescriptor> create(RetainPtr<File>&&, SocketRole = SocketRole::None);
|
static Retained<FileDescription> create(RetainPtr<File>&&, SocketRole = SocketRole::None);
|
||||||
~FileDescriptor();
|
~FileDescription();
|
||||||
|
|
||||||
Retained<FileDescriptor> clone();
|
Retained<FileDescription> clone();
|
||||||
|
|
||||||
int close();
|
int close();
|
||||||
|
|
||||||
|
@ -105,8 +105,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class VFS;
|
friend class VFS;
|
||||||
FileDescriptor(RetainPtr<File>&&, SocketRole = SocketRole::None);
|
FileDescription(RetainPtr<File>&&, SocketRole = SocketRole::None);
|
||||||
FileDescriptor(FIFO&, FIFO::Direction);
|
FileDescription(FIFO&, FIFO::Direction);
|
||||||
|
|
||||||
RetainPtr<Custody> m_custody;
|
RetainPtr<Custody> m_custody;
|
||||||
RetainPtr<Inode> m_inode;
|
RetainPtr<Inode> m_inode;
|
|
@ -19,7 +19,7 @@
|
||||||
static const dword mepoch = 476763780;
|
static const dword mepoch = 476763780;
|
||||||
|
|
||||||
class Inode;
|
class Inode;
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
class LocalSocket;
|
class LocalSocket;
|
||||||
class VMObject;
|
class VMObject;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ void Inode::sync()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuffer Inode::read_entire(FileDescriptor* descriptor) const
|
ByteBuffer Inode::read_entire(FileDescription* descriptor) const
|
||||||
{
|
{
|
||||||
size_t initial_size = metadata().size ? metadata().size : 4096;
|
size_t initial_size = metadata().size ? metadata().size : 4096;
|
||||||
StringBuilder builder(initial_size);
|
StringBuilder builder(initial_size);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include <Kernel/KResult.h>
|
#include <Kernel/KResult.h>
|
||||||
#include <Kernel/Lock.h>
|
#include <Kernel/Lock.h>
|
||||||
|
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
class LocalSocket;
|
class LocalSocket;
|
||||||
class VMObject;
|
class VMObject;
|
||||||
|
|
||||||
|
@ -37,12 +37,12 @@ public:
|
||||||
InodeIdentifier identifier() const { return { fsid(), index() }; }
|
InodeIdentifier identifier() const { return { fsid(), index() }; }
|
||||||
virtual InodeMetadata metadata() const = 0;
|
virtual InodeMetadata metadata() const = 0;
|
||||||
|
|
||||||
ByteBuffer read_entire(FileDescriptor* = nullptr) const;
|
ByteBuffer read_entire(FileDescription* = nullptr) const;
|
||||||
|
|
||||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const = 0;
|
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const = 0;
|
||||||
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const = 0;
|
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const = 0;
|
||||||
virtual InodeIdentifier lookup(StringView name) = 0;
|
virtual InodeIdentifier lookup(StringView name) = 0;
|
||||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescriptor*) = 0;
|
virtual ssize_t write_bytes(off_t, ssize_t, const byte* data, FileDescription*) = 0;
|
||||||
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) = 0;
|
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) = 0;
|
||||||
virtual KResult remove_child(const String& name) = 0;
|
virtual KResult remove_child(const String& name) = 0;
|
||||||
virtual size_t directory_entry_count() const = 0;
|
virtual size_t directory_entry_count() const = 0;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include <Kernel/FileSystem/InodeFile.h>
|
#include <Kernel/FileSystem/InodeFile.h>
|
||||||
#include <Kernel/FileSystem/Inode.h>
|
#include <Kernel/FileSystem/Inode.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
|
|
||||||
|
@ -13,17 +13,17 @@ InodeFile::~InodeFile()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t InodeFile::read(FileDescriptor& descriptor, byte* buffer, ssize_t count)
|
ssize_t InodeFile::read(FileDescription& descriptor, byte* buffer, ssize_t count)
|
||||||
{
|
{
|
||||||
return m_inode->read_bytes(descriptor.offset(), count, buffer, &descriptor);
|
return m_inode->read_bytes(descriptor.offset(), count, buffer, &descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t InodeFile::write(FileDescriptor& descriptor, const byte* data, ssize_t count)
|
ssize_t InodeFile::write(FileDescription& descriptor, const byte* data, ssize_t count)
|
||||||
{
|
{
|
||||||
return m_inode->write_bytes(descriptor.offset(), count, data, &descriptor);
|
return m_inode->write_bytes(descriptor.offset(), count, data, &descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescriptor& descriptor, LinearAddress preferred_laddr, size_t offset, size_t size, int prot)
|
KResultOr<Region*> InodeFile::mmap(Process& process, FileDescription& descriptor, LinearAddress preferred_laddr, size_t offset, size_t size, int prot)
|
||||||
{
|
{
|
||||||
ASSERT(offset == 0);
|
ASSERT(offset == 0);
|
||||||
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
|
// FIXME: If PROT_EXEC, check that the underlying file system isn't mounted noexec.
|
||||||
|
@ -34,7 +34,7 @@ KResultOr<Region*> InodeFile::mmap(Process& process, FileDescriptor& descriptor,
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
String InodeFile::absolute_path(const FileDescriptor& descriptor) const
|
String InodeFile::absolute_path(const FileDescription& descriptor) const
|
||||||
{
|
{
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
ASSERT(descriptor.custody());
|
ASSERT(descriptor.custody());
|
||||||
|
|
|
@ -16,14 +16,14 @@ public:
|
||||||
const Inode& inode() const { return *m_inode; }
|
const Inode& inode() const { return *m_inode; }
|
||||||
Inode& inode() { return *m_inode; }
|
Inode& inode() { return *m_inode; }
|
||||||
|
|
||||||
virtual bool can_read(FileDescriptor&) const override { return true; }
|
virtual bool can_read(FileDescription&) const override { return true; }
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
|
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual KResultOr<Region*> mmap(Process&, FileDescriptor&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot) override;
|
virtual KResultOr<Region*> mmap(Process&, FileDescription&, LinearAddress preferred_laddr, size_t offset, size_t size, int prot) override;
|
||||||
|
|
||||||
virtual String absolute_path(const FileDescriptor&) const override;
|
virtual String absolute_path(const FileDescription&) const override;
|
||||||
|
|
||||||
virtual KResult truncate(off_t) override;
|
virtual KResult truncate(off_t) override;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "ProcFS.h"
|
#include "ProcFS.h"
|
||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include <Kernel/FileSystem/Custody.h>
|
#include <Kernel/FileSystem/Custody.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||||
#include <Kernel/VM/MemoryManager.h>
|
#include <Kernel/VM/MemoryManager.h>
|
||||||
#include "StdLib.h"
|
#include "StdLib.h"
|
||||||
|
@ -189,7 +189,7 @@ ByteBuffer procfs$pid_fds(InodeIdentifier identifier)
|
||||||
return { };
|
return { };
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
||||||
auto* descriptor = process.file_descriptor(i);
|
auto* descriptor = process.file_description(i);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
continue;
|
continue;
|
||||||
builder.appendf("% 3u %s\n", i, descriptor->absolute_path().characters());
|
builder.appendf("% 3u %s\n", i, descriptor->absolute_path().characters());
|
||||||
|
@ -204,7 +204,7 @@ ByteBuffer procfs$pid_fd_entry(InodeIdentifier identifier)
|
||||||
return { };
|
return { };
|
||||||
auto& process = handle->process();
|
auto& process = handle->process();
|
||||||
int fd = to_fd(identifier);
|
int fd = to_fd(identifier);
|
||||||
auto* descriptor = process.file_descriptor(fd);
|
auto* descriptor = process.file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return { };
|
return { };
|
||||||
return descriptor->absolute_path().to_byte_buffer();
|
return descriptor->absolute_path().to_byte_buffer();
|
||||||
|
@ -835,7 +835,7 @@ InodeMetadata ProcFSInode::metadata() const
|
||||||
return metadata;
|
return metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor* descriptor) const
|
ssize_t ProcFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* descriptor) const
|
||||||
{
|
{
|
||||||
#ifdef PROCFS_DEBUG
|
#ifdef PROCFS_DEBUG
|
||||||
dbgprintf("ProcFS: read_bytes %u\n", index());
|
dbgprintf("ProcFS: read_bytes %u\n", index());
|
||||||
|
@ -941,7 +941,7 @@ bool ProcFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)
|
||||||
return false;
|
return false;
|
||||||
auto& process = handle->process();
|
auto& process = handle->process();
|
||||||
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
for (int i = 0; i < process.max_open_file_descriptors(); ++i) {
|
||||||
auto* descriptor = process.file_descriptor(i);
|
auto* descriptor = process.file_description(i);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
continue;
|
continue;
|
||||||
char name[16];
|
char name[16];
|
||||||
|
@ -1027,7 +1027,7 @@ InodeIdentifier ProcFSInode::lookup(StringView name)
|
||||||
{
|
{
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
if (auto* process = Process::from_pid(to_pid(identifier())))
|
if (auto* process = Process::from_pid(to_pid(identifier())))
|
||||||
fd_exists = process->file_descriptor(name_as_number);
|
fd_exists = process->file_description(name_as_number);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (fd_exists)
|
if (fd_exists)
|
||||||
|
@ -1041,7 +1041,7 @@ void ProcFSInode::flush_metadata()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescriptor*)
|
ssize_t ProcFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescription*)
|
||||||
{
|
{
|
||||||
auto* directory_entry = fs().get_directory_entry(identifier());
|
auto* directory_entry = fs().get_directory_entry(identifier());
|
||||||
if (!directory_entry || !directory_entry->write_callback)
|
if (!directory_entry || !directory_entry->write_callback)
|
||||||
|
|
|
@ -80,12 +80,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^Inode
|
// ^Inode
|
||||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override;
|
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override;
|
||||||
virtual InodeMetadata metadata() const override;
|
virtual InodeMetadata metadata() const override;
|
||||||
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
||||||
virtual InodeIdentifier lookup(StringView name) override;
|
virtual InodeIdentifier lookup(StringView name) override;
|
||||||
virtual void flush_metadata() override;
|
virtual void flush_metadata() override;
|
||||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescriptor*) override;
|
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescription*) override;
|
||||||
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
||||||
virtual KResult remove_child(const String& name) override;
|
virtual KResult remove_child(const String& name) override;
|
||||||
virtual size_t directory_entry_count() const override;
|
virtual size_t directory_entry_count() const override;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include <Kernel/FileSystem/SyntheticFileSystem.h>
|
#include <Kernel/FileSystem/SyntheticFileSystem.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <LibC/errno_numbers.h>
|
#include <LibC/errno_numbers.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
|
|
||||||
|
@ -185,7 +185,7 @@ InodeMetadata SynthFSInode::metadata() const
|
||||||
return m_metadata;
|
return m_metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescriptor* descriptor) const
|
ssize_t SynthFSInode::read_bytes(off_t offset, ssize_t count, byte* buffer, FileDescription* descriptor) const
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
#ifdef SYNTHFS_DEBUG
|
#ifdef SYNTHFS_DEBUG
|
||||||
|
@ -250,7 +250,7 @@ void SynthFSInode::flush_metadata()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescriptor*)
|
ssize_t SynthFSInode::write_bytes(off_t offset, ssize_t size, const byte* buffer, FileDescription*)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
if (!m_write_callback)
|
if (!m_write_callback)
|
||||||
|
|
|
@ -57,12 +57,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^Inode
|
// ^Inode
|
||||||
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescriptor*) const override;
|
virtual ssize_t read_bytes(off_t, ssize_t, byte* buffer, FileDescription*) const override;
|
||||||
virtual InodeMetadata metadata() const override;
|
virtual InodeMetadata metadata() const override;
|
||||||
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
virtual bool traverse_as_directory(Function<bool(const FS::DirectoryEntry&)>) const override;
|
||||||
virtual InodeIdentifier lookup(StringView name) override;
|
virtual InodeIdentifier lookup(StringView name) override;
|
||||||
virtual void flush_metadata() override;
|
virtual void flush_metadata() override;
|
||||||
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescriptor*) override;
|
virtual ssize_t write_bytes(off_t, ssize_t, const byte* buffer, FileDescription*) override;
|
||||||
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
virtual KResult add_child(InodeIdentifier child_id, const String& name, mode_t) override;
|
||||||
virtual KResult remove_child(const String& name) override;
|
virtual KResult remove_child(const String& name) override;
|
||||||
virtual size_t directory_entry_count() const override;
|
virtual size_t directory_entry_count() const override;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "VirtualFileSystem.h"
|
#include "VirtualFileSystem.h"
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include <AK/FileSystemPath.h>
|
#include <AK/FileSystemPath.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
@ -149,7 +149,7 @@ KResult VFS::stat(StringView path, int options, Custody& base, struct stat& stat
|
||||||
return custody_or_error.value()->inode().metadata().stat(statbuf);
|
return custody_or_error.value()->inode().metadata().stat(statbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Retained<FileDescriptor>> VFS::open(StringView path, int options, mode_t mode, Custody& base)
|
KResultOr<Retained<FileDescription>> VFS::open(StringView path, int options, mode_t mode, Custody& base)
|
||||||
{
|
{
|
||||||
auto custody_or_error = resolve_path(path, base, nullptr, options);
|
auto custody_or_error = resolve_path(path, base, nullptr, options);
|
||||||
if (options & O_CREAT) {
|
if (options & O_CREAT) {
|
||||||
|
@ -194,7 +194,7 @@ KResultOr<Retained<FileDescriptor>> VFS::open(StringView path, int options, mode
|
||||||
}
|
}
|
||||||
if (should_truncate_file)
|
if (should_truncate_file)
|
||||||
inode.truncate(0);
|
inode.truncate(0);
|
||||||
return FileDescriptor::create(custody);
|
return FileDescription::create(custody);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
|
KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
|
||||||
|
@ -224,7 +224,7 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Retained<FileDescriptor>> VFS::create(StringView path, int options, mode_t mode, Custody& base)
|
KResultOr<Retained<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& base)
|
||||||
{
|
{
|
||||||
(void)options;
|
(void)options;
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ KResultOr<Retained<FileDescriptor>> VFS::create(StringView path, int options, mo
|
||||||
return KResult(error);
|
return KResult(error);
|
||||||
|
|
||||||
auto new_custody = Custody::create(parent_custody, p.basename(), *new_file);
|
auto new_custody = Custody::create(parent_custody, p.basename(), *new_file);
|
||||||
return FileDescriptor::create(*new_custody);
|
return FileDescription::create(*new_custody);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
|
KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
class Custody;
|
class Custody;
|
||||||
class Device;
|
class Device;
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
|
|
||||||
class VFS {
|
class VFS {
|
||||||
AK_MAKE_ETERNAL
|
AK_MAKE_ETERNAL
|
||||||
|
@ -59,9 +59,9 @@ public:
|
||||||
bool mount_root(Retained<FS>&&);
|
bool mount_root(Retained<FS>&&);
|
||||||
bool mount(Retained<FS>&&, StringView path);
|
bool mount(Retained<FS>&&, StringView path);
|
||||||
|
|
||||||
KResultOr<Retained<FileDescriptor>> open(RetainPtr<Device>&&, int options);
|
KResultOr<Retained<FileDescription>> open(RetainPtr<Device>&&, int options);
|
||||||
KResultOr<Retained<FileDescriptor>> open(StringView path, int options, mode_t mode, Custody& base);
|
KResultOr<Retained<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base);
|
||||||
KResultOr<Retained<FileDescriptor>> create(StringView path, int options, mode_t mode, Custody& base);
|
KResultOr<Retained<FileDescription>> create(StringView path, int options, mode_t mode, Custody& base);
|
||||||
KResult mkdir(StringView path, mode_t mode, Custody& base);
|
KResult mkdir(StringView path, mode_t mode, Custody& base);
|
||||||
KResult link(StringView old_path, StringView new_path, Custody& base);
|
KResult link(StringView old_path, StringView new_path, Custody& base);
|
||||||
KResult unlink(StringView path, Custody& base);
|
KResult unlink(StringView path, Custody& base);
|
||||||
|
@ -94,7 +94,7 @@ public:
|
||||||
KResultOr<Retained<Custody>> resolve_path(StringView path, Custody& base, RetainPtr<Custody>* parent = nullptr, int options = 0);
|
KResultOr<Retained<Custody>> resolve_path(StringView path, Custody& base, RetainPtr<Custody>* parent = nullptr, int options = 0);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class FileDescriptor;
|
friend class FileDescription;
|
||||||
|
|
||||||
RetainPtr<Inode> get_inode(InodeIdentifier);
|
RetainPtr<Inode> get_inode(InodeIdentifier);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include "KSyms.h"
|
#include "KSyms.h"
|
||||||
#include "Process.h"
|
#include "Process.h"
|
||||||
#include "Scheduler.h"
|
#include "Scheduler.h"
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <AK/ELF/ELFLoader.h>
|
#include <AK/ELF/ELFLoader.h>
|
||||||
#include <AK/TemporaryChange.h>
|
#include <AK/TemporaryChange.h>
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ VFS_OBJS = \
|
||||||
FileSystem/DiskBackedFileSystem.o \
|
FileSystem/DiskBackedFileSystem.o \
|
||||||
FileSystem/Ext2FileSystem.o \
|
FileSystem/Ext2FileSystem.o \
|
||||||
FileSystem/VirtualFileSystem.o \
|
FileSystem/VirtualFileSystem.o \
|
||||||
FileSystem/FileDescriptor.o \
|
FileSystem/FileDescription.o \
|
||||||
FileSystem/SyntheticFileSystem.o
|
FileSystem/SyntheticFileSystem.o
|
||||||
|
|
||||||
AK_OBJS = \
|
AK_OBJS = \
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <Kernel/Net/ARP.h>
|
#include <Kernel/Net/ARP.h>
|
||||||
#include <Kernel/Net/Routing.h>
|
#include <Kernel/Net/Routing.h>
|
||||||
#include <LibC/errno_numbers.h>
|
#include <LibC/errno_numbers.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
|
|
||||||
#define IPV4_SOCKET_DEBUG
|
#define IPV4_SOCKET_DEBUG
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ KResult IPv4Socket::bind(const sockaddr* address, socklen_t address_size)
|
||||||
return protocol_bind();
|
return protocol_bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult IPv4Socket::connect(FileDescriptor& descriptor, const sockaddr* address, socklen_t address_size, ShouldBlock should_block)
|
KResult IPv4Socket::connect(FileDescription& descriptor, const sockaddr* address, socklen_t address_size, ShouldBlock should_block)
|
||||||
{
|
{
|
||||||
ASSERT(!m_bound);
|
ASSERT(!m_bound);
|
||||||
if (address_size != sizeof(sockaddr_in))
|
if (address_size != sizeof(sockaddr_in))
|
||||||
|
@ -104,17 +104,17 @@ KResult IPv4Socket::connect(FileDescriptor& descriptor, const sockaddr* address,
|
||||||
return protocol_connect(descriptor, should_block);
|
return protocol_connect(descriptor, should_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPv4Socket::attach(FileDescriptor&)
|
void IPv4Socket::attach(FileDescription&)
|
||||||
{
|
{
|
||||||
++m_attached_fds;
|
++m_attached_fds;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPv4Socket::detach(FileDescriptor&)
|
void IPv4Socket::detach(FileDescription&)
|
||||||
{
|
{
|
||||||
--m_attached_fds;
|
--m_attached_fds;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPv4Socket::can_read(FileDescriptor& descriptor) const
|
bool IPv4Socket::can_read(FileDescription& descriptor) const
|
||||||
{
|
{
|
||||||
if (descriptor.socket_role() == SocketRole::Listener)
|
if (descriptor.socket_role() == SocketRole::Listener)
|
||||||
return can_accept();
|
return can_accept();
|
||||||
|
@ -123,17 +123,17 @@ bool IPv4Socket::can_read(FileDescriptor& descriptor) const
|
||||||
return m_can_read;
|
return m_can_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t IPv4Socket::read(FileDescriptor& descriptor, byte* buffer, ssize_t size)
|
ssize_t IPv4Socket::read(FileDescription& descriptor, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
return recvfrom(descriptor, buffer, size, 0, nullptr, 0);
|
return recvfrom(descriptor, buffer, size, 0, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t IPv4Socket::write(FileDescriptor& descriptor, const byte* data, ssize_t size)
|
ssize_t IPv4Socket::write(FileDescription& descriptor, const byte* data, ssize_t size)
|
||||||
{
|
{
|
||||||
return sendto(descriptor, data, size, 0, nullptr, 0);
|
return sendto(descriptor, data, size, 0, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPv4Socket::can_write(FileDescriptor&) const
|
bool IPv4Socket::can_write(FileDescription&) const
|
||||||
{
|
{
|
||||||
return is_connected();
|
return is_connected();
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ int IPv4Socket::allocate_local_port_if_needed()
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t IPv4Socket::sendto(FileDescriptor&, const void* data, size_t data_length, int flags, const sockaddr* addr, socklen_t addr_length)
|
ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_length, int flags, const sockaddr* addr, socklen_t addr_length)
|
||||||
{
|
{
|
||||||
(void)flags;
|
(void)flags;
|
||||||
if (addr && addr_length != sizeof(sockaddr_in))
|
if (addr && addr_length != sizeof(sockaddr_in))
|
||||||
|
@ -184,7 +184,7 @@ ssize_t IPv4Socket::sendto(FileDescriptor&, const void* data, size_t data_length
|
||||||
return protocol_send(data, data_length);
|
return protocol_send(data, data_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t IPv4Socket::recvfrom(FileDescriptor& descriptor, void* buffer, size_t buffer_length, int flags, sockaddr* addr, socklen_t* addr_length)
|
ssize_t IPv4Socket::recvfrom(FileDescription& descriptor, void* buffer, size_t buffer_length, int flags, sockaddr* addr, socklen_t* addr_length)
|
||||||
{
|
{
|
||||||
(void)flags;
|
(void)flags;
|
||||||
if (addr_length && *addr_length < sizeof(sockaddr_in))
|
if (addr_length && *addr_length < sizeof(sockaddr_in))
|
||||||
|
|
|
@ -21,17 +21,17 @@ public:
|
||||||
static Lockable<HashTable<IPv4Socket*>>& all_sockets();
|
static Lockable<HashTable<IPv4Socket*>>& all_sockets();
|
||||||
|
|
||||||
virtual KResult bind(const sockaddr*, socklen_t) override;
|
virtual KResult bind(const sockaddr*, socklen_t) override;
|
||||||
virtual KResult connect(FileDescriptor&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
||||||
virtual bool get_local_address(sockaddr*, socklen_t*) override;
|
virtual bool get_local_address(sockaddr*, socklen_t*) override;
|
||||||
virtual bool get_peer_address(sockaddr*, socklen_t*) override;
|
virtual bool get_peer_address(sockaddr*, socklen_t*) override;
|
||||||
virtual void attach(FileDescriptor&) override;
|
virtual void attach(FileDescription&) override;
|
||||||
virtual void detach(FileDescriptor&) override;
|
virtual void detach(FileDescription&) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_write(FileDescriptor&) const override;
|
virtual bool can_write(FileDescription&) const override;
|
||||||
virtual ssize_t sendto(FileDescriptor&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
||||||
virtual ssize_t recvfrom(FileDescriptor&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
||||||
|
|
||||||
void did_receive(const IPv4Address& peer_address, word peer_port, ByteBuffer&&);
|
void did_receive(const IPv4Address& peer_address, word peer_port, ByteBuffer&&);
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ protected:
|
||||||
virtual KResult protocol_bind() { return KSuccess; }
|
virtual KResult protocol_bind() { return KSuccess; }
|
||||||
virtual int protocol_receive(const ByteBuffer&, void*, size_t, int, sockaddr*, socklen_t*) { return -ENOTIMPL; }
|
virtual int protocol_receive(const ByteBuffer&, void*, size_t, int, sockaddr*, socklen_t*) { return -ENOTIMPL; }
|
||||||
virtual int protocol_send(const void*, int) { return -ENOTIMPL; }
|
virtual int protocol_send(const void*, int) { return -ENOTIMPL; }
|
||||||
virtual KResult protocol_connect(FileDescriptor&, ShouldBlock) { return KSuccess; }
|
virtual KResult protocol_connect(FileDescription&, ShouldBlock) { return KSuccess; }
|
||||||
virtual int protocol_allocate_local_port() { return 0; }
|
virtual int protocol_allocate_local_port() { return 0; }
|
||||||
virtual bool protocol_is_disconnected() const { return false; }
|
virtual bool protocol_is_disconnected() const { return false; }
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <Kernel/Net/LocalSocket.h>
|
#include <Kernel/Net/LocalSocket.h>
|
||||||
#include <Kernel/UnixTypes.h>
|
#include <Kernel/UnixTypes.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||||
#include <LibC/errno_numbers.h>
|
#include <LibC/errno_numbers.h>
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ KResult LocalSocket::bind(const sockaddr* address, socklen_t address_size)
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult LocalSocket::connect(FileDescriptor& descriptor, const sockaddr* address, socklen_t address_size, ShouldBlock)
|
KResult LocalSocket::connect(FileDescription& descriptor, const sockaddr* address, socklen_t address_size, ShouldBlock)
|
||||||
{
|
{
|
||||||
ASSERT(!m_bound);
|
ASSERT(!m_bound);
|
||||||
if (address_size != sizeof(sockaddr_un))
|
if (address_size != sizeof(sockaddr_un))
|
||||||
|
@ -106,7 +106,7 @@ KResult LocalSocket::connect(FileDescriptor& descriptor, const sockaddr* address
|
||||||
return current->wait_for_connect(descriptor);
|
return current->wait_for_connect(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalSocket::attach(FileDescriptor& descriptor)
|
void LocalSocket::attach(FileDescription& descriptor)
|
||||||
{
|
{
|
||||||
switch (descriptor.socket_role()) {
|
switch (descriptor.socket_role()) {
|
||||||
case SocketRole::Accepted:
|
case SocketRole::Accepted:
|
||||||
|
@ -123,7 +123,7 @@ void LocalSocket::attach(FileDescriptor& descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalSocket::detach(FileDescriptor& descriptor)
|
void LocalSocket::detach(FileDescription& descriptor)
|
||||||
{
|
{
|
||||||
switch (descriptor.socket_role()) {
|
switch (descriptor.socket_role()) {
|
||||||
case SocketRole::Accepted:
|
case SocketRole::Accepted:
|
||||||
|
@ -143,7 +143,7 @@ void LocalSocket::detach(FileDescriptor& descriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalSocket::can_read(FileDescriptor& descriptor) const
|
bool LocalSocket::can_read(FileDescription& descriptor) const
|
||||||
{
|
{
|
||||||
auto role = descriptor.socket_role();
|
auto role = descriptor.socket_role();
|
||||||
if (role == SocketRole::Listener)
|
if (role == SocketRole::Listener)
|
||||||
|
@ -155,7 +155,7 @@ bool LocalSocket::can_read(FileDescriptor& descriptor) const
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LocalSocket::read(FileDescriptor& descriptor, byte* buffer, ssize_t size)
|
ssize_t LocalSocket::read(FileDescription& descriptor, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
auto role = descriptor.socket_role();
|
auto role = descriptor.socket_role();
|
||||||
if (role == SocketRole::Accepted) {
|
if (role == SocketRole::Accepted) {
|
||||||
|
@ -175,7 +175,7 @@ ssize_t LocalSocket::read(FileDescriptor& descriptor, byte* buffer, ssize_t size
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalSocket::has_attached_peer(const FileDescriptor& descriptor) const
|
bool LocalSocket::has_attached_peer(const FileDescription& descriptor) const
|
||||||
{
|
{
|
||||||
if (descriptor.socket_role() == SocketRole::Accepted)
|
if (descriptor.socket_role() == SocketRole::Accepted)
|
||||||
return m_connected_fds_open || m_connecting_fds_open;
|
return m_connected_fds_open || m_connecting_fds_open;
|
||||||
|
@ -184,7 +184,7 @@ bool LocalSocket::has_attached_peer(const FileDescriptor& descriptor) const
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LocalSocket::write(FileDescriptor& descriptor, const byte* data, ssize_t size)
|
ssize_t LocalSocket::write(FileDescription& descriptor, const byte* data, ssize_t size)
|
||||||
{
|
{
|
||||||
if (!has_attached_peer(descriptor))
|
if (!has_attached_peer(descriptor))
|
||||||
return -EPIPE;
|
return -EPIPE;
|
||||||
|
@ -195,7 +195,7 @@ ssize_t LocalSocket::write(FileDescriptor& descriptor, const byte* data, ssize_t
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LocalSocket::can_write(FileDescriptor& descriptor) const
|
bool LocalSocket::can_write(FileDescription& descriptor) const
|
||||||
{
|
{
|
||||||
if (descriptor.socket_role() == SocketRole::Accepted)
|
if (descriptor.socket_role() == SocketRole::Accepted)
|
||||||
return !has_attached_peer(descriptor) || m_for_client.bytes_in_write_buffer() < 16384;
|
return !has_attached_peer(descriptor) || m_for_client.bytes_in_write_buffer() < 16384;
|
||||||
|
@ -204,12 +204,12 @@ bool LocalSocket::can_write(FileDescriptor& descriptor) const
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LocalSocket::sendto(FileDescriptor& descriptor, const void* data, size_t data_size, int, const sockaddr*, socklen_t)
|
ssize_t LocalSocket::sendto(FileDescription& descriptor, const void* data, size_t data_size, int, const sockaddr*, socklen_t)
|
||||||
{
|
{
|
||||||
return write(descriptor, (const byte*)data, data_size);
|
return write(descriptor, (const byte*)data, data_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t LocalSocket::recvfrom(FileDescriptor& descriptor, void* buffer, size_t buffer_size, int, sockaddr*, socklen_t*)
|
ssize_t LocalSocket::recvfrom(FileDescription& descriptor, void* buffer, size_t buffer_size, int, sockaddr*, socklen_t*)
|
||||||
{
|
{
|
||||||
return read(descriptor, (byte*)buffer, buffer_size);
|
return read(descriptor, (byte*)buffer, buffer_size);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include <Kernel/DoubleBuffer.h>
|
#include <Kernel/DoubleBuffer.h>
|
||||||
#include <Kernel/Net/Socket.h>
|
#include <Kernel/Net/Socket.h>
|
||||||
|
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
|
|
||||||
class LocalSocket final : public Socket {
|
class LocalSocket final : public Socket {
|
||||||
public:
|
public:
|
||||||
|
@ -11,24 +11,24 @@ public:
|
||||||
virtual ~LocalSocket() override;
|
virtual ~LocalSocket() override;
|
||||||
|
|
||||||
virtual KResult bind(const sockaddr*, socklen_t) override;
|
virtual KResult bind(const sockaddr*, socklen_t) override;
|
||||||
virtual KResult connect(FileDescriptor&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock = ShouldBlock::Yes) override;
|
||||||
virtual bool get_local_address(sockaddr*, socklen_t*) override;
|
virtual bool get_local_address(sockaddr*, socklen_t*) override;
|
||||||
virtual bool get_peer_address(sockaddr*, socklen_t*) override;
|
virtual bool get_peer_address(sockaddr*, socklen_t*) override;
|
||||||
virtual void attach(FileDescriptor&) override;
|
virtual void attach(FileDescription&) override;
|
||||||
virtual void detach(FileDescriptor&) override;
|
virtual void detach(FileDescription&) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_write(FileDescriptor&) const override;
|
virtual bool can_write(FileDescription&) const override;
|
||||||
virtual ssize_t sendto(FileDescriptor&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
virtual ssize_t sendto(FileDescription&, const void*, size_t, int, const sockaddr*, socklen_t) override;
|
||||||
virtual ssize_t recvfrom(FileDescriptor&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit LocalSocket(int type);
|
explicit LocalSocket(int type);
|
||||||
virtual bool is_local() const override { return true; }
|
virtual bool is_local() const override { return true; }
|
||||||
bool has_attached_peer(const FileDescriptor&) const;
|
bool has_attached_peer(const FileDescription&) const;
|
||||||
|
|
||||||
RetainPtr<FileDescriptor> m_file;
|
RetainPtr<FileDescription> m_file;
|
||||||
|
|
||||||
bool m_bound { false };
|
bool m_bound { false };
|
||||||
int m_accepted_fds_open { 0 };
|
int m_accepted_fds_open { 0 };
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/Net/Socket.h>
|
#include <Kernel/Net/Socket.h>
|
||||||
#include <Kernel/Net/LocalSocket.h>
|
#include <Kernel/Net/LocalSocket.h>
|
||||||
#include <Kernel/Net/IPv4Socket.h>
|
#include <Kernel/Net/IPv4Socket.h>
|
||||||
|
@ -142,7 +142,7 @@ static const char* to_string(SocketRole role)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String Socket::absolute_path(const FileDescriptor& descriptor) const
|
String Socket::absolute_path(const FileDescription& descriptor) const
|
||||||
{
|
{
|
||||||
return String::format("socket:%x (role: %s)", this, to_string(descriptor.socket_role()));
|
return String::format("socket:%x (role: %s)", this, to_string(descriptor.socket_role()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ enum class ShouldBlock
|
||||||
Yes = 1
|
Yes = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
|
|
||||||
class Socket : public File {
|
class Socket : public File {
|
||||||
public:
|
public:
|
||||||
|
@ -40,15 +40,15 @@ public:
|
||||||
KResult listen(int backlog);
|
KResult listen(int backlog);
|
||||||
|
|
||||||
virtual KResult bind(const sockaddr*, socklen_t) = 0;
|
virtual KResult bind(const sockaddr*, socklen_t) = 0;
|
||||||
virtual KResult connect(FileDescriptor&, const sockaddr*, socklen_t, ShouldBlock) = 0;
|
virtual KResult connect(FileDescription&, const sockaddr*, socklen_t, ShouldBlock) = 0;
|
||||||
virtual bool get_local_address(sockaddr*, socklen_t*) = 0;
|
virtual bool get_local_address(sockaddr*, socklen_t*) = 0;
|
||||||
virtual bool get_peer_address(sockaddr*, socklen_t*) = 0;
|
virtual bool get_peer_address(sockaddr*, socklen_t*) = 0;
|
||||||
virtual bool is_local() const { return false; }
|
virtual bool is_local() const { return false; }
|
||||||
virtual bool is_ipv4() const { return false; }
|
virtual bool is_ipv4() const { return false; }
|
||||||
virtual void attach(FileDescriptor&) = 0;
|
virtual void attach(FileDescription&) = 0;
|
||||||
virtual void detach(FileDescriptor&) = 0;
|
virtual void detach(FileDescription&) = 0;
|
||||||
virtual ssize_t sendto(FileDescriptor&, const void*, size_t, int flags, const sockaddr*, socklen_t) = 0;
|
virtual ssize_t sendto(FileDescription&, const void*, size_t, int flags, const sockaddr*, socklen_t) = 0;
|
||||||
virtual ssize_t recvfrom(FileDescriptor&, void*, size_t, int flags, sockaddr*, socklen_t*) = 0;
|
virtual ssize_t recvfrom(FileDescription&, void*, size_t, int flags, sockaddr*, socklen_t*) = 0;
|
||||||
|
|
||||||
KResult setsockopt(int level, int option, const void*, socklen_t);
|
KResult setsockopt(int level, int option, const void*, socklen_t);
|
||||||
KResult getsockopt(int level, int option, void*, socklen_t*);
|
KResult getsockopt(int level, int option, void*, socklen_t*);
|
||||||
|
@ -62,7 +62,7 @@ public:
|
||||||
|
|
||||||
Lock& lock() { return m_lock; }
|
Lock& lock() { return m_lock; }
|
||||||
|
|
||||||
virtual String absolute_path(const FileDescriptor&) const override;
|
virtual String absolute_path(const FileDescription&) const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Socket(int domain, int type, int protocol);
|
Socket(int domain, int type, int protocol);
|
||||||
|
|
|
@ -148,7 +148,7 @@ NetworkOrdered<word> TCPSocket::compute_tcp_checksum(const IPv4Address& source,
|
||||||
return ~(checksum & 0xffff);
|
return ~(checksum & 0xffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult TCPSocket::protocol_connect(FileDescriptor& descriptor, ShouldBlock should_block)
|
KResult TCPSocket::protocol_connect(FileDescription& descriptor, ShouldBlock should_block)
|
||||||
{
|
{
|
||||||
auto* adapter = adapter_for_route_to(peer_address());
|
auto* adapter = adapter_for_route_to(peer_address());
|
||||||
if (!adapter)
|
if (!adapter)
|
||||||
|
|
|
@ -36,7 +36,7 @@ private:
|
||||||
|
|
||||||
virtual int protocol_receive(const ByteBuffer&, void* buffer, size_t buffer_size, int flags, sockaddr* addr, socklen_t* addr_length) override;
|
virtual int protocol_receive(const ByteBuffer&, void* buffer, size_t buffer_size, int flags, sockaddr* addr, socklen_t* addr_length) override;
|
||||||
virtual int protocol_send(const void*, int) override;
|
virtual int protocol_send(const void*, int) override;
|
||||||
virtual KResult protocol_connect(FileDescriptor&, ShouldBlock) override;
|
virtual KResult protocol_connect(FileDescription&, ShouldBlock) override;
|
||||||
virtual int protocol_allocate_local_port() override;
|
virtual int protocol_allocate_local_port() override;
|
||||||
virtual bool protocol_is_disconnected() const override;
|
virtual bool protocol_is_disconnected() const override;
|
||||||
virtual KResult protocol_bind() override;
|
virtual KResult protocol_bind() override;
|
||||||
|
|
|
@ -18,7 +18,7 @@ private:
|
||||||
|
|
||||||
virtual int protocol_receive(const ByteBuffer&, void* buffer, size_t buffer_size, int flags, sockaddr* addr, socklen_t* addr_length) override;
|
virtual int protocol_receive(const ByteBuffer&, void* buffer, size_t buffer_size, int flags, sockaddr* addr, socklen_t* addr_length) override;
|
||||||
virtual int protocol_send(const void*, int) override;
|
virtual int protocol_send(const void*, int) override;
|
||||||
virtual KResult protocol_connect(FileDescriptor&, ShouldBlock) override { return KSuccess; }
|
virtual KResult protocol_connect(FileDescription&, ShouldBlock) override { return KSuccess; }
|
||||||
virtual int protocol_allocate_local_port() override;
|
virtual int protocol_allocate_local_port() override;
|
||||||
virtual KResult protocol_bind() override;
|
virtual KResult protocol_bind() override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
#include "kmalloc.h"
|
#include "kmalloc.h"
|
||||||
#include "StdLib.h"
|
#include "StdLib.h"
|
||||||
#include "i386.h"
|
#include "i386.h"
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||||
#include <Kernel/Devices/NullDevice.h>
|
#include <Kernel/Devices/NullDevice.h>
|
||||||
#include <Kernel/VM/MemoryManager.h>
|
#include <Kernel/VM/MemoryManager.h>
|
||||||
|
@ -190,7 +190,7 @@ void* Process::sys$mmap(const Syscall::SC_mmap_params* params)
|
||||||
}
|
}
|
||||||
if (offset & ~PAGE_MASK)
|
if (offset & ~PAGE_MASK)
|
||||||
return (void*)-EINVAL;
|
return (void*)-EINVAL;
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return (void*)-EBADF;
|
return (void*)-EBADF;
|
||||||
auto region_or_error = descriptor->mmap(*this, LinearAddress((dword)addr), offset, size, prot);
|
auto region_or_error = descriptor->mmap(*this, LinearAddress((dword)addr), offset, size, prot);
|
||||||
|
@ -765,7 +765,7 @@ Process* Process::from_pid(pid_t pid)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileDescriptor* Process::file_descriptor(int fd)
|
FileDescription* Process::file_description(int fd)
|
||||||
{
|
{
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -774,7 +774,7 @@ FileDescriptor* Process::file_descriptor(int fd)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FileDescriptor* Process::file_descriptor(int fd) const
|
const FileDescription* Process::file_description(int fd) const
|
||||||
{
|
{
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -789,7 +789,7 @@ ssize_t Process::sys$get_dir_entries(int fd, void* buffer, ssize_t size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!validate_write(buffer, size))
|
if (!validate_write(buffer, size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->get_dir_entries((byte*)buffer, size);
|
return descriptor->get_dir_entries((byte*)buffer, size);
|
||||||
|
@ -797,7 +797,7 @@ ssize_t Process::sys$get_dir_entries(int fd, void* buffer, ssize_t size)
|
||||||
|
|
||||||
int Process::sys$lseek(int fd, off_t offset, int whence)
|
int Process::sys$lseek(int fd, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->seek(offset, whence);
|
return descriptor->seek(offset, whence);
|
||||||
|
@ -809,7 +809,7 @@ int Process::sys$ttyname_r(int fd, char* buffer, ssize_t size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!validate_write(buffer, size))
|
if (!validate_write(buffer, size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_tty())
|
if (!descriptor->is_tty())
|
||||||
|
@ -827,7 +827,7 @@ int Process::sys$ptsname_r(int fd, char* buffer, ssize_t size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (!validate_write(buffer, size))
|
if (!validate_write(buffer, size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
auto* master_pty = descriptor->master_pty();
|
auto* master_pty = descriptor->master_pty();
|
||||||
|
@ -850,7 +850,7 @@ ssize_t Process::sys$writev(int fd, const struct iovec* iov, int iov_count)
|
||||||
|
|
||||||
// FIXME: Return EINVAL if sum of iovecs is greater than INT_MAX
|
// FIXME: Return EINVAL if sum of iovecs is greater than INT_MAX
|
||||||
|
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
|
@ -874,7 +874,7 @@ ssize_t Process::sys$writev(int fd, const struct iovec* iov, int iov_count)
|
||||||
return nwritten;
|
return nwritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t Process::do_write(FileDescriptor& descriptor, const byte* data, int data_size)
|
ssize_t Process::do_write(FileDescription& descriptor, const byte* data, int data_size)
|
||||||
{
|
{
|
||||||
ssize_t nwritten = 0;
|
ssize_t nwritten = 0;
|
||||||
if (!descriptor.is_blocking()) {
|
if (!descriptor.is_blocking()) {
|
||||||
|
@ -931,7 +931,7 @@ ssize_t Process::sys$write(int fd, const byte* data, ssize_t size)
|
||||||
#ifdef DEBUG_IO
|
#ifdef DEBUG_IO
|
||||||
dbgprintf("%s(%u): sys$write(%d, %p, %u)\n", name().characters(), pid(), fd, data, size);
|
dbgprintf("%s(%u): sys$write(%d, %p, %u)\n", name().characters(), pid(), fd, data, size);
|
||||||
#endif
|
#endif
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
auto nwritten = do_write(*descriptor, data, size);
|
auto nwritten = do_write(*descriptor, data, size);
|
||||||
|
@ -954,7 +954,7 @@ ssize_t Process::sys$read(int fd, byte* buffer, ssize_t size)
|
||||||
#ifdef DEBUG_IO
|
#ifdef DEBUG_IO
|
||||||
dbgprintf("%s(%u) sys$read(%d, %p, %u)\n", name().characters(), pid(), fd, buffer, size);
|
dbgprintf("%s(%u) sys$read(%d, %p, %u)\n", name().characters(), pid(), fd, buffer, size);
|
||||||
#endif
|
#endif
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (descriptor->is_blocking()) {
|
if (descriptor->is_blocking()) {
|
||||||
|
@ -969,7 +969,7 @@ ssize_t Process::sys$read(int fd, byte* buffer, ssize_t size)
|
||||||
|
|
||||||
int Process::sys$close(int fd)
|
int Process::sys$close(int fd)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
int rc = descriptor->close();
|
int rc = descriptor->close();
|
||||||
|
@ -1009,10 +1009,10 @@ int Process::sys$fcntl(int fd, int cmd, dword arg)
|
||||||
(void) cmd;
|
(void) cmd;
|
||||||
(void) arg;
|
(void) arg;
|
||||||
dbgprintf("sys$fcntl: fd=%d, cmd=%d, arg=%u\n", fd, cmd, arg);
|
dbgprintf("sys$fcntl: fd=%d, cmd=%d, arg=%u\n", fd, cmd, arg);
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
// NOTE: The FD flags are not shared between FileDescriptor objects.
|
// NOTE: The FD flags are not shared between FileDescription objects.
|
||||||
// This means that dup() doesn't copy the FD_CLOEXEC flag!
|
// This means that dup() doesn't copy the FD_CLOEXEC flag!
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case F_DUPFD: {
|
case F_DUPFD: {
|
||||||
|
@ -1045,7 +1045,7 @@ int Process::sys$fstat(int fd, stat* statbuf)
|
||||||
{
|
{
|
||||||
if (!validate_write_typed(statbuf))
|
if (!validate_write_typed(statbuf))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->fstat(*statbuf);
|
return descriptor->fstat(*statbuf);
|
||||||
|
@ -1226,7 +1226,7 @@ int Process::sys$uname(utsname* buf)
|
||||||
|
|
||||||
int Process::sys$isatty(int fd)
|
int Process::sys$isatty(int fd)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_tty())
|
if (!descriptor->is_tty())
|
||||||
|
@ -1607,7 +1607,7 @@ int Process::sys$setpgid(pid_t specified_pid, pid_t specified_pgid)
|
||||||
|
|
||||||
int Process::sys$ioctl(int fd, unsigned request, unsigned arg)
|
int Process::sys$ioctl(int fd, unsigned request, unsigned arg)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->file().ioctl(*descriptor, request, arg);
|
return descriptor->file().ioctl(*descriptor, request, arg);
|
||||||
|
@ -1620,7 +1620,7 @@ int Process::sys$getdtablesize()
|
||||||
|
|
||||||
int Process::sys$dup(int old_fd)
|
int Process::sys$dup(int old_fd)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(old_fd);
|
auto* descriptor = file_description(old_fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
int new_fd = alloc_fd(0);
|
int new_fd = alloc_fd(0);
|
||||||
|
@ -1632,7 +1632,7 @@ int Process::sys$dup(int old_fd)
|
||||||
|
|
||||||
int Process::sys$dup2(int old_fd, int new_fd)
|
int Process::sys$dup2(int old_fd, int new_fd)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(old_fd);
|
auto* descriptor = file_description(old_fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (new_fd < 0 || new_fd >= m_max_open_file_descriptors)
|
if (new_fd < 0 || new_fd >= m_max_open_file_descriptors)
|
||||||
|
@ -1779,7 +1779,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
|
||||||
return 0;
|
return 0;
|
||||||
for (int fd = 0; fd < params->nfds; ++fd) {
|
for (int fd = 0; fd < params->nfds; ++fd) {
|
||||||
if (FD_ISSET(fd, fds)) {
|
if (FD_ISSET(fd, fds)) {
|
||||||
if (!file_descriptor(fd))
|
if (!file_description(fd))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
vector.append(fd);
|
vector.append(fd);
|
||||||
}
|
}
|
||||||
|
@ -1806,7 +1806,7 @@ int Process::sys$select(const Syscall::SC_select_params* params)
|
||||||
return;
|
return;
|
||||||
FD_ZERO(fds);
|
FD_ZERO(fds);
|
||||||
for (int fd : vector) {
|
for (int fd : vector) {
|
||||||
if (auto* descriptor = file_descriptor(fd); descriptor && should_mark(*descriptor)) {
|
if (auto* descriptor = file_description(fd); descriptor && should_mark(*descriptor)) {
|
||||||
FD_SET(fd, fds);
|
FD_SET(fd, fds);
|
||||||
++marked_fd_count;
|
++marked_fd_count;
|
||||||
}
|
}
|
||||||
|
@ -1858,7 +1858,7 @@ int Process::sys$poll(pollfd* fds, int nfds, int timeout)
|
||||||
int fds_with_revents = 0;
|
int fds_with_revents = 0;
|
||||||
|
|
||||||
for (int i = 0; i < nfds; ++i) {
|
for (int i = 0; i < nfds; ++i) {
|
||||||
auto* descriptor = file_descriptor(fds[i].fd);
|
auto* descriptor = file_description(fds[i].fd);
|
||||||
if (!descriptor) {
|
if (!descriptor) {
|
||||||
fds[i].revents = POLLNVAL;
|
fds[i].revents = POLLNVAL;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1934,7 +1934,7 @@ int Process::sys$chmod(const char* pathname, mode_t mode)
|
||||||
|
|
||||||
int Process::sys$fchmod(int fd, mode_t mode)
|
int Process::sys$fchmod(int fd, mode_t mode)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->fchmod(mode);
|
return descriptor->fchmod(mode);
|
||||||
|
@ -1942,7 +1942,7 @@ int Process::sys$fchmod(int fd, mode_t mode)
|
||||||
|
|
||||||
int Process::sys$fchown(int fd, uid_t uid, gid_t gid)
|
int Process::sys$fchown(int fd, uid_t uid, gid_t gid)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
return descriptor->chown(uid, gid);
|
return descriptor->chown(uid, gid);
|
||||||
|
@ -2041,7 +2041,7 @@ int Process::sys$socket(int domain, int type, int protocol)
|
||||||
auto result = Socket::create(domain, type, protocol);
|
auto result = Socket::create(domain, type, protocol);
|
||||||
if (result.is_error())
|
if (result.is_error())
|
||||||
return result.error();
|
return result.error();
|
||||||
auto descriptor = FileDescriptor::create(*result.value());
|
auto descriptor = FileDescription::create(*result.value());
|
||||||
unsigned flags = 0;
|
unsigned flags = 0;
|
||||||
if (type & SOCK_CLOEXEC)
|
if (type & SOCK_CLOEXEC)
|
||||||
flags |= FD_CLOEXEC;
|
flags |= FD_CLOEXEC;
|
||||||
|
@ -2055,7 +2055,7 @@ int Process::sys$bind(int sockfd, const sockaddr* address, socklen_t address_len
|
||||||
{
|
{
|
||||||
if (!validate_read(address, address_length))
|
if (!validate_read(address, address_length))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!descriptor->is_socket())
|
||||||
|
@ -2066,7 +2066,7 @@ int Process::sys$bind(int sockfd, const sockaddr* address, socklen_t address_len
|
||||||
|
|
||||||
int Process::sys$listen(int sockfd, int backlog)
|
int Process::sys$listen(int sockfd, int backlog)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!descriptor->is_socket())
|
||||||
|
@ -2088,7 +2088,7 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a
|
||||||
int accepted_socket_fd = alloc_fd();
|
int accepted_socket_fd = alloc_fd();
|
||||||
if (accepted_socket_fd < 0)
|
if (accepted_socket_fd < 0)
|
||||||
return accepted_socket_fd;
|
return accepted_socket_fd;
|
||||||
auto* accepting_socket_descriptor = file_descriptor(accepting_socket_fd);
|
auto* accepting_socket_descriptor = file_description(accepting_socket_fd);
|
||||||
if (!accepting_socket_descriptor)
|
if (!accepting_socket_descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!accepting_socket_descriptor->is_socket())
|
if (!accepting_socket_descriptor->is_socket())
|
||||||
|
@ -2102,7 +2102,7 @@ int Process::sys$accept(int accepting_socket_fd, sockaddr* address, socklen_t* a
|
||||||
ASSERT(accepted_socket);
|
ASSERT(accepted_socket);
|
||||||
bool success = accepted_socket->get_local_address(address, address_size);
|
bool success = accepted_socket->get_local_address(address, address_size);
|
||||||
ASSERT(success);
|
ASSERT(success);
|
||||||
auto accepted_socket_descriptor = FileDescriptor::create(move(accepted_socket), SocketRole::Accepted);
|
auto accepted_socket_descriptor = FileDescription::create(move(accepted_socket), SocketRole::Accepted);
|
||||||
// NOTE: The accepted socket inherits fd flags from the accepting socket.
|
// NOTE: The accepted socket inherits fd flags from the accepting socket.
|
||||||
// I'm not sure if this matches other systems but it makes sense to me.
|
// I'm not sure if this matches other systems but it makes sense to me.
|
||||||
accepted_socket_descriptor->set_blocking(accepting_socket_descriptor->is_blocking());
|
accepted_socket_descriptor->set_blocking(accepting_socket_descriptor->is_blocking());
|
||||||
|
@ -2117,7 +2117,7 @@ int Process::sys$connect(int sockfd, const sockaddr* address, socklen_t address_
|
||||||
int fd = alloc_fd();
|
int fd = alloc_fd();
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!descriptor->is_socket())
|
||||||
|
@ -2151,7 +2151,7 @@ ssize_t Process::sys$sendto(const Syscall::SC_sendto_params* params)
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (addr && !validate_read(addr, addr_length))
|
if (addr && !validate_read(addr, addr_length))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!descriptor->is_socket())
|
||||||
|
@ -2183,7 +2183,7 @@ ssize_t Process::sys$recvfrom(const Syscall::SC_recvfrom_params* params)
|
||||||
} else if (addr) {
|
} else if (addr) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!descriptor->is_socket())
|
||||||
|
@ -2212,7 +2212,7 @@ int Process::sys$getsockname(int sockfd, sockaddr* addr, socklen_t* addrlen)
|
||||||
if (!validate_write(addr, *addrlen))
|
if (!validate_write(addr, *addrlen))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
|
@ -2237,7 +2237,7 @@ int Process::sys$getpeername(int sockfd, sockaddr* addr, socklen_t* addrlen)
|
||||||
if (!validate_write(addr, *addrlen))
|
if (!validate_write(addr, *addrlen))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
|
@ -2312,7 +2312,7 @@ int Process::sys$getsockopt(const Syscall::SC_getsockopt_params* params)
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
if (!validate_write(value, *value_size))
|
if (!validate_write(value, *value_size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!descriptor->is_socket())
|
||||||
|
@ -2333,7 +2333,7 @@ int Process::sys$setsockopt(const Syscall::SC_setsockopt_params* params)
|
||||||
|
|
||||||
if (!validate_read(value, value_size))
|
if (!validate_read(value, value_size))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
auto* descriptor = file_descriptor(sockfd);
|
auto* descriptor = file_description(sockfd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
if (!descriptor->is_socket())
|
if (!descriptor->is_socket())
|
||||||
|
@ -2672,7 +2672,7 @@ int Process::sys$shm_open(const char* name, int flags, mode_t mode)
|
||||||
auto shm_or_error = SharedMemory::open(String(name), flags, mode);
|
auto shm_or_error = SharedMemory::open(String(name), flags, mode);
|
||||||
if (shm_or_error.is_error())
|
if (shm_or_error.is_error())
|
||||||
return shm_or_error.error();
|
return shm_or_error.error();
|
||||||
auto descriptor = FileDescriptor::create(shm_or_error.value().ptr());
|
auto descriptor = FileDescription::create(shm_or_error.value().ptr());
|
||||||
m_fds[fd].set(move(descriptor), FD_CLOEXEC);
|
m_fds[fd].set(move(descriptor), FD_CLOEXEC);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
@ -2686,7 +2686,7 @@ int Process::sys$shm_unlink(const char* name)
|
||||||
|
|
||||||
int Process::sys$ftruncate(int fd, off_t length)
|
int Process::sys$ftruncate(int fd, off_t length)
|
||||||
{
|
{
|
||||||
auto* descriptor = file_descriptor(fd);
|
auto* descriptor = file_description(fd);
|
||||||
if (!descriptor)
|
if (!descriptor)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
// FIXME: Check that fd is writable, otherwise EINVAL.
|
// FIXME: Check that fd is writable, otherwise EINVAL.
|
||||||
|
@ -2704,7 +2704,7 @@ int Process::sys$systrace(pid_t pid)
|
||||||
int fd = alloc_fd();
|
int fd = alloc_fd();
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return fd;
|
return fd;
|
||||||
auto descriptor = FileDescriptor::create(peer->ensure_tracer());
|
auto descriptor = FileDescription::create(peer->ensure_tracer());
|
||||||
m_fds[fd].set(move(descriptor), 0);
|
m_fds[fd].set(move(descriptor), 0);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
@ -2716,13 +2716,13 @@ ProcessTracer& Process::ensure_tracer()
|
||||||
return *m_tracer;
|
return *m_tracer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::FileDescriptorAndFlags::clear()
|
void Process::FileDescriptionAndFlags::clear()
|
||||||
{
|
{
|
||||||
descriptor = nullptr;
|
descriptor = nullptr;
|
||||||
flags = 0;
|
flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Process::FileDescriptorAndFlags::set(Retained<FileDescriptor>&& d, dword f)
|
void Process::FileDescriptionAndFlags::set(Retained<FileDescription>&& d, dword f)
|
||||||
{
|
{
|
||||||
descriptor = move(d);
|
descriptor = move(d);
|
||||||
flags = f;
|
flags = f;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include <LibC/signal_numbers.h>
|
#include <LibC/signal_numbers.h>
|
||||||
|
|
||||||
class ELFLoader;
|
class ELFLoader;
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
class PageDirectory;
|
class PageDirectory;
|
||||||
class Region;
|
class Region;
|
||||||
class VMObject;
|
class VMObject;
|
||||||
|
@ -87,8 +87,8 @@ public:
|
||||||
|
|
||||||
bool in_group(gid_t) const;
|
bool in_group(gid_t) const;
|
||||||
|
|
||||||
FileDescriptor* file_descriptor(int fd);
|
FileDescription* file_description(int fd);
|
||||||
const FileDescriptor* file_descriptor(int fd) const;
|
const FileDescription* file_description(int fd) const;
|
||||||
|
|
||||||
template<typename Callback>
|
template<typename Callback>
|
||||||
static void for_each(Callback);
|
static void for_each(Callback);
|
||||||
|
@ -280,7 +280,7 @@ private:
|
||||||
Range allocate_range(LinearAddress, size_t);
|
Range allocate_range(LinearAddress, size_t);
|
||||||
|
|
||||||
int do_exec(String path, Vector<String> arguments, Vector<String> environment);
|
int do_exec(String path, Vector<String> arguments, Vector<String> environment);
|
||||||
ssize_t do_write(FileDescriptor&, const byte*, int data_size);
|
ssize_t do_write(FileDescription&, const byte*, int data_size);
|
||||||
|
|
||||||
int alloc_fd(int first_candidate_fd = 0);
|
int alloc_fd(int first_candidate_fd = 0);
|
||||||
void disown_all_shared_buffers();
|
void disown_all_shared_buffers();
|
||||||
|
@ -306,17 +306,17 @@ private:
|
||||||
|
|
||||||
Priority m_priority { NormalPriority };
|
Priority m_priority { NormalPriority };
|
||||||
|
|
||||||
struct FileDescriptorAndFlags {
|
struct FileDescriptionAndFlags {
|
||||||
operator bool() const { return !!descriptor; }
|
operator bool() const { return !!descriptor; }
|
||||||
void clear();
|
void clear();
|
||||||
void set(Retained<FileDescriptor>&& d, dword f = 0);
|
void set(Retained<FileDescription>&& d, dword f = 0);
|
||||||
RetainPtr<FileDescriptor> descriptor;
|
RetainPtr<FileDescription> descriptor;
|
||||||
dword flags { 0 };
|
dword flags { 0 };
|
||||||
};
|
};
|
||||||
Vector<FileDescriptorAndFlags> m_fds;
|
Vector<FileDescriptionAndFlags> m_fds;
|
||||||
RingLevel m_ring { Ring0 };
|
RingLevel m_ring { Ring0 };
|
||||||
|
|
||||||
int m_max_open_file_descriptors { 128 };
|
static const int m_max_open_file_descriptors { FD_SETSIZE };
|
||||||
|
|
||||||
byte m_termination_status { 0 };
|
byte m_termination_status { 0 };
|
||||||
byte m_termination_signal { 0 };
|
byte m_termination_signal { 0 };
|
||||||
|
|
|
@ -18,7 +18,7 @@ void ProcessTracer::did_syscall(dword function, dword arg1, dword arg2, dword ar
|
||||||
m_calls.enqueue(data);
|
m_calls.enqueue(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ProcessTracer::read(FileDescriptor&, byte* buffer, int buffer_size)
|
int ProcessTracer::read(FileDescription&, byte* buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
if (m_calls.is_empty())
|
if (m_calls.is_empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -29,7 +29,7 @@ int ProcessTracer::read(FileDescriptor&, byte* buffer, int buffer_size)
|
||||||
return sizeof(data);
|
return sizeof(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
String ProcessTracer::absolute_path(const FileDescriptor&) const
|
String ProcessTracer::absolute_path(const FileDescription&) const
|
||||||
{
|
{
|
||||||
return String::format("tracer:%d", m_pid);
|
return String::format("tracer:%d", m_pid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,13 +12,13 @@ public:
|
||||||
bool is_dead() const { return m_dead; }
|
bool is_dead() const { return m_dead; }
|
||||||
void set_dead() { m_dead = true; }
|
void set_dead() { m_dead = true; }
|
||||||
|
|
||||||
virtual bool can_read(FileDescriptor&) const override { return !m_calls.is_empty() || m_dead; }
|
virtual bool can_read(FileDescription&) const override { return !m_calls.is_empty() || m_dead; }
|
||||||
virtual int read(FileDescriptor&, byte*, int) override;
|
virtual int read(FileDescription&, byte*, int) override;
|
||||||
|
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
virtual int write(FileDescriptor&, const byte*, int) override { return -EIO; }
|
virtual int write(FileDescription&, const byte*, int) override { return -EIO; }
|
||||||
|
|
||||||
virtual String absolute_path(const FileDescriptor&) const override;
|
virtual String absolute_path(const FileDescription&) const override;
|
||||||
|
|
||||||
void did_syscall(dword function, dword arg1, dword arg2, dword arg3, dword result);
|
void did_syscall(dword function, dword arg1, dword arg2, dword arg3, dword result);
|
||||||
pid_t pid() const { return m_pid; }
|
pid_t pid() const { return m_pid; }
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "i8253.h"
|
#include "i8253.h"
|
||||||
#include <AK/TemporaryChange.h>
|
#include <AK/TemporaryChange.h>
|
||||||
#include <Kernel/Alarm.h>
|
#include <Kernel/Alarm.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/Devices/PCSpeaker.h>
|
#include <Kernel/Devices/PCSpeaker.h>
|
||||||
|
|
||||||
//#define LOG_EVERY_CONTEXT_SWITCH
|
//#define LOG_EVERY_CONTEXT_SWITCH
|
||||||
|
|
|
@ -68,12 +68,12 @@ KResult SharedMemory::truncate(int length)
|
||||||
return KResult(-ENOTIMPL);
|
return KResult(-ENOTIMPL);
|
||||||
}
|
}
|
||||||
|
|
||||||
String SharedMemory::absolute_path(const FileDescriptor&) const
|
String SharedMemory::absolute_path(const FileDescription&) const
|
||||||
{
|
{
|
||||||
return String::format("shm:%u", this);
|
return String::format("shm:%u", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SharedMemory::read(FileDescriptor&, byte* buffer, int buffer_size)
|
int SharedMemory::read(FileDescription&, byte* buffer, int buffer_size)
|
||||||
{
|
{
|
||||||
UNUSED_PARAM(buffer);
|
UNUSED_PARAM(buffer);
|
||||||
UNUSED_PARAM(buffer_size);
|
UNUSED_PARAM(buffer_size);
|
||||||
|
@ -81,7 +81,7 @@ int SharedMemory::read(FileDescriptor&, byte* buffer, int buffer_size)
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SharedMemory::write(FileDescriptor&, const byte* data, int data_size)
|
int SharedMemory::write(FileDescription&, const byte* data, int data_size)
|
||||||
{
|
{
|
||||||
UNUSED_PARAM(data);
|
UNUSED_PARAM(data);
|
||||||
UNUSED_PARAM(data_size);
|
UNUSED_PARAM(data_size);
|
||||||
|
@ -89,7 +89,7 @@ int SharedMemory::write(FileDescriptor&, const byte* data, int data_size)
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Region*> SharedMemory::mmap(Process& process, FileDescriptor&, LinearAddress laddr, size_t offset, size_t size, int prot)
|
KResultOr<Region*> SharedMemory::mmap(Process& process, FileDescription&, LinearAddress laddr, size_t offset, size_t size, int prot)
|
||||||
{
|
{
|
||||||
if (!vmo())
|
if (!vmo())
|
||||||
return KResult(-ENODEV);
|
return KResult(-ENODEV);
|
||||||
|
|
|
@ -24,14 +24,14 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^File
|
// ^File
|
||||||
virtual bool can_read(FileDescriptor&) const override { return true; }
|
virtual bool can_read(FileDescription&) const override { return true; }
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
virtual int read(FileDescriptor&, byte*, int) override;
|
virtual int read(FileDescription&, byte*, int) override;
|
||||||
virtual int write(FileDescriptor&, const byte*, int) override;
|
virtual int write(FileDescription&, const byte*, int) override;
|
||||||
virtual String absolute_path(const FileDescriptor&) const override;
|
virtual String absolute_path(const FileDescription&) const override;
|
||||||
virtual const char* class_name() const override { return "SharedMemory"; }
|
virtual const char* class_name() const override { return "SharedMemory"; }
|
||||||
virtual bool is_shared_memory() const override { return true; }
|
virtual bool is_shared_memory() const override { return true; }
|
||||||
virtual KResultOr<Region*> mmap(Process&, FileDescriptor&, LinearAddress, size_t offset, size_t size, int prot) override;
|
virtual KResultOr<Region*> mmap(Process&, FileDescription&, LinearAddress, size_t offset, size_t size, int prot) override;
|
||||||
|
|
||||||
SharedMemory(const String& name, uid_t, gid_t, mode_t);
|
SharedMemory(const String& name, uid_t, gid_t, mode_t);
|
||||||
|
|
||||||
|
|
|
@ -31,14 +31,14 @@ String MasterPTY::pts_name() const
|
||||||
return m_pts_name;
|
return m_pts_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t MasterPTY::read(FileDescriptor&, byte* buffer, ssize_t size)
|
ssize_t MasterPTY::read(FileDescription&, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
if (!m_slave && m_buffer.is_empty())
|
if (!m_slave && m_buffer.is_empty())
|
||||||
return 0;
|
return 0;
|
||||||
return m_buffer.read(buffer, size);
|
return m_buffer.read(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t MasterPTY::write(FileDescriptor&, const byte* buffer, ssize_t size)
|
ssize_t MasterPTY::write(FileDescription&, const byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
if (!m_slave)
|
if (!m_slave)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -46,14 +46,14 @@ ssize_t MasterPTY::write(FileDescriptor&, const byte* buffer, ssize_t size)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MasterPTY::can_read(FileDescriptor&) const
|
bool MasterPTY::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
if (!m_slave)
|
if (!m_slave)
|
||||||
return true;
|
return true;
|
||||||
return !m_buffer.is_empty();
|
return !m_buffer.is_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MasterPTY::can_write(FileDescriptor&) const
|
bool MasterPTY::can_write(FileDescription&) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ void MasterPTY::notify_slave_closed(Badge<SlavePTY>)
|
||||||
dbgprintf("MasterPTY(%u): slave closed, my retains: %u, slave retains: %u\n", m_index, retain_count(), m_slave->retain_count());
|
dbgprintf("MasterPTY(%u): slave closed, my retains: %u, slave retains: %u\n", m_index, retain_count(), m_slave->retain_count());
|
||||||
#endif
|
#endif
|
||||||
// +1 retain for my MasterPTY::m_slave
|
// +1 retain for my MasterPTY::m_slave
|
||||||
// +1 retain for FileDescriptor::m_device
|
// +1 retain for FileDescription::m_device
|
||||||
if (m_slave->retain_count() == 2)
|
if (m_slave->retain_count() == 2)
|
||||||
m_slave = nullptr;
|
m_slave = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ void MasterPTY::close()
|
||||||
{
|
{
|
||||||
if (retain_count() == 2) {
|
if (retain_count() == 2) {
|
||||||
InterruptDisabler disabler;
|
InterruptDisabler disabler;
|
||||||
// After the closing FileDescriptor dies, slave is the only thing keeping me alive.
|
// After the closing FileDescription dies, slave is the only thing keeping me alive.
|
||||||
// From this point, let's consider ourselves closed.
|
// From this point, let's consider ourselves closed.
|
||||||
m_closed = true;
|
m_closed = true;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ void MasterPTY::close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int MasterPTY::ioctl(FileDescriptor& descriptor, unsigned request, unsigned arg)
|
int MasterPTY::ioctl(FileDescription& descriptor, unsigned request, unsigned arg)
|
||||||
{
|
{
|
||||||
if (request == TIOCSWINSZ)
|
if (request == TIOCSWINSZ)
|
||||||
return m_slave->ioctl(descriptor, request, arg);
|
return m_slave->ioctl(descriptor, request, arg);
|
||||||
|
|
|
@ -20,13 +20,13 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual bool can_write(FileDescriptor&) const override;
|
virtual bool can_write(FileDescription&) const override;
|
||||||
virtual void close() override;
|
virtual void close() override;
|
||||||
virtual bool is_master_pty() const override { return true; }
|
virtual bool is_master_pty() const override { return true; }
|
||||||
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg) override;
|
virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override;
|
||||||
virtual const char* class_name() const override { return "MasterPTY"; }
|
virtual const char* class_name() const override { return "MasterPTY"; }
|
||||||
|
|
||||||
RetainPtr<SlavePTY> m_slave;
|
RetainPtr<SlavePTY> m_slave;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "PTYMultiplexer.h"
|
#include "PTYMultiplexer.h"
|
||||||
#include "MasterPTY.h"
|
#include "MasterPTY.h"
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
#include <LibC/errno_numbers.h>
|
#include <LibC/errno_numbers.h>
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ PTYMultiplexer::~PTYMultiplexer()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
KResultOr<Retained<FileDescriptor>> PTYMultiplexer::open(int options)
|
KResultOr<Retained<FileDescription>> PTYMultiplexer::open(int options)
|
||||||
{
|
{
|
||||||
UNUSED_PARAM(options);
|
UNUSED_PARAM(options);
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
|
@ -39,7 +39,7 @@ KResultOr<Retained<FileDescriptor>> PTYMultiplexer::open(int options)
|
||||||
#ifdef PTMX_DEBUG
|
#ifdef PTMX_DEBUG
|
||||||
dbgprintf("PTYMultiplexer::open: Vending master %u\n", master->index());
|
dbgprintf("PTYMultiplexer::open: Vending master %u\n", master->index());
|
||||||
#endif
|
#endif
|
||||||
return FileDescriptor::create(master.ptr());
|
return FileDescription::create(master.ptr());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PTYMultiplexer::notify_master_destroyed(Badge<MasterPTY>, unsigned index)
|
void PTYMultiplexer::notify_master_destroyed(Badge<MasterPTY>, unsigned index)
|
||||||
|
|
|
@ -15,11 +15,11 @@ public:
|
||||||
static PTYMultiplexer& the();
|
static PTYMultiplexer& the();
|
||||||
|
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual KResultOr<Retained<FileDescriptor>> open(int options) override;
|
virtual KResultOr<Retained<FileDescription>> open(int options) override;
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override { return 0; }
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override { return 0; }
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override { return 0; }
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override { return 0; }
|
||||||
virtual bool can_read(FileDescriptor&) const override { return true; }
|
virtual bool can_read(FileDescription&) const override { return true; }
|
||||||
virtual bool can_write(FileDescriptor&) const override { return true; }
|
virtual bool can_write(FileDescription&) const override { return true; }
|
||||||
|
|
||||||
void notify_master_destroyed(Badge<MasterPTY>, unsigned index);
|
void notify_master_destroyed(Badge<MasterPTY>, unsigned index);
|
||||||
|
|
||||||
|
|
|
@ -41,19 +41,19 @@ ssize_t SlavePTY::on_tty_write(const byte* data, ssize_t size)
|
||||||
return m_master->on_slave_write(data, size);
|
return m_master->on_slave_write(data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SlavePTY::can_write(FileDescriptor&) const
|
bool SlavePTY::can_write(FileDescription&) const
|
||||||
{
|
{
|
||||||
return m_master->can_write_from_slave();
|
return m_master->can_write_from_slave();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SlavePTY::can_read(FileDescriptor& descriptor) const
|
bool SlavePTY::can_read(FileDescription& descriptor) const
|
||||||
{
|
{
|
||||||
if (m_master->is_closed())
|
if (m_master->is_closed())
|
||||||
return true;
|
return true;
|
||||||
return TTY::can_read(descriptor);
|
return TTY::can_read(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t SlavePTY::read(FileDescriptor& descriptor, byte* buffer, ssize_t size)
|
ssize_t SlavePTY::read(FileDescription& descriptor, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
if (m_master->is_closed())
|
if (m_master->is_closed())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -21,9 +21,9 @@ private:
|
||||||
virtual ssize_t on_tty_write(const byte*, ssize_t) override;
|
virtual ssize_t on_tty_write(const byte*, ssize_t) override;
|
||||||
|
|
||||||
// ^CharacterDevice
|
// ^CharacterDevice
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual bool can_write(FileDescriptor&) const override;
|
virtual bool can_write(FileDescription&) const override;
|
||||||
virtual const char* class_name() const override { return "SlavePTY"; }
|
virtual const char* class_name() const override { return "SlavePTY"; }
|
||||||
virtual void close() override;
|
virtual void close() override;
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,12 @@ void TTY::set_default_termios()
|
||||||
memcpy(m_termios.c_cc, default_cc, sizeof(default_cc));
|
memcpy(m_termios.c_cc, default_cc, sizeof(default_cc));
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t TTY::read(FileDescriptor&, byte* buffer, ssize_t size)
|
ssize_t TTY::read(FileDescription&, byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
return m_buffer.read(buffer, size);
|
return m_buffer.read(buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t TTY::write(FileDescriptor&, const byte* buffer, ssize_t size)
|
ssize_t TTY::write(FileDescription&, const byte* buffer, ssize_t size)
|
||||||
{
|
{
|
||||||
#ifdef TTY_DEBUG
|
#ifdef TTY_DEBUG
|
||||||
dbgprintf("TTY::write {%u} ", size);
|
dbgprintf("TTY::write {%u} ", size);
|
||||||
|
@ -42,12 +42,12 @@ ssize_t TTY::write(FileDescriptor&, const byte* buffer, ssize_t size)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TTY::can_read(FileDescriptor&) const
|
bool TTY::can_read(FileDescription&) const
|
||||||
{
|
{
|
||||||
return !m_buffer.is_empty();
|
return !m_buffer.is_empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TTY::can_write(FileDescriptor&) const
|
bool TTY::can_write(FileDescription&) const
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ void TTY::set_termios(const termios& t)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TTY::ioctl(FileDescriptor&, unsigned request, unsigned arg)
|
int TTY::ioctl(FileDescription&, unsigned request, unsigned arg)
|
||||||
{
|
{
|
||||||
auto& process = current->process();
|
auto& process = current->process();
|
||||||
pid_t pgid;
|
pid_t pgid;
|
||||||
|
|
|
@ -10,12 +10,12 @@ class TTY : public CharacterDevice {
|
||||||
public:
|
public:
|
||||||
virtual ~TTY() override;
|
virtual ~TTY() override;
|
||||||
|
|
||||||
virtual ssize_t read(FileDescriptor&, byte*, ssize_t) override;
|
virtual ssize_t read(FileDescription&, byte*, ssize_t) override;
|
||||||
virtual ssize_t write(FileDescriptor&, const byte*, ssize_t) override;
|
virtual ssize_t write(FileDescription&, const byte*, ssize_t) override;
|
||||||
virtual bool can_read(FileDescriptor&) const override;
|
virtual bool can_read(FileDescription&) const override;
|
||||||
virtual bool can_write(FileDescriptor&) const override;
|
virtual bool can_write(FileDescription&) const override;
|
||||||
virtual int ioctl(FileDescriptor&, unsigned request, unsigned arg) override final;
|
virtual int ioctl(FileDescription&, unsigned request, unsigned arg) override final;
|
||||||
virtual String absolute_path(const FileDescriptor&) const override { return tty_name(); }
|
virtual String absolute_path(const FileDescription&) const override { return tty_name(); }
|
||||||
|
|
||||||
virtual String tty_name() const = 0;
|
virtual String tty_name() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#include <Kernel/Thread.h>
|
#include <Kernel/Thread.h>
|
||||||
#include <Kernel/Scheduler.h>
|
#include <Kernel/Scheduler.h>
|
||||||
#include <Kernel/Process.h>
|
#include <Kernel/Process.h>
|
||||||
#include <Kernel/FileSystem/FileDescriptor.h>
|
#include <Kernel/FileSystem/FileDescription.h>
|
||||||
#include <Kernel/VM/MemoryManager.h>
|
#include <Kernel/VM/MemoryManager.h>
|
||||||
#include <LibC/signal_numbers.h>
|
#include <LibC/signal_numbers.h>
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ void Thread::block(Thread::State new_state)
|
||||||
process().big_lock().lock();
|
process().big_lock().lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Thread::block(Thread::State new_state, FileDescriptor& descriptor)
|
void Thread::block(Thread::State new_state, FileDescription& descriptor)
|
||||||
{
|
{
|
||||||
m_blocked_descriptor = &descriptor;
|
m_blocked_descriptor = &descriptor;
|
||||||
block(new_state);
|
block(new_state);
|
||||||
|
@ -512,7 +512,7 @@ Thread* Thread::clone(Process& process)
|
||||||
return clone;
|
return clone;
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult Thread::wait_for_connect(FileDescriptor& descriptor)
|
KResult Thread::wait_for_connect(FileDescription& descriptor)
|
||||||
{
|
{
|
||||||
ASSERT(descriptor.is_socket());
|
ASSERT(descriptor.is_socket());
|
||||||
auto& socket = *descriptor.socket();
|
auto& socket = *descriptor.socket();
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include <Kernel/i386.h>
|
#include <Kernel/i386.h>
|
||||||
|
|
||||||
class Alarm;
|
class Alarm;
|
||||||
class FileDescriptor;
|
class FileDescription;
|
||||||
class Process;
|
class Process;
|
||||||
class Region;
|
class Region;
|
||||||
class Thread;
|
class Thread;
|
||||||
|
@ -97,13 +97,13 @@ public:
|
||||||
|
|
||||||
void sleep(dword ticks);
|
void sleep(dword ticks);
|
||||||
void block(Thread::State);
|
void block(Thread::State);
|
||||||
void block(Thread::State, FileDescriptor&);
|
void block(Thread::State, FileDescription&);
|
||||||
void unblock();
|
void unblock();
|
||||||
|
|
||||||
void set_wakeup_time(qword t) { m_wakeup_time = t; }
|
void set_wakeup_time(qword t) { m_wakeup_time = t; }
|
||||||
qword wakeup_time() const { return m_wakeup_time; }
|
qword wakeup_time() const { return m_wakeup_time; }
|
||||||
void snooze_until(Alarm&);
|
void snooze_until(Alarm&);
|
||||||
KResult wait_for_connect(FileDescriptor&);
|
KResult wait_for_connect(FileDescription&);
|
||||||
|
|
||||||
const FarPtr& far_ptr() const { return m_far_ptr; }
|
const FarPtr& far_ptr() const { return m_far_ptr; }
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ private:
|
||||||
RetainPtr<Region> m_kernel_stack_region;
|
RetainPtr<Region> m_kernel_stack_region;
|
||||||
RetainPtr<Region> m_kernel_stack_for_signal_handler_region;
|
RetainPtr<Region> m_kernel_stack_for_signal_handler_region;
|
||||||
pid_t m_waitee_pid { -1 };
|
pid_t m_waitee_pid { -1 };
|
||||||
RetainPtr<FileDescriptor> m_blocked_descriptor;
|
RetainPtr<FileDescription> m_blocked_descriptor;
|
||||||
timeval m_select_timeout;
|
timeval m_select_timeout;
|
||||||
SignalActionData m_signal_action_data[32];
|
SignalActionData m_signal_action_data[32];
|
||||||
Region* m_signal_stack_user_region { nullptr };
|
Region* m_signal_stack_user_region { nullptr };
|
||||||
|
|
|
@ -10,11 +10,11 @@ CFile::CFile(const StringView& filename)
|
||||||
|
|
||||||
CFile::~CFile()
|
CFile::~CFile()
|
||||||
{
|
{
|
||||||
if (m_should_close_file_descriptor == ShouldCloseFileDescriptor::Yes && mode() != NotOpen)
|
if (m_should_close_file_descriptor == ShouldCloseFileDescription::Yes && mode() != NotOpen)
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CFile::open(int fd, CIODevice::OpenMode mode, ShouldCloseFileDescriptor should_close)
|
bool CFile::open(int fd, CIODevice::OpenMode mode, ShouldCloseFileDescription should_close)
|
||||||
{
|
{
|
||||||
set_fd(fd);
|
set_fd(fd);
|
||||||
set_mode(mode);
|
set_mode(mode);
|
||||||
|
|
|
@ -14,16 +14,16 @@ public:
|
||||||
|
|
||||||
virtual bool open(CIODevice::OpenMode) override;
|
virtual bool open(CIODevice::OpenMode) override;
|
||||||
|
|
||||||
enum class ShouldCloseFileDescriptor
|
enum class ShouldCloseFileDescription
|
||||||
{
|
{
|
||||||
No = 0,
|
No = 0,
|
||||||
Yes
|
Yes
|
||||||
};
|
};
|
||||||
bool open(int fd, CIODevice::OpenMode, ShouldCloseFileDescriptor);
|
bool open(int fd, CIODevice::OpenMode, ShouldCloseFileDescription);
|
||||||
|
|
||||||
virtual const char* class_name() const override { return "CFile"; }
|
virtual const char* class_name() const override { return "CFile"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String m_filename;
|
String m_filename;
|
||||||
ShouldCloseFileDescriptor m_should_close_file_descriptor { ShouldCloseFileDescriptor::Yes };
|
ShouldCloseFileDescription m_should_close_file_descriptor { ShouldCloseFileDescription::Yes };
|
||||||
};
|
};
|
||||||
|
|
|
@ -189,10 +189,10 @@ static bool handle_builtin(int argc, char** argv, int& retval)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileDescriptorCollector {
|
class FileDescriptionCollector {
|
||||||
public:
|
public:
|
||||||
FileDescriptorCollector() { }
|
FileDescriptionCollector() { }
|
||||||
~FileDescriptorCollector() { collect(); }
|
~FileDescriptionCollector() { collect(); }
|
||||||
|
|
||||||
void collect()
|
void collect()
|
||||||
{
|
{
|
||||||
|
@ -302,7 +302,7 @@ static int run_command(const String& cmd)
|
||||||
if (subcommands.is_empty())
|
if (subcommands.is_empty())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
FileDescriptorCollector fds;
|
FileDescriptionCollector fds;
|
||||||
|
|
||||||
for (int i = 0; i < subcommands.size(); ++i) {
|
for (int i = 0; i < subcommands.size(); ++i) {
|
||||||
auto& subcommand = subcommands[i];
|
auto& subcommand = subcommands[i];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue