2018-10-10 06:53:07 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
|
#include <AK/RetainPtr.h>
|
2018-12-03 21:27:16 -02:00
|
|
|
#include <AK/AKString.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
#include <AK/Vector.h>
|
2018-10-24 07:43:52 -03:00
|
|
|
#include <AK/Function.h>
|
2018-10-10 06:53:07 -03:00
|
|
|
#include "InodeIdentifier.h"
|
2018-10-24 07:43:52 -03:00
|
|
|
#include "InodeMetadata.h"
|
|
|
|
|
#include "FileSystem.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
|
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
|
2018-10-28 10:11:51 -03:00
|
|
|
#define O_NOFOLLOW_NOERROR 0x4000000
|
|
|
|
|
|
2019-02-15 21:47:20 -02:00
|
|
|
class Device;
|
2018-11-07 08:37:54 -02:00
|
|
|
class FileDescriptor;
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-01-31 14:31:23 -02:00
|
|
|
inline constexpr dword encoded_device(unsigned major, unsigned minor)
|
2018-10-30 09:59:29 -03:00
|
|
|
{
|
|
|
|
|
return (minor & 0xff) | (major << 8) | ((minor & ~0xff) << 12);
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 11:43:10 -02:00
|
|
|
class VFS;
|
|
|
|
|
|
|
|
|
|
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:
|
2018-11-15 14:13:10 -02:00
|
|
|
Mount(InodeIdentifier host, RetainPtr<FS>&&);
|
2018-10-26 13:43:25 -03:00
|
|
|
|
|
|
|
|
InodeIdentifier host() const { return m_host; }
|
|
|
|
|
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
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
InodeIdentifier m_host;
|
|
|
|
|
InodeIdentifier m_guest;
|
2018-11-15 14:13:10 -02:00
|
|
|
RetainPtr<FS> m_guest_fs;
|
2018-10-26 13:43:25 -03:00
|
|
|
};
|
|
|
|
|
|
2019-02-15 09:30:48 -02:00
|
|
|
[[gnu::pure]] 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
|
|
|
|
2018-11-15 14:13:10 -02:00
|
|
|
bool mount_root(RetainPtr<FS>&&);
|
|
|
|
|
bool mount(RetainPtr<FS>&&, const String& path);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-03-06 18:14:31 -03:00
|
|
|
KResultOr<Retained<FileDescriptor>> open(RetainPtr<Device>&&, int options);
|
|
|
|
|
KResultOr<Retained<FileDescriptor>> open(const String& path, int options, mode_t mode, Inode& base);
|
|
|
|
|
KResultOr<Retained<FileDescriptor>> create(const String& path, int options, mode_t mode, Inode& base);
|
2019-02-25 16:47:56 -03:00
|
|
|
KResult mkdir(const String& path, mode_t mode, Inode& base);
|
2019-02-27 11:31:26 -03:00
|
|
|
KResult link(const String& old_path, const String& new_path, Inode& base);
|
2019-02-27 10:11:25 -03:00
|
|
|
KResult unlink(const String& path, Inode& base);
|
2019-03-01 21:50:34 -03:00
|
|
|
KResult symlink(const String& target, const String& linkpath, Inode& base);
|
2019-02-27 10:11:25 -03:00
|
|
|
KResult rmdir(const String& path, Inode& base);
|
2019-02-25 16:47:56 -03:00
|
|
|
KResult chmod(const String& path, mode_t, Inode& base);
|
2019-03-01 06:39:19 -03:00
|
|
|
KResult chmod(Inode&, mode_t);
|
2019-02-27 08:32:53 -03:00
|
|
|
KResult chown(const String& path, uid_t, gid_t, Inode& base);
|
2019-02-26 11:57:59 -03:00
|
|
|
KResult access(const String& path, int mode, Inode& base);
|
2019-03-01 20:11:08 -03:00
|
|
|
KResult stat(const String& path, int options, Inode& base, struct stat&);
|
2019-02-25 16:47:56 -03:00
|
|
|
KResult utime(const String& path, Inode& base, time_t atime, time_t mtime);
|
2019-04-07 18:35:26 -03:00
|
|
|
KResult rename(const String& oldpath, const String& newpath, Inode& base);
|
2019-03-01 19:54:07 -03:00
|
|
|
KResultOr<Retained<Inode>> open_directory(const String& path, Inode& base);
|
2018-10-10 06:53:07 -03:00
|
|
|
|
2019-02-15 21:47:20 -02:00
|
|
|
void register_device(Device&);
|
|
|
|
|
void unregister_device(Device&);
|
2018-10-13 21:59:22 -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
|
|
|
|
2019-03-06 18:30:13 -03:00
|
|
|
KResultOr<String> absolute_path(Inode&);
|
|
|
|
|
KResultOr<String> absolute_path(InodeIdentifier);
|
2018-10-28 08:20:25 -03:00
|
|
|
|
2018-11-18 20:28:43 -02:00
|
|
|
InodeIdentifier root_inode_id() const;
|
2019-01-16 09:57:07 -02:00
|
|
|
Inode* root_inode() { return m_root_inode.ptr(); }
|
|
|
|
|
const Inode* root_inode() const { return m_root_inode.ptr(); }
|
2018-11-18 20:28:43 -02:00
|
|
|
|
2018-12-19 21:39:29 -02:00
|
|
|
void sync();
|
|
|
|
|
|
2019-02-15 21:47:20 -02:00
|
|
|
Device* get_device(unsigned major, unsigned minor);
|
2019-01-31 02:55:30 -02:00
|
|
|
|
2018-10-10 06:53:07 -03:00
|
|
|
private:
|
2018-11-07 08:37:54 -02:00
|
|
|
friend class FileDescriptor;
|
2018-10-24 07:43:52 -03:00
|
|
|
|
2018-12-19 18:18:28 -02:00
|
|
|
RetainPtr<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&)>);
|
2019-02-25 16: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-03-01 20:11:08 -03:00
|
|
|
KResultOr<Retained<Inode>> resolve_path_to_inode(const String& path, Inode& base, RetainPtr<Inode>* parent_id = nullptr, int options = 0);
|
2019-02-25 16:47:56 -03:00
|
|
|
KResultOr<InodeIdentifier> resolve_symbolic_link(InodeIdentifier base, Inode& symlink_inode);
|
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-01-16 09:57:07 -02:00
|
|
|
RetainPtr<Inode> m_root_inode;
|
2018-10-10 06:53:07 -03:00
|
|
|
Vector<OwnPtr<Mount>> m_mounts;
|
2019-02-15 21:47:20 -02:00
|
|
|
HashMap<dword, Device*> m_devices;
|
2018-10-10 06:53:07 -03:00
|
|
|
};
|
|
|
|
|
|