kernel: Move file descriptors into their own separate file

This commit is contained in:
apio 2023-10-23 20:13:11 +02:00
parent 8476ea0dc9
commit b3cbbea9d6
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 71 additions and 62 deletions

View File

@ -56,6 +56,7 @@ set(SOURCES
src/fs/MBR.cpp
src/fs/GPT.cpp
src/fs/StorageCache.cpp
src/fs/OpenFileDescription.cpp
src/net/UnixSocket.cpp
src/fs/tmpfs/FileSystem.cpp
src/fs/tmpfs/Inode.cpp

View File

@ -0,0 +1,33 @@
#include "fs/OpenFileDescription.h"
#include <bits/open-flags.h>
OpenFileDescription::OpenFileDescription(SharedPtr<VFS::Inode> ino, int fl) : inode(ino), flags(fl)
{
inode->add_handle();
}
OpenFileDescription::~OpenFileDescription()
{
inode->remove_handle();
inode->did_close();
}
bool FileDescriptor::should_append()
{
return description->flags & O_APPEND;
}
bool FileDescriptor::should_block()
{
return !(description->flags & O_NONBLOCK);
}
bool FileDescriptor::is_readable()
{
return description->flags & O_RDONLY;
}
bool FileDescriptor::is_writable()
{
return description->flags & O_WRONLY;
}

View File

@ -0,0 +1,36 @@
#pragma once
#include "fs/VFS.h"
#include <luna/SharedPtr.h>
#include <luna/String.h>
struct OpenFileDescription : public Shareable
{
SharedPtr<VFS::Inode> inode;
int flags { 0 };
String path;
OpenFileDescription(SharedPtr<VFS::Inode>, int);
~OpenFileDescription();
};
struct FileDescriptor
{
SharedPtr<OpenFileDescription> description;
usize offset { 0 };
int flags { 0 };
bool should_append();
bool should_block();
bool is_writable();
bool is_readable();
SharedPtr<VFS::Inode> inode()
{
return description->inode;
}
int& status_flags()
{
return description->flags;
}
};

View File

@ -236,34 +236,3 @@ void Thread::send_signal(int signo)
wake_up();
}
}
OpenFileDescription::OpenFileDescription(SharedPtr<VFS::Inode> ino, int fl) : inode(ino), flags(fl)
{
inode->add_handle();
}
OpenFileDescription::~OpenFileDescription()
{
inode->remove_handle();
inode->did_close();
}
bool FileDescriptor::should_append()
{
return description->flags & O_APPEND;
}
bool FileDescriptor::should_block()
{
return !(description->flags & O_NONBLOCK);
}
bool FileDescriptor::is_readable()
{
return description->flags & O_RDONLY;
}
bool FileDescriptor::is_writable()
{
return description->flags & O_WRONLY;
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "arch/MMU.h"
#include "fs/OpenFileDescription.h"
#include "fs/VFS.h"
#include "memory/AddressSpace.h"
#include <bits/signal.h>
@ -29,37 +30,6 @@ enum class ThreadState
Dying
};
struct OpenFileDescription : public Shareable
{
SharedPtr<VFS::Inode> inode;
int flags { 0 };
OpenFileDescription(SharedPtr<VFS::Inode>, int);
~OpenFileDescription();
};
struct FileDescriptor
{
SharedPtr<OpenFileDescription> description;
usize offset { 0 };
int flags { 0 };
bool should_append();
bool should_block();
bool is_writable();
bool is_readable();
SharedPtr<VFS::Inode> inode()
{
return description->inode;
}
int& status_flags()
{
return description->flags;
}
};
static constexpr int FD_MAX = 64;
struct Credentials