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