2018-10-10 11:53:07 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <AK/RetainPtr.h>
|
2018-12-04 00:27:16 +01:00
|
|
|
#include <AK/AKString.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
#include <AK/Vector.h>
|
2018-10-24 12:43:52 +02:00
|
|
|
#include <AK/Function.h>
|
2018-10-10 11:53:07 +02:00
|
|
|
#include "InodeIdentifier.h"
|
2018-10-24 12:43:52 +02:00
|
|
|
#include "InodeMetadata.h"
|
2018-10-14 21:19:27 +02:00
|
|
|
#include "Limits.h"
|
2018-10-24 12:43:52 +02:00
|
|
|
#include "FileSystem.h"
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-10-28 14:11:51 +01:00
|
|
|
#define O_RDONLY 0
|
|
|
|
#define O_WRONLY 1
|
|
|
|
#define O_RDWR 2
|
2018-11-13 01:36:31 +01:00
|
|
|
#define O_CREAT 0100
|
|
|
|
#define O_EXCL 0200
|
|
|
|
#define O_NOCTTY 0400
|
|
|
|
#define O_TRUNC 01000
|
|
|
|
#define O_APPEND 02000
|
|
|
|
#define O_NONBLOCK 04000
|
2018-10-28 14:11:51 +01:00
|
|
|
#define O_DIRECTORY 00200000
|
|
|
|
#define O_NOFOLLOW 00400000
|
2018-11-13 01:36:31 +01:00
|
|
|
#define O_CLOEXEC 02000000
|
2018-10-28 14:11:51 +01:00
|
|
|
#define O_NOFOLLOW_NOERROR 0x4000000
|
2019-01-31 05:05:57 +01:00
|
|
|
#define O_DONT_OPEN_DEVICE 0x8000000
|
2018-10-28 14:11:51 +01:00
|
|
|
|
2019-02-16 00:47:20 +01:00
|
|
|
class Device;
|
2018-11-07 11:37:54 +01:00
|
|
|
class FileDescriptor;
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-01-31 17:31:23 +01:00
|
|
|
inline constexpr dword encoded_device(unsigned major, unsigned minor)
|
2018-10-30 13:59:29 +01:00
|
|
|
{
|
|
|
|
return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
|
|
|
|
}
|
|
|
|
|
2018-11-15 14:43:10 +01:00
|
|
|
class VFS;
|
|
|
|
|
|
|
|
class VFS {
|
2018-10-31 23:19:15 +01:00
|
|
|
AK_MAKE_ETERNAL
|
2018-10-10 11:53:07 +02:00
|
|
|
public:
|
2018-10-26 18:43:25 +02:00
|
|
|
class Mount {
|
|
|
|
public:
|
2018-11-15 17:13:10 +01:00
|
|
|
Mount(InodeIdentifier host, RetainPtr<FS>&&);
|
2018-10-26 18:43:25 +02:00
|
|
|
|
|
|
|
InodeIdentifier host() const { return m_host; }
|
|
|
|
InodeIdentifier guest() const { return m_guest; }
|
|
|
|
|
2018-11-15 17:13:10 +01:00
|
|
|
const FS& guest_fs() const { return *m_guest_fs; }
|
2018-10-26 18:43:25 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
InodeIdentifier m_host;
|
|
|
|
InodeIdentifier m_guest;
|
2018-11-15 17:13:10 +01:00
|
|
|
RetainPtr<FS> m_guest_fs;
|
2018-10-26 18:43:25 +02:00
|
|
|
};
|
|
|
|
|
2019-02-15 12:30:48 +01:00
|
|
|
[[gnu::pure]] static VFS& the();
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-11-15 14:43:10 +01:00
|
|
|
VFS();
|
|
|
|
~VFS();
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-11-15 17:13:10 +01:00
|
|
|
bool mount_root(RetainPtr<FS>&&);
|
|
|
|
bool mount(RetainPtr<FS>&&, const String& path);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-02-16 00:47:20 +01:00
|
|
|
RetainPtr<FileDescriptor> open(RetainPtr<Device>&&, int& error, int options);
|
2019-02-01 15:36:45 +01:00
|
|
|
RetainPtr<FileDescriptor> open(const String& path, int& error, int options, mode_t mode, Inode& base);
|
|
|
|
RetainPtr<FileDescriptor> create(const String& path, int& error, int options, mode_t mode, Inode& base);
|
2019-02-01 15:29:11 +01:00
|
|
|
bool mkdir(const String& path, mode_t mode, Inode& base, int& error);
|
2019-01-22 07:03:44 +01:00
|
|
|
bool unlink(const String& path, Inode& base, int& error);
|
2019-01-28 04:16:01 +01:00
|
|
|
bool rmdir(const String& path, Inode& base, int& error);
|
2019-01-29 04:55:08 +01:00
|
|
|
bool chmod(const String& path, mode_t, Inode& base, int& error);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-02-16 00:47:20 +01:00
|
|
|
void register_device(Device&);
|
|
|
|
void unregister_device(Device&);
|
2018-10-14 02:59:22 +02:00
|
|
|
|
2018-11-15 15:10:12 +01:00
|
|
|
size_t mount_count() const { return m_mounts.size(); }
|
|
|
|
void for_each_mount(Function<void(const Mount&)>) const;
|
2018-10-26 18:43:25 +02:00
|
|
|
|
2018-12-19 21:18:28 +01:00
|
|
|
String absolute_path(Inode&);
|
2019-01-31 06:13:55 +01:00
|
|
|
String absolute_path(InodeIdentifier);
|
2018-10-28 12:20:25 +01:00
|
|
|
|
2018-11-18 23:28:43 +01:00
|
|
|
InodeIdentifier root_inode_id() const;
|
2019-01-16 12:57:07 +01:00
|
|
|
Inode* root_inode() { return m_root_inode.ptr(); }
|
|
|
|
const Inode* root_inode() const { return m_root_inode.ptr(); }
|
2018-11-18 23:28:43 +01:00
|
|
|
|
2018-12-20 00:39:29 +01:00
|
|
|
void sync();
|
|
|
|
|
2019-02-16 00:47:20 +01:00
|
|
|
Device* get_device(unsigned major, unsigned minor);
|
2019-01-31 05:55:30 +01:00
|
|
|
|
2018-10-10 11:53:07 +02:00
|
|
|
private:
|
2018-11-07 11:37:54 +01:00
|
|
|
friend class FileDescriptor;
|
2018-10-24 12:43:52 +02:00
|
|
|
|
2018-12-19 21:18:28 +01:00
|
|
|
RetainPtr<Inode> get_inode(InodeIdentifier);
|
2018-11-13 23:44:54 +01:00
|
|
|
|
2018-11-15 14:43:10 +01:00
|
|
|
bool is_vfs_root(InodeIdentifier) const;
|
|
|
|
|
2018-12-19 21:18:28 +01:00
|
|
|
void traverse_directory_inode(Inode&, Function<bool(const FS::DirectoryEntry&)>);
|
2019-01-28 04:16:01 +01:00
|
|
|
InodeIdentifier resolve_path(const String& path, InodeIdentifier base, int& error, int options = 0, InodeIdentifier* parent_id = nullptr);
|
2018-12-21 17:45:42 +01:00
|
|
|
InodeIdentifier resolve_symbolic_link(InodeIdentifier base, Inode& symlink_inode, int& error);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2018-11-15 15:10:12 +01:00
|
|
|
Mount* find_mount_for_host(InodeIdentifier);
|
|
|
|
Mount* find_mount_for_guest(InodeIdentifier);
|
2018-10-10 11:53:07 +02:00
|
|
|
|
2019-01-16 12:57:07 +01:00
|
|
|
RetainPtr<Inode> m_root_inode;
|
2018-10-10 11:53:07 +02:00
|
|
|
Vector<OwnPtr<Mount>> m_mounts;
|
2019-02-16 00:47:20 +01:00
|
|
|
HashMap<dword, Device*> m_devices;
|
2018-10-10 11:53:07 +02:00
|
|
|
};
|
|
|
|
|