2018-10-10 06:53:07 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-05-31 10:36:49 -03:00
|
|
|
#include <AK/Badge.h>
|
2019-05-28 06:53:16 -03:00
|
|
|
#include <AK/Function.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
#include <AK/HashMap.h>
|
2019-07-24 04:15:33 -03:00
|
|
|
#include <AK/NonnullOwnPtrVector.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
#include <AK/OwnPtr.h>
|
2019-06-21 13:45:35 -03:00
|
|
|
#include <AK/RefPtr.h>
|
2020-01-11 12:25:26 -03:00
|
|
|
#include <AK/String.h>
|
2019-05-31 10:36:49 -03:00
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
|
|
|
|
#include <Kernel/FileSystem/InodeIdentifier.h>
|
|
|
|
|
#include <Kernel/FileSystem/InodeMetadata.h>
|
2019-02-25 16:47:56 -03:00
|
|
|
#include <Kernel/KResult.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-10-28 10:11:51 -03:00
|
|
|
#define O_RDONLY 0
|
|
|
|
|
#define O_WRONLY 1
|
|
|
|
|
#define O_RDWR 2
|
2020-01-11 12:33:35 -03:00
|
|
|
#define O_EXEC 4
|
2018-11-12 22:36:31 -02: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 10:11:51 -03:00
|
|
|
#define O_DIRECTORY 00200000
|
|
|
|
|
#define O_NOFOLLOW 00400000
|
2018-11-12 22:36:31 -02:00
|
|
|
#define O_CLOEXEC 02000000
|
2019-11-05 15:35:12 -03:00
|
|
|
#define O_DIRECT 04000000
|
2018-10-28 10:11:51 -03:00
|
|
|
#define O_NOFOLLOW_NOERROR 0x4000000
|
|
|
|
|
|
2020-01-11 12:45:38 -03:00
|
|
|
#define MS_NODEV 1
|
|
|
|
|
#define MS_NOEXEC 2
|
|
|
|
|
#define MS_NOSUID 4
|
|
|
|
|
#define MS_BIND 8
|
|
|
|
|
|
2019-05-30 12:46:08 -03:00
|
|
|
class Custody;
|
2019-02-15 21:47:20 -02:00
|
|
|
class Device;
|
2019-06-07 04:36:51 -03:00
|
|
|
class FileDescription;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2020-01-03 16:13:21 -03:00
|
|
|
struct UidAndGid {
|
|
|
|
|
uid_t uid;
|
|
|
|
|
gid_t gid;
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-15 11:43:10 -02:00
|
|
|
class VFS {
|
2018-10-31 19:19:15 -03:00
|
|
|
AK_MAKE_ETERNAL
|
2018-10-10 06:53:07 -03:00
|
|
|
public:
|
2018-10-26 13:43:25 -03:00
|
|
|
class Mount {
|
|
|
|
|
public:
|
2020-01-11 12:25:26 -03:00
|
|
|
Mount(FS&, Custody* host_custody, int flags);
|
2020-01-12 13:22:24 -03:00
|
|
|
Mount(Inode& source, Custody& host_custody, int flags);
|
2018-10-26 13:43:25 -03:00
|
|
|
|
2019-05-30 16:29:26 -03:00
|
|
|
InodeIdentifier host() const;
|
2018-10-26 13:43:25 -03:00
|
|
|
InodeIdentifier guest() const { return m_guest; }
|
|
|
|
|
|
2018-11-15 14:13:10 -02:00
|
|
|
const FS& guest_fs() const { return *m_guest_fs; }
|
2018-10-26 13:43:25 -03:00
|
|
|
|
2019-05-30 16:29:26 -03:00
|
|
|
String absolute_path() const;
|
|
|
|
|
|
2020-01-11 12:25:26 -03:00
|
|
|
int flags() const { return m_flags; }
|
|
|
|
|
|
2018-10-26 13:43:25 -03:00
|
|
|
private:
|
|
|
|
|
InodeIdentifier m_host;
|
|
|
|
|
InodeIdentifier m_guest;
|
2019-06-21 13:37:47 -03:00
|
|
|
NonnullRefPtr<FS> m_guest_fs;
|
|
|
|
|
RefPtr<Custody> m_host_custody;
|
2020-01-11 12:25:26 -03:00
|
|
|
int m_flags;
|
2018-10-26 13:43:25 -03:00
|
|
|
};
|
|
|
|
|
|
2019-07-16 08:44:41 -03:00
|
|
|
static VFS& the();
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-11-15 11:43:10 -02:00
|
|
|
VFS();
|
|
|
|
|
~VFS();
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2020-01-11 12:05:24 -03:00
|
|
|
bool mount_root(FS&);
|
2020-01-11 12:25:26 -03:00
|
|
|
KResult mount(FS&, Custody& mount_point, int flags);
|
2020-01-12 13:22:24 -03:00
|
|
|
KResult bind_mount(Custody& source, Custody& mount_point, int flags);
|
2019-08-17 09:24:50 -03:00
|
|
|
KResult unmount(InodeIdentifier guest_inode_id);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2020-01-03 16:13:21 -03:00
|
|
|
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
|
|
|
|
|
KResultOr<NonnullRefPtr<FileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> = {});
|
2019-05-30 13:58:59 -03:00
|
|
|
KResult mkdir(StringView path, mode_t mode, Custody& base);
|
|
|
|
|
KResult link(StringView old_path, StringView new_path, Custody& base);
|
|
|
|
|
KResult unlink(StringView path, Custody& base);
|
|
|
|
|
KResult symlink(StringView target, StringView linkpath, Custody& base);
|
|
|
|
|
KResult rmdir(StringView path, Custody& base);
|
|
|
|
|
KResult chmod(StringView path, mode_t, Custody& base);
|
2019-06-02 07:36:38 -03:00
|
|
|
KResult chmod(Inode&, mode_t);
|
2019-05-30 13:58:59 -03:00
|
|
|
KResult chown(StringView path, uid_t, gid_t, Custody& base);
|
2019-06-02 07:30:24 -03:00
|
|
|
KResult chown(Inode&, uid_t, gid_t);
|
2019-05-30 13:58:59 -03:00
|
|
|
KResult access(StringView path, int mode, Custody& base);
|
2019-08-02 14:23:23 -03:00
|
|
|
KResultOr<InodeMetadata> lookup_metadata(StringView path, Custody& base, int options = 0);
|
2019-05-30 13:58:59 -03:00
|
|
|
KResult utime(StringView path, Custody& base, time_t atime, time_t mtime);
|
|
|
|
|
KResult rename(StringView oldpath, StringView newpath, Custody& base);
|
|
|
|
|
KResult mknod(StringView path, mode_t, dev_t, Custody& base);
|
2019-06-21 13:37:47 -03:00
|
|
|
KResultOr<NonnullRefPtr<Custody>> open_directory(StringView path, Custody& base);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-11-15 12:10:12 -02:00
|
|
|
size_t mount_count() const { return m_mounts.size(); }
|
|
|
|
|
void for_each_mount(Function<void(const Mount&)>) const;
|
2018-10-26 13:43:25 -03:00
|
|
|
|
2018-11-18 20:28:43 -02:00
|
|
|
InodeIdentifier root_inode_id() const;
|
|
|
|
|
|
2018-12-19 21:39:29 -02:00
|
|
|
void sync();
|
|
|
|
|
|
2019-05-30 12:46:08 -03:00
|
|
|
Custody& root_custody();
|
2020-01-15 04:52:33 -03:00
|
|
|
KResultOr<NonnullRefPtr<Custody>> resolve_path(StringView path, Custody& base, RefPtr<Custody>* out_parent = nullptr, int options = 0, int symlink_recursion_level = 0);
|
2019-05-30 12:46:08 -03:00
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
private:
|
2019-06-07 04:36:51 -03:00
|
|
|
friend class FileDescription;
|
2018-10-24 07:43:52 -03:00
|
|
|
|
2019-06-21 13:37:47 -03:00
|
|
|
RefPtr<Inode> get_inode(InodeIdentifier);
|
2018-11-13 20:44:54 -02:00
|
|
|
|
2018-11-15 11:43:10 -02:00
|
|
|
bool is_vfs_root(InodeIdentifier) const;
|
|
|
|
|
|
2018-12-19 18:18:28 -02:00
|
|
|
void traverse_directory_inode(Inode&, Function<bool(const FS::DirectoryEntry&)>);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2018-11-15 12:10:12 -02:00
|
|
|
Mount* find_mount_for_host(InodeIdentifier);
|
|
|
|
|
Mount* find_mount_for_guest(InodeIdentifier);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-08-11 10:56:39 -03:00
|
|
|
Lock m_lock { "VFSLock" };
|
|
|
|
|
|
2019-06-21 13:37:47 -03:00
|
|
|
RefPtr<Inode> m_root_inode;
|
2020-01-11 12:05:24 -03:00
|
|
|
Vector<Mount> m_mounts;
|
2019-05-30 12:46:08 -03:00
|
|
|
|
2019-06-21 13:37:47 -03:00
|
|
|
RefPtr<Custody> m_root_custody;
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|