kernel: Move file descriptors into their own separate file
This commit is contained in:
parent
8476ea0dc9
commit
b3cbbea9d6
@ -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
|
||||
|
33
kernel/src/fs/OpenFileDescription.cpp
Normal file
33
kernel/src/fs/OpenFileDescription.cpp
Normal 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;
|
||||
}
|
36
kernel/src/fs/OpenFileDescription.h
Normal file
36
kernel/src/fs/OpenFileDescription.h
Normal 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;
|
||||
}
|
||||
};
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user