Kernel/LibC: Add basic pipe() syscall and command

You can now create pipes :)
This commit is contained in:
Bananymous
2023-07-06 22:16:26 +03:00
parent cdcb395640
commit 4cd72992c8
9 changed files with 220 additions and 1 deletions

View File

@@ -76,6 +76,7 @@ namespace Kernel
virtual dev_t rdev() const = 0;
virtual bool is_device() const { return false; }
virtual bool is_pipe() const { return false; }
virtual BAN::StringView name() const = 0;

View File

@@ -0,0 +1,54 @@
#pragma once
#include <kernel/FS/Inode.h>
#include <kernel/Semaphore.h>
#include <kernel/SpinLock.h>
namespace Kernel
{
class Pipe : public Inode
{
public:
static BAN::ErrorOr<BAN::RefPtr<Inode>> create(const Credentials&);
virtual bool is_pipe() const override { return true; }
void clone_writing();
void close_writing();
virtual ino_t ino() const override { return 0; } // FIXME
virtual Mode mode() const override { return { Mode::IFIFO | Mode::IRUSR | Mode::IWUSR }; }
virtual nlink_t nlink() const override { return 1; }
virtual uid_t uid() const override { return m_uid; }
virtual gid_t gid() const override { return m_gid; }
virtual off_t size() const override { return 0; }
virtual timespec atime() const override { return m_atime; }
virtual timespec mtime() const override { return m_mtime; }
virtual timespec ctime() const override { return m_ctime; }
virtual blksize_t blksize() const override { return 4096; }
virtual blkcnt_t blocks() const override { return 0; }
virtual dev_t dev() const override { return 0; } // FIXME
virtual dev_t rdev() const override { return 0; } // FIXME
virtual BAN::StringView name() const override { return ""sv; }
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
virtual BAN::ErrorOr<size_t> write(size_t, const void*, size_t) override;
private:
Pipe(const Credentials&);
private:
const uid_t m_uid;
const gid_t m_gid;
timespec m_atime {};
timespec m_mtime {};
timespec m_ctime {};
BAN::Vector<uint8_t> m_buffer;
SpinLock m_lock;
Semaphore m_semaphore;
uint32_t m_writing_count { 1 };
};
}

View File

@@ -84,6 +84,8 @@ namespace Kernel
BAN::ErrorOr<long> sys_write(int fd, const void* buffer, size_t count);
BAN::ErrorOr<long> sys_creat(BAN::StringView name, mode_t);
BAN::ErrorOr<long> sys_pipe(int fildes[2]);
BAN::ErrorOr<long> sys_seek(int fd, off_t offset, int whence);
BAN::ErrorOr<long> sys_tell(int fd);
@@ -136,6 +138,7 @@ namespace Kernel
BAN::ErrorOr<void> validate_fd(int);
OpenFileDescription& open_file_description(int);
BAN::ErrorOr<int> get_free_fd();
BAN::ErrorOr<void> get_free_fd_pair(int fds[2]);
struct ExitStatus