2023-07-07 23:11:37 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <BAN/Array.h>
|
|
|
|
#include <kernel/FS/Inode.h>
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
namespace Kernel
|
|
|
|
{
|
|
|
|
|
|
|
|
class OpenFileDescriptorSet
|
|
|
|
{
|
|
|
|
BAN_NON_COPYABLE(OpenFileDescriptorSet);
|
|
|
|
|
|
|
|
public:
|
|
|
|
OpenFileDescriptorSet(const Credentials&);
|
|
|
|
~OpenFileDescriptorSet();
|
|
|
|
|
2023-07-19 17:47:12 +03:00
|
|
|
OpenFileDescriptorSet& operator=(OpenFileDescriptorSet&&);
|
|
|
|
|
2023-07-07 23:11:37 +03:00
|
|
|
BAN::ErrorOr<void> clone_from(const OpenFileDescriptorSet&);
|
|
|
|
|
|
|
|
BAN::ErrorOr<int> open(BAN::StringView absolute_path, int flags);
|
|
|
|
|
|
|
|
BAN::ErrorOr<void> pipe(int fds[2]);
|
|
|
|
|
2023-08-17 12:03:29 +03:00
|
|
|
BAN::ErrorOr<int> dup(int);
|
2023-07-07 23:11:37 +03:00
|
|
|
BAN::ErrorOr<int> dup2(int, int);
|
|
|
|
|
2023-09-04 12:57:09 +03:00
|
|
|
BAN::ErrorOr<int> fcntl(int fd, int cmd, int extra);
|
|
|
|
|
2023-07-07 23:11:37 +03:00
|
|
|
BAN::ErrorOr<void> seek(int fd, off_t offset, int whence);
|
|
|
|
BAN::ErrorOr<off_t> tell(int) const;
|
|
|
|
|
|
|
|
BAN::ErrorOr<void> fstat(int fd, struct stat*) const;
|
2023-09-08 11:46:53 +03:00
|
|
|
BAN::ErrorOr<void> fstatat(int fd, BAN::StringView path, struct stat* buf, int flag);
|
|
|
|
BAN::ErrorOr<void> stat(BAN::StringView absolute_path, struct stat* buf, int flag);
|
2023-07-07 23:11:37 +03:00
|
|
|
|
|
|
|
BAN::ErrorOr<void> close(int);
|
|
|
|
void close_all();
|
|
|
|
void close_cloexec();
|
|
|
|
|
2023-10-20 05:07:44 +03:00
|
|
|
BAN::ErrorOr<size_t> read(int fd, BAN::ByteSpan);
|
|
|
|
BAN::ErrorOr<size_t> write(int fd, BAN::ConstByteSpan);
|
2023-07-07 23:11:37 +03:00
|
|
|
|
|
|
|
BAN::ErrorOr<void> read_dir_entries(int fd, DirectoryEntryList* list, size_t list_size);
|
|
|
|
|
|
|
|
BAN::ErrorOr<BAN::StringView> path_of(int) const;
|
2023-07-23 18:52:33 +03:00
|
|
|
BAN::ErrorOr<BAN::RefPtr<Inode>> inode_of(int);
|
2023-09-29 17:23:42 +03:00
|
|
|
BAN::ErrorOr<int> flags_of(int) const;
|
2023-07-07 23:11:37 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
struct OpenFileDescription : public BAN::RefCounted<OpenFileDescription>
|
|
|
|
{
|
2023-07-10 16:06:36 +03:00
|
|
|
OpenFileDescription(BAN::RefPtr<Inode> inode, BAN::String path, off_t offset, int flags)
|
2023-07-07 23:11:37 +03:00
|
|
|
: inode(inode)
|
|
|
|
, path(BAN::move(path))
|
|
|
|
, offset(offset)
|
|
|
|
, flags(flags)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
BAN::RefPtr<Inode> inode;
|
|
|
|
BAN::String path;
|
|
|
|
off_t offset { 0 };
|
2023-07-10 16:06:36 +03:00
|
|
|
int flags { 0 };
|
2023-07-07 23:11:37 +03:00
|
|
|
|
|
|
|
friend class BAN::RefPtr<OpenFileDescription>;
|
|
|
|
};
|
|
|
|
|
|
|
|
BAN::ErrorOr<void> validate_fd(int) const;
|
|
|
|
BAN::ErrorOr<int> get_free_fd() const;
|
|
|
|
BAN::ErrorOr<void> get_free_fd_pair(int fds[2]) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const Credentials& m_credentials;
|
|
|
|
|
|
|
|
BAN::Array<BAN::RefPtr<OpenFileDescription>, OPEN_MAX> m_open_files;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|