Kernel: Rename VFS => VirtualFileSystem

This commit is contained in:
Andreas Kling 2021-07-11 00:25:24 +02:00
parent d53d9d3677
commit 0d39bd04d3
38 changed files with 124 additions and 124 deletions

View file

@ -46,7 +46,7 @@ CoreDump::CoreDump(NonnullRefPtr<Process> process, NonnullRefPtr<FileDescription
RefPtr<FileDescription> CoreDump::create_target_file(const Process& process, const String& output_path)
{
auto output_directory = KLexicalPath::dirname(output_path);
auto dump_directory = VFS::the().open_directory(output_directory, VFS::the().root_custody());
auto dump_directory = VirtualFileSystem::the().open_directory(output_directory, VirtualFileSystem::the().root_custody());
if (dump_directory.is_error()) {
dbgln("Can't find directory '{}' for core dump", output_directory);
return nullptr;
@ -56,7 +56,7 @@ RefPtr<FileDescription> CoreDump::create_target_file(const Process& process, con
dbgln("Refusing to put core dump in sketchy directory '{}'", output_directory);
return nullptr;
}
auto fd_or_error = VFS::the().open(
auto fd_or_error = VirtualFileSystem::the().open(
KLexicalPath::basename(output_path),
O_CREAT | O_WRONLY | O_EXCL,
S_IFREG, // We will enable reading from userspace when we finish generating the coredump file

View file

@ -237,7 +237,7 @@ KResultOr<size_t> FileDescription::get_dir_entries(UserOrKernelBuffer& output_bu
return true;
};
KResult result = VFS::the().traverse_directory_inode(*m_inode, [&flush_stream_to_output_buffer, &stream, this](auto& entry) {
KResult result = VirtualFileSystem::the().traverse_directory_inode(*m_inode, [&flush_stream_to_output_buffer, &stream, this](auto& entry) {
size_t serialized_size = sizeof(ino_t) + sizeof(u8) + sizeof(size_t) + sizeof(char) * entry.name.length();
if (serialized_size > stream.remaining()) {
if (!flush_stream_to_output_buffer()) {

View file

@ -113,7 +113,7 @@ public:
OwnPtr<FileDescriptionData>& data() { return m_data; }
void set_original_inode(Badge<VFS>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); }
void set_original_inode(Badge<VirtualFileSystem>, NonnullRefPtr<Inode>&& inode) { m_inode = move(inode); }
KResult truncate(u64);
@ -124,7 +124,7 @@ public:
FileBlockCondition& block_condition();
private:
friend class VFS;
friend class VirtualFileSystem;
explicit FileDescription(File&);
KResult attach();

View file

@ -86,7 +86,7 @@ KResultOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<C
auto& contents = contents_or.value();
auto path = StringView(contents->data(), contents->size());
return VFS::the().resolve_path(path, base, out_parent, options, symlink_recursion_level);
return VirtualFileSystem::the().resolve_path(path, base, out_parent, options, symlink_recursion_level);
}
Inode::Inode(FileSystem& fs, InodeIndex index)
@ -254,7 +254,7 @@ void Inode::did_delete_self()
KResult Inode::prepare_to_write_data()
{
// FIXME: It's a poor design that filesystems are expected to call this before writing out data.
// We should funnel everything through an interface at the VFS layer so this can happen from a single place.
// We should funnel everything through an interface at the VirtualFileSystem layer so this can happen from a single place.
Locker locker(m_lock);
if (fs().is_readonly())
return EROFS;

View file

@ -25,7 +25,7 @@ namespace Kernel {
class Inode : public RefCounted<Inode>
, public Weakable<Inode> {
friend class VFS;
friend class VirtualFileSystem;
friend class FileSystem;
public:

View file

@ -125,14 +125,14 @@ KResult InodeFile::chown(FileDescription& description, uid_t uid, gid_t gid)
{
VERIFY(description.inode() == m_inode);
VERIFY(description.custody());
return VFS::the().chown(*description.custody(), uid, gid);
return VirtualFileSystem::the().chown(*description.custody(), uid, gid);
}
KResult InodeFile::chmod(FileDescription& description, mode_t mode)
{
VERIFY(description.inode() == m_inode);
VERIFY(description.custody());
return VFS::the().chmod(*description.custody(), mode);
return VirtualFileSystem::the().chmod(*description.custody(), mode);
}
}

View file

@ -21,40 +21,40 @@
namespace Kernel {
static AK::Singleton<VFS> s_the;
static AK::Singleton<VirtualFileSystem> s_the;
static constexpr int symlink_recursion_limit { 5 }; // FIXME: increase?
static constexpr int root_mount_flags = MS_NODEV | MS_NOSUID | MS_RDONLY;
UNMAP_AFTER_INIT void VFS::initialize()
UNMAP_AFTER_INIT void VirtualFileSystem::initialize()
{
s_the.ensure_instance();
}
VFS& VFS::the()
VirtualFileSystem& VirtualFileSystem::the()
{
return *s_the;
}
UNMAP_AFTER_INIT VFS::VFS()
UNMAP_AFTER_INIT VirtualFileSystem::VirtualFileSystem()
{
}
UNMAP_AFTER_INIT VFS::~VFS()
UNMAP_AFTER_INIT VirtualFileSystem::~VirtualFileSystem()
{
}
InodeIdentifier VFS::root_inode_id() const
InodeIdentifier VirtualFileSystem::root_inode_id() const
{
VERIFY(m_root_inode);
return m_root_inode->identifier();
}
KResult VFS::mount(FileSystem& fs, Custody& mount_point, int flags)
KResult VirtualFileSystem::mount(FileSystem& fs, Custody& mount_point, int flags)
{
Locker locker(m_lock);
auto& inode = mount_point.inode();
dbgln("VFS: Mounting {} at {} (inode: {}) with flags {}",
dbgln("VirtualFileSystem: Mounting {} at {} (inode: {}) with flags {}",
fs.class_name(),
mount_point.try_create_absolute_path(),
inode.identifier(),
@ -65,22 +65,22 @@ KResult VFS::mount(FileSystem& fs, Custody& mount_point, int flags)
return KSuccess;
}
KResult VFS::bind_mount(Custody& source, Custody& mount_point, int flags)
KResult VirtualFileSystem::bind_mount(Custody& source, Custody& mount_point, int flags)
{
Locker locker(m_lock);
dbgln("VFS: Bind-mounting {} at {}", source.try_create_absolute_path(), mount_point.try_create_absolute_path());
dbgln("VirtualFileSystem: Bind-mounting {} at {}", source.try_create_absolute_path(), mount_point.try_create_absolute_path());
// FIXME: check that this is not already a mount point
Mount mount { source.inode(), mount_point, flags };
m_mounts.append(move(mount));
return KSuccess;
}
KResult VFS::remount(Custody& mount_point, int new_flags)
KResult VirtualFileSystem::remount(Custody& mount_point, int new_flags)
{
Locker locker(m_lock);
dbgln("VFS: Remounting {}", mount_point.try_create_absolute_path());
dbgln("VirtualFileSystem: Remounting {}", mount_point.try_create_absolute_path());
Mount* mount = find_mount_for_guest(mount_point.inode());
if (!mount)
@ -90,32 +90,32 @@ KResult VFS::remount(Custody& mount_point, int new_flags)
return KSuccess;
}
KResult VFS::unmount(Inode& guest_inode)
KResult VirtualFileSystem::unmount(Inode& guest_inode)
{
Locker locker(m_lock);
dbgln("VFS: unmount called with inode {}", guest_inode.identifier());
dbgln("VirtualFileSystem: unmount called with inode {}", guest_inode.identifier());
for (size_t i = 0; i < m_mounts.size(); ++i) {
auto& mount = m_mounts.at(i);
if (&mount.guest() == &guest_inode) {
if (auto result = mount.guest_fs().prepare_to_unmount(); result.is_error()) {
dbgln("VFS: Failed to unmount!");
dbgln("VirtualFileSystem: Failed to unmount!");
return result;
}
dbgln("VFS: found fs {} at mount index {}! Unmounting...", mount.guest_fs().fsid(), i);
dbgln("VirtualFileSystem: found fs {} at mount index {}! Unmounting...", mount.guest_fs().fsid(), i);
m_mounts.unstable_take(i);
return KSuccess;
}
}
dbgln("VFS: Nothing mounted on inode {}", guest_inode.identifier());
dbgln("VirtualFileSystem: Nothing mounted on inode {}", guest_inode.identifier());
return ENODEV;
}
bool VFS::mount_root(FileSystem& fs)
bool VirtualFileSystem::mount_root(FileSystem& fs)
{
if (m_root_inode) {
dmesgln("VFS: mount_root can't mount another root");
dmesgln("VirtualFileSystem: mount_root can't mount another root");
return false;
}
@ -123,12 +123,12 @@ bool VFS::mount_root(FileSystem& fs)
auto root_inode = fs.root_inode();
if (!root_inode->is_directory()) {
dmesgln("VFS: root inode ({}) for / is not a directory :(", root_inode->identifier());
dmesgln("VirtualFileSystem: root inode ({}) for / is not a directory :(", root_inode->identifier());
return false;
}
m_root_inode = move(root_inode);
dmesgln("VFS: mounted root from {} ({})", fs.class_name(), static_cast<FileBackedFS&>(fs).file_description().absolute_path());
dmesgln("VirtualFileSystem: mounted root from {} ({})", fs.class_name(), static_cast<FileBackedFS&>(fs).file_description().absolute_path());
m_mounts.append(move(mount));
@ -139,7 +139,7 @@ bool VFS::mount_root(FileSystem& fs)
return true;
}
auto VFS::find_mount_for_host(Inode& inode) -> Mount*
auto VirtualFileSystem::find_mount_for_host(Inode& inode) -> Mount*
{
for (auto& mount : m_mounts) {
if (mount.host() == &inode)
@ -148,7 +148,7 @@ auto VFS::find_mount_for_host(Inode& inode) -> Mount*
return nullptr;
}
auto VFS::find_mount_for_host(InodeIdentifier id) -> Mount*
auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount*
{
for (auto& mount : m_mounts) {
if (mount.host() && mount.host()->identifier() == id)
@ -157,7 +157,7 @@ auto VFS::find_mount_for_host(InodeIdentifier id) -> Mount*
return nullptr;
}
auto VFS::find_mount_for_guest(Inode& inode) -> Mount*
auto VirtualFileSystem::find_mount_for_guest(Inode& inode) -> Mount*
{
for (auto& mount : m_mounts) {
if (&mount.guest() == &inode)
@ -166,7 +166,7 @@ auto VFS::find_mount_for_guest(Inode& inode) -> Mount*
return nullptr;
}
auto VFS::find_mount_for_guest(InodeIdentifier id) -> Mount*
auto VirtualFileSystem::find_mount_for_guest(InodeIdentifier id) -> Mount*
{
for (auto& mount : m_mounts) {
if (mount.guest().identifier() == id)
@ -175,12 +175,12 @@ auto VFS::find_mount_for_guest(InodeIdentifier id) -> Mount*
return nullptr;
}
bool VFS::is_vfs_root(InodeIdentifier inode) const
bool VirtualFileSystem::is_vfs_root(InodeIdentifier inode) const
{
return inode == root_inode_id();
}
KResult VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(FileSystem::DirectoryEntryView const&)> callback)
KResult VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<bool(FileSystem::DirectoryEntryView const&)> callback)
{
return dir_inode.traverse_as_directory([&](auto& entry) {
InodeIdentifier resolved_inode;
@ -202,9 +202,9 @@ KResult VFS::traverse_directory_inode(Inode& dir_inode, Function<bool(FileSystem
});
}
KResult VFS::utime(StringView path, Custody& base, time_t atime, time_t mtime)
KResult VirtualFileSystem::utime(StringView path, Custody& base, time_t atime, time_t mtime)
{
auto custody_or_error = VFS::the().resolve_path(move(path), base);
auto custody_or_error = VirtualFileSystem::the().resolve_path(move(path), base);
if (custody_or_error.is_error())
return custody_or_error.error();
auto& custody = *custody_or_error.value();
@ -222,7 +222,7 @@ KResult VFS::utime(StringView path, Custody& base, time_t atime, time_t mtime)
return KSuccess;
}
KResultOr<InodeMetadata> VFS::lookup_metadata(StringView path, Custody& base, int options)
KResultOr<InodeMetadata> VirtualFileSystem::lookup_metadata(StringView path, Custody& base, int options)
{
auto custody_or_error = resolve_path(path, base, nullptr, options);
if (custody_or_error.is_error())
@ -230,7 +230,7 @@ KResultOr<InodeMetadata> VFS::lookup_metadata(StringView path, Custody& base, in
return custody_or_error.value()->inode().metadata();
}
KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner)
KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> owner)
{
if ((options & O_CREAT) && (options & O_DIRECTORY))
return EINVAL;
@ -333,7 +333,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
return description;
}
KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
KResult VirtualFileSystem::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
{
if (!is_regular_file(mode) && !is_block_device(mode) && !is_character_device(mode) && !is_fifo(mode) && !is_socket(mode))
return EINVAL;
@ -354,11 +354,11 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
return EROFS;
auto basename = KLexicalPath::basename(path);
dbgln("VFS::mknod: '{}' mode={} dev={} in {}", basename, mode, dev, parent_inode.identifier());
dbgln("VirtualFileSystem::mknod: '{}' mode={} dev={} in {}", basename, mode, dev, parent_inode.identifier());
return parent_inode.create_child(basename, mode, dev, current_process->euid(), current_process->egid()).result();
}
KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
KResultOr<NonnullRefPtr<FileDescription>> VirtualFileSystem::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
{
auto basename = KLexicalPath::basename(path);
auto parent_path = parent_custody.try_create_absolute_path();
@ -382,7 +382,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int optio
if (parent_custody.is_readonly())
return EROFS;
dbgln_if(VFS_DEBUG, "VFS::create: '{}' in {}", basename, parent_inode.identifier());
dbgln_if(VFS_DEBUG, "VirtualFileSystem::create: '{}' in {}", basename, parent_inode.identifier());
uid_t uid = owner.has_value() ? owner.value().uid : current_process->euid();
gid_t gid = owner.has_value() ? owner.value().gid : current_process->egid();
auto inode_or_error = parent_inode.create_child(basename, mode, 0, uid, gid);
@ -400,7 +400,7 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int optio
return description;
}
KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
KResult VirtualFileSystem::mkdir(StringView path, mode_t mode, Custody& base)
{
// Unlike in basically every other case, where it's only the last
// path component (the one being created) that is allowed not to
@ -425,11 +425,11 @@ KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)
return EROFS;
auto basename = KLexicalPath::basename(path);
dbgln_if(VFS_DEBUG, "VFS::mkdir: '{}' in {}", basename, parent_inode.identifier());
dbgln_if(VFS_DEBUG, "VirtualFileSystem::mkdir: '{}' in {}", basename, parent_inode.identifier());
return parent_inode.create_child(basename, S_IFDIR | mode, 0, current_process->euid(), current_process->egid()).result();
}
KResult VFS::access(StringView path, int mode, Custody& base)
KResult VirtualFileSystem::access(StringView path, int mode, Custody& base)
{
auto custody_or_error = resolve_path(path, base);
if (custody_or_error.is_error())
@ -455,7 +455,7 @@ KResult VFS::access(StringView path, int mode, Custody& base)
return KSuccess;
}
KResultOr<NonnullRefPtr<Custody>> VFS::open_directory(StringView path, Custody& base)
KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::open_directory(StringView path, Custody& base)
{
auto inode_or_error = resolve_path(path, base);
if (inode_or_error.is_error())
@ -469,7 +469,7 @@ KResultOr<NonnullRefPtr<Custody>> VFS::open_directory(StringView path, Custody&
return custody;
}
KResult VFS::chmod(Custody& custody, mode_t mode)
KResult VirtualFileSystem::chmod(Custody& custody, mode_t mode)
{
auto& inode = custody.inode();
@ -484,7 +484,7 @@ KResult VFS::chmod(Custody& custody, mode_t mode)
return inode.chmod(mode);
}
KResult VFS::chmod(StringView path, mode_t mode, Custody& base)
KResult VirtualFileSystem::chmod(StringView path, mode_t mode, Custody& base)
{
auto custody_or_error = resolve_path(path, base);
if (custody_or_error.is_error())
@ -493,7 +493,7 @@ KResult VFS::chmod(StringView path, mode_t mode, Custody& base)
return chmod(custody, mode);
}
KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
KResult VirtualFileSystem::rename(StringView old_path, StringView new_path, Custody& base)
{
RefPtr<Custody> old_parent_custody;
auto old_custody_or_error = resolve_path(old_path, base, &old_parent_custody, O_NOFOLLOW_NOERROR);
@ -566,7 +566,7 @@ KResult VFS::rename(StringView old_path, StringView new_path, Custody& base)
return KSuccess;
}
KResult VFS::chown(Custody& custody, uid_t a_uid, gid_t a_gid)
KResult VirtualFileSystem::chown(Custody& custody, uid_t a_uid, gid_t a_gid)
{
auto& inode = custody.inode();
auto metadata = inode.metadata();
@ -592,10 +592,10 @@ KResult VFS::chown(Custody& custody, uid_t a_uid, gid_t a_gid)
if (custody.is_readonly())
return EROFS;
dbgln_if(VFS_DEBUG, "VFS::chown(): inode {} <- uid={} gid={}", inode.identifier(), new_uid, new_gid);
dbgln_if(VFS_DEBUG, "VirtualFileSystem::chown(): inode {} <- uid={} gid={}", inode.identifier(), new_uid, new_gid);
if (metadata.is_setuid() || metadata.is_setgid()) {
dbgln_if(VFS_DEBUG, "VFS::chown(): Stripping SUID/SGID bits from {}", inode.identifier());
dbgln_if(VFS_DEBUG, "VirtualFileSystem::chown(): Stripping SUID/SGID bits from {}", inode.identifier());
if (auto result = inode.chmod(metadata.mode & ~(04000 | 02000)); result.is_error())
return result;
}
@ -603,7 +603,7 @@ KResult VFS::chown(Custody& custody, uid_t a_uid, gid_t a_gid)
return inode.chown(new_uid, new_gid);
}
KResult VFS::chown(StringView path, uid_t a_uid, gid_t a_gid, Custody& base)
KResult VirtualFileSystem::chown(StringView path, uid_t a_uid, gid_t a_gid, Custody& base)
{
auto custody_or_error = resolve_path(path, base);
if (custody_or_error.is_error())
@ -629,7 +629,7 @@ static bool hard_link_allowed(const Inode& inode)
return false;
}
KResult VFS::link(StringView old_path, StringView new_path, Custody& base)
KResult VirtualFileSystem::link(StringView old_path, StringView new_path, Custody& base)
{
auto old_custody_or_error = resolve_path(old_path, base);
if (old_custody_or_error.is_error())
@ -665,7 +665,7 @@ KResult VFS::link(StringView old_path, StringView new_path, Custody& base)
return parent_inode.add_child(old_inode, KLexicalPath::basename(new_path), old_inode.mode());
}
KResult VFS::unlink(StringView path, Custody& base)
KResult VirtualFileSystem::unlink(StringView path, Custody& base)
{
RefPtr<Custody> parent_custody;
auto custody_or_error = resolve_path(path, base, &parent_custody, O_NOFOLLOW_NOERROR | O_UNLINK_INTERNAL);
@ -701,7 +701,7 @@ KResult VFS::unlink(StringView path, Custody& base)
return KSuccess;
}
KResult VFS::symlink(StringView target, StringView linkpath, Custody& base)
KResult VirtualFileSystem::symlink(StringView target, StringView linkpath, Custody& base)
{
RefPtr<Custody> parent_custody;
auto existing_custody_or_error = resolve_path(linkpath, base, &parent_custody);
@ -719,7 +719,7 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base)
return EROFS;
auto basename = KLexicalPath::basename(linkpath);
dbgln_if(VFS_DEBUG, "VFS::symlink: '{}' (-> '{}') in {}", basename, target, parent_inode.identifier());
dbgln_if(VFS_DEBUG, "VirtualFileSystem::symlink: '{}' (-> '{}') in {}", basename, target, parent_inode.identifier());
auto inode_or_error = parent_inode.create_child(basename, S_IFLNK | 0644, 0, current_process->euid(), current_process->egid());
if (inode_or_error.is_error())
return inode_or_error.error();
@ -731,7 +731,7 @@ KResult VFS::symlink(StringView target, StringView linkpath, Custody& base)
return KSuccess;
}
KResult VFS::rmdir(StringView path, Custody& base)
KResult VirtualFileSystem::rmdir(StringView path, Custody& base)
{
RefPtr<Custody> parent_custody;
auto custody_or_error = resolve_path(path, base, &parent_custody);
@ -780,7 +780,7 @@ KResult VFS::rmdir(StringView path, Custody& base)
return parent_inode.remove_child(KLexicalPath::basename(path));
}
VFS::Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags)
VirtualFileSystem::Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags)
: m_guest(guest_fs.root_inode())
, m_guest_fs(guest_fs)
, m_host_custody(host_custody)
@ -788,7 +788,7 @@ VFS::Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags)
{
}
VFS::Mount::Mount(Inode& source, Custody& host_custody, int flags)
VirtualFileSystem::Mount::Mount(Inode& source, Custody& host_custody, int flags)
: m_guest(source)
, m_guest_fs(source.fs())
, m_host_custody(host_custody)
@ -796,45 +796,45 @@ VFS::Mount::Mount(Inode& source, Custody& host_custody, int flags)
{
}
String VFS::Mount::absolute_path() const
String VirtualFileSystem::Mount::absolute_path() const
{
if (!m_host_custody)
return "/";
return m_host_custody->absolute_path();
}
Inode* VFS::Mount::host()
Inode* VirtualFileSystem::Mount::host()
{
if (!m_host_custody)
return nullptr;
return &m_host_custody->inode();
}
const Inode* VFS::Mount::host() const
const Inode* VirtualFileSystem::Mount::host() const
{
if (!m_host_custody)
return nullptr;
return &m_host_custody->inode();
}
void VFS::for_each_mount(Function<void(const Mount&)> callback) const
void VirtualFileSystem::for_each_mount(Function<void(const Mount&)> callback) const
{
for (auto& mount : m_mounts) {
callback(mount);
}
}
void VFS::sync()
void VirtualFileSystem::sync()
{
FileSystem::sync();
}
Custody& VFS::root_custody()
Custody& VirtualFileSystem::root_custody()
{
return *m_root_custody;
}
UnveilNode const& VFS::find_matching_unveiled_path(StringView path)
UnveilNode const& VirtualFileSystem::find_matching_unveiled_path(StringView path)
{
VERIFY(Process::current()->veil_state() != VeilState::None);
auto& unveil_root = Process::current()->unveiled_paths();
@ -843,7 +843,7 @@ UnveilNode const& VFS::find_matching_unveiled_path(StringView path)
return unveil_root.traverse_until_last_accessible_node(path_parts.begin(), path_parts.end());
}
KResult VFS::validate_path_against_process_veil(Custody const& custody, int options)
KResult VirtualFileSystem::validate_path_against_process_veil(Custody const& custody, int options)
{
if (Process::current()->veil_state() == VeilState::None)
return KSuccess;
@ -853,7 +853,7 @@ KResult VFS::validate_path_against_process_veil(Custody const& custody, int opti
return validate_path_against_process_veil(absolute_path->view(), options);
}
KResult VFS::validate_path_against_process_veil(StringView path, int options)
KResult VirtualFileSystem::validate_path_against_process_veil(StringView path, int options)
{
if (Process::current()->veil_state() == VeilState::None)
return KSuccess;
@ -918,7 +918,7 @@ KResult VFS::validate_path_against_process_veil(StringView path, int options)
return KSuccess;
}
KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path(StringView path, Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level)
KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path(StringView path, Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level)
{
auto custody_or_error = resolve_path_without_veil(path, base, out_parent, options, symlink_recursion_level);
if (custody_or_error.is_error())
@ -946,7 +946,7 @@ static bool safe_to_follow_symlink(const Inode& inode, const InodeMetadata& pare
return false;
}
KResultOr<NonnullRefPtr<Custody>> VFS::resolve_path_without_veil(StringView path, Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level)
KResultOr<NonnullRefPtr<Custody>> VirtualFileSystem::resolve_path_without_veil(StringView path, Custody& base, RefPtr<Custody>* out_parent, int options, int symlink_recursion_level)
{
if (symlink_recursion_level >= symlink_recursion_limit)
return ELOOP;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -30,7 +30,7 @@ struct UidAndGid {
gid_t gid;
};
class VFS {
class VirtualFileSystem {
AK_MAKE_ETERNAL
public:
class Mount {
@ -59,10 +59,10 @@ public:
};
static void initialize();
static VFS& the();
static VirtualFileSystem& the();
VFS();
~VFS();
VirtualFileSystem();
~VirtualFileSystem();
bool mount_root(FileSystem&);
KResult mount(FileSystem&, Custody& mount_point, int flags);

View file

@ -53,7 +53,7 @@ class TTY;
class Thread;
class UDPSocket;
class UserOrKernelBuffer;
class VFS;
class VirtualFileSystem;
class VMObject;
class WaitQueue;
class WorkQueue;

View file

@ -339,7 +339,7 @@ private:
virtual bool output(KBufferBuilder& builder) override
{
JsonArraySerializer array { builder };
VFS::the().for_each_mount([&array](auto& mount) {
VirtualFileSystem::the().for_each_mount([&array](auto& mount) {
auto& fs = mount.guest_fs();
auto fs_object = array.add_object();
fs_object.add("class_name", fs.class_name());

View file

@ -166,7 +166,7 @@ void dump_backtrace()
UNMAP_AFTER_INIT void load_kernel_symbol_table()
{
auto result = VFS::the().open("/res/kernel.map", O_RDONLY, 0, VFS::the().root_custody());
auto result = VirtualFileSystem::the().open("/res/kernel.map", O_RDONLY, 0, VirtualFileSystem::the().root_custody());
if (!result.is_error()) {
auto description = result.value();
auto buffer = description->read_entire_file();

View file

@ -126,7 +126,7 @@ KResult LocalSocket::bind(Userspace<const sockaddr*> user_address, socklen_t add
mode_t mode = S_IFSOCK | (m_prebind_mode & 0777);
UidAndGid owner { m_prebind_uid, m_prebind_gid };
auto result = VFS::the().open(path, O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current()->current_directory(), owner);
auto result = VirtualFileSystem::the().open(path, O_CREAT | O_EXCL | O_NOFOLLOW_NOERROR, mode, Process::current()->current_directory(), owner);
if (result.is_error()) {
if (result.error() == -EEXIST)
return EADDRINUSE;
@ -168,7 +168,7 @@ KResult LocalSocket::connect(FileDescription& description, Userspace<const socka
dbgln_if(LOCAL_SOCKET_DEBUG, "LocalSocket({}) connect({})", this, safe_address);
auto description_or_error = VFS::the().open(safe_address, O_RDWR, 0, Process::current()->current_directory());
auto description_or_error = VirtualFileSystem::the().open(safe_address, O_RDWR, 0, Process::current()->current_directory());
if (description_or_error.is_error())
return ECONNREFUSED;

View file

@ -153,7 +153,7 @@ RefPtr<Process> Process::create_user_process(RefPtr<Thread>& first_thread, const
}
if (!cwd)
cwd = VFS::the().root_custody();
cwd = VirtualFileSystem::the().root_custody();
auto process = Process::create(first_thread, parts.take_last(), uid, gid, parent_pid, false, move(cwd), nullptr, tty);
if (!first_thread)
@ -488,7 +488,7 @@ siginfo_t Process::wait_info()
Custody& Process::current_directory()
{
if (!m_cwd)
m_cwd = VFS::the().root_custody();
m_cwd = VirtualFileSystem::the().root_custody();
return *m_cwd;
}
@ -526,7 +526,7 @@ bool Process::dump_perfcore()
VERIFY(is_dumpable());
VERIFY(m_perf_event_buffer);
dbgln("Generating perfcore for pid: {}", pid().value());
auto description_or_error = VFS::the().open(String::formatted("perfcore.{}", pid().value()), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() });
auto description_or_error = VirtualFileSystem::the().open(String::formatted("perfcore.{}", pid().value()), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { uid(), gid() });
if (description_or_error.is_error())
return false;
auto& description = description_or_error.value();
@ -742,7 +742,7 @@ void Process::FileDescriptionAndFlags::set(NonnullRefPtr<FileDescription>&& desc
Custody& Process::root_directory()
{
if (!m_root_directory)
m_root_directory = VFS::the().root_custody();
m_root_directory = VirtualFileSystem::the().root_custody();
return *m_root_directory;
}

View file

@ -16,7 +16,7 @@ KResultOr<FlatPtr> Process::sys$access(Userspace<const char*> user_path, size_t
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().access(path.value()->view(), mode, current_directory());
return VirtualFileSystem::the().access(path.value()->view(), mode, current_directory());
}
}

View file

@ -17,7 +17,7 @@ KResultOr<FlatPtr> Process::sys$chdir(Userspace<const char*> user_path, size_t p
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
auto directory_or_error = VFS::the().open_directory(path.value()->view(), current_directory());
auto directory_or_error = VirtualFileSystem::the().open_directory(path.value()->view(), current_directory());
if (directory_or_error.is_error())
return directory_or_error.error();
m_cwd = *directory_or_error.value();

View file

@ -17,7 +17,7 @@ KResultOr<FlatPtr> Process::sys$chmod(Userspace<const char*> user_path, size_t p
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().chmod(path.value()->view(), mode, current_directory());
return VirtualFileSystem::the().chmod(path.value()->view(), mode, current_directory());
}
KResultOr<FlatPtr> Process::sys$fchmod(int fd, mode_t mode)

View file

@ -27,7 +27,7 @@ KResultOr<FlatPtr> Process::sys$chown(Userspace<const Syscall::SC_chown_params*>
auto path = get_syscall_path_argument(params.path);
if (path.is_error())
return path.error();
return VFS::the().chown(path.value()->view(), params.uid, params.gid, current_directory());
return VirtualFileSystem::the().chown(path.value()->view(), params.uid, params.gid, current_directory());
}
}

View file

@ -19,7 +19,7 @@ KResultOr<FlatPtr> Process::sys$chroot(Userspace<const char*> user_path, size_t
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
auto directory_or_error = VFS::the().open_directory(path.value()->view(), current_directory());
auto directory_or_error = VirtualFileSystem::the().open_directory(path.value()->view(), current_directory());
if (directory_or_error.is_error())
return directory_or_error.error();
auto directory = directory_or_error.value();

View file

@ -762,7 +762,7 @@ KResultOr<RefPtr<FileDescription>> Process::find_elf_interpreter_for_executable(
if (!interpreter_path.is_empty()) {
dbgln_if(EXEC_DEBUG, "exec({}): Using program interpreter {}", path, interpreter_path);
auto interp_result = VFS::the().open(interpreter_path, O_EXEC, 0, current_directory());
auto interp_result = VirtualFileSystem::the().open(interpreter_path, O_EXEC, 0, current_directory());
if (interp_result.is_error()) {
dbgln("exec({}): Unable to open program interpreter {}", path, interpreter_path);
return interp_result.error();
@ -838,7 +838,7 @@ KResult Process::exec(String path, Vector<String> arguments, Vector<String> envi
// * ET_EXEC binary that just gets loaded
// * ET_DYN binary that requires a program interpreter
//
auto file_or_error = VFS::the().open(path, O_EXEC, 0, current_directory());
auto file_or_error = VirtualFileSystem::the().open(path, O_EXEC, 0, current_directory());
if (file_or_error.is_error())
return file_or_error.error();
auto description = file_or_error.release_value();

View file

@ -59,7 +59,7 @@ KResultOr<FlatPtr> Process::sys$inode_watcher_add_watch(Userspace<const Syscall:
if (path.is_error())
return path.error();
auto custody_or_error = VFS::the().resolve_path(path.value()->view(), current_directory());
auto custody_or_error = VirtualFileSystem::the().resolve_path(path.value()->view(), current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();

View file

@ -22,7 +22,7 @@ KResultOr<FlatPtr> Process::sys$link(Userspace<const Syscall::SC_link_params*> u
auto new_path = copy_string_from_user(params.new_path);
if (new_path.is_null())
return EFAULT;
return VFS::the().link(old_path, new_path, current_directory());
return VirtualFileSystem::the().link(old_path, new_path, current_directory());
}
KResultOr<FlatPtr> Process::sys$symlink(Userspace<const Syscall::SC_symlink_params*> user_params)
@ -37,7 +37,7 @@ KResultOr<FlatPtr> Process::sys$symlink(Userspace<const Syscall::SC_symlink_para
auto linkpath = get_syscall_path_argument(params.linkpath);
if (linkpath.is_error())
return linkpath.error();
return VFS::the().symlink(target.value()->view(), linkpath.value()->view(), current_directory());
return VirtualFileSystem::the().symlink(target.value()->view(), linkpath.value()->view(), current_directory());
}
}

View file

@ -16,6 +16,6 @@ KResultOr<FlatPtr> Process::sys$mkdir(Userspace<const char*> user_path, size_t p
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().mkdir(path.value()->view(), mode & ~umask(), current_directory());
return VirtualFileSystem::the().mkdir(path.value()->view(), mode & ~umask(), current_directory());
}
}

View file

@ -21,7 +21,7 @@ KResultOr<FlatPtr> Process::sys$mknod(Userspace<const Syscall::SC_mknod_params*>
auto path = get_syscall_path_argument(params.path);
if (path.is_error())
return path.error();
return VFS::the().mknod(path.value()->view(), params.mode & ~umask(), params.dev, current_directory());
return VirtualFileSystem::the().mknod(path.value()->view(), params.mode & ~umask(), params.dev, current_directory());
}
}

View file

@ -25,7 +25,7 @@ KResultOr<FlatPtr> Process::sys$module_load(Userspace<const char*> user_path, si
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
auto description_or_error = VFS::the().open(path.value()->view(), O_RDONLY, 0, current_directory());
auto description_or_error = VirtualFileSystem::the().open(path.value()->view(), O_RDONLY, 0, current_directory());
if (description_or_error.is_error())
return description_or_error.error();
auto& description = description_or_error.value();

View file

@ -42,7 +42,7 @@ KResultOr<FlatPtr> Process::sys$mount(Userspace<const Syscall::SC_mount_params*>
else
dbgln("mount {} @ {}", fs_type, target);
auto custody_or_error = VFS::the().resolve_path(target, current_directory());
auto custody_or_error = VirtualFileSystem::the().resolve_path(target, current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();
@ -50,7 +50,7 @@ KResultOr<FlatPtr> Process::sys$mount(Userspace<const Syscall::SC_mount_params*>
if (params.flags & MS_REMOUNT) {
// We're not creating a new mount, we're updating an existing one!
return VFS::the().remount(target_custody, params.flags & ~MS_REMOUNT);
return VirtualFileSystem::the().remount(target_custody, params.flags & ~MS_REMOUNT);
}
if (params.flags & MS_BIND) {
@ -61,7 +61,7 @@ KResultOr<FlatPtr> Process::sys$mount(Userspace<const Syscall::SC_mount_params*>
// We only support bind-mounting inodes, not arbitrary files.
return ENODEV;
}
return VFS::the().bind_mount(*description->custody(), target_custody, params.flags);
return VirtualFileSystem::the().bind_mount(*description->custody(), target_custody, params.flags);
}
RefPtr<FileSystem> fs;
@ -106,7 +106,7 @@ KResultOr<FlatPtr> Process::sys$mount(Userspace<const Syscall::SC_mount_params*>
return ENODEV;
}
auto result = VFS::the().mount(fs.release_nonnull(), target_custody, params.flags);
auto result = VirtualFileSystem::the().mount(fs.release_nonnull(), target_custody, params.flags);
if (!description.is_null())
dbgln("mount: successfully mounted {} on {}", description->absolute_path(), target);
else
@ -125,12 +125,12 @@ KResultOr<FlatPtr> Process::sys$umount(Userspace<const char*> user_mountpoint, s
if (mountpoint.is_error())
return mountpoint.error();
auto custody_or_error = VFS::the().resolve_path(mountpoint.value()->view(), current_directory());
auto custody_or_error = VirtualFileSystem::the().resolve_path(mountpoint.value()->view(), current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();
auto& guest_inode = custody_or_error.value()->inode();
return VFS::the().unmount(guest_inode);
return VirtualFileSystem::the().unmount(guest_inode);
}
}

View file

@ -62,7 +62,7 @@ KResultOr<FlatPtr> Process::sys$open(Userspace<const Syscall::SC_open_params*> u
base = base_description->custody();
}
auto result = VFS::the().open(path.value()->view(), options, mode & ~umask(), *base);
auto result = VirtualFileSystem::the().open(path.value()->view(), options, mode & ~umask(), *base);
if (result.is_error())
return result.error();
auto description = result.value();

View file

@ -23,7 +23,7 @@ KResultOr<FlatPtr> Process::sys$readlink(Userspace<const Syscall::SC_readlink_pa
if (path.is_error())
return path.error();
auto result = VFS::the().open(path.value()->view(), O_RDONLY | O_NOFOLLOW_NOERROR, 0, current_directory());
auto result = VirtualFileSystem::the().open(path.value()->view(), O_RDONLY | O_NOFOLLOW_NOERROR, 0, current_directory());
if (result.is_error())
return result.error();
auto description = result.value();

View file

@ -23,7 +23,7 @@ KResultOr<FlatPtr> Process::sys$realpath(Userspace<const Syscall::SC_realpath_pa
if (path.is_error())
return path.error();
auto custody_or_error = VFS::the().resolve_path(path.value()->view(), current_directory());
auto custody_or_error = VirtualFileSystem::the().resolve_path(path.value()->view(), current_directory());
if (custody_or_error.is_error())
return custody_or_error.error();
auto& custody = custody_or_error.value();

View file

@ -22,7 +22,7 @@ KResultOr<FlatPtr> Process::sys$rename(Userspace<const Syscall::SC_rename_params
auto new_path = get_syscall_path_argument(params.new_path);
if (new_path.is_error())
return new_path.error();
return VFS::the().rename(old_path.value()->view(), new_path.value()->view(), current_directory());
return VirtualFileSystem::the().rename(old_path.value()->view(), new_path.value()->view(), current_directory());
}
}

View file

@ -16,7 +16,7 @@ KResultOr<FlatPtr> Process::sys$rmdir(Userspace<const char*> user_path, size_t p
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().rmdir(path.value()->view(), current_directory());
return VirtualFileSystem::the().rmdir(path.value()->view(), current_directory());
}
}

View file

@ -47,7 +47,7 @@ KResultOr<FlatPtr> Process::sys$stat(Userspace<const Syscall::SC_stat_params*> u
return EINVAL;
base = base_description->custody();
}
auto metadata_or_error = VFS::the().lookup_metadata(path.value()->view(), *base, params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR);
auto metadata_or_error = VirtualFileSystem::the().lookup_metadata(path.value()->view(), *base, params.follow_symlinks ? 0 : O_NOFOLLOW_NOERROR);
if (metadata_or_error.is_error())
return metadata_or_error.error();
stat statbuf;

View file

@ -13,7 +13,7 @@ namespace Kernel {
KResultOr<FlatPtr> Process::do_statvfs(String path, statvfs* buf)
{
auto custody_or_error = VFS::the().resolve_path(path, current_directory(), nullptr, 0);
auto custody_or_error = VirtualFileSystem::the().resolve_path(path, current_directory(), nullptr, 0);
if (custody_or_error.is_error())
return custody_or_error.error();
@ -42,7 +42,7 @@ KResultOr<FlatPtr> Process::do_statvfs(String path, statvfs* buf)
Custody* current_custody = custody;
while (current_custody) {
VFS::the().for_each_mount([&kernelbuf, &current_custody](auto& mount) {
VirtualFileSystem::the().for_each_mount([&kernelbuf, &current_custody](auto& mount) {
if (current_custody) {
if (&current_custody->inode() == &mount.guest()) {
int mountflags = mount.flags();

View file

@ -12,7 +12,7 @@ namespace Kernel {
KResultOr<FlatPtr> Process::sys$sync()
{
REQUIRE_PROMISE(stdio);
VFS::the().sync();
VirtualFileSystem::the().sync();
return 0;
}

View file

@ -16,7 +16,7 @@ KResultOr<FlatPtr> Process::sys$unlink(Userspace<const char*> user_path, size_t
auto path = get_syscall_path_argument(user_path, path_length);
if (path.is_error())
return path.error();
return VFS::the().unlink(path.value()->view(), current_directory());
return VirtualFileSystem::the().unlink(path.value()->view(), current_directory());
}
}

View file

@ -87,7 +87,7 @@ KResultOr<FlatPtr> Process::sys$unveil(Userspace<const Syscall::SC_unveil_params
// If this case is encountered, the parent node of the path is returned and the custody of that inode is used instead.
RefPtr<Custody> parent_custody; // Parent inode in case of ENOENT
OwnPtr<KString> new_unveiled_path;
auto custody_or_error = VFS::the().resolve_path_without_veil(path.view(), root_directory(), &parent_custody);
auto custody_or_error = VirtualFileSystem::the().resolve_path_without_veil(path.view(), root_directory(), &parent_custody);
if (!custody_or_error.is_error()) {
new_unveiled_path = custody_or_error.value()->try_create_absolute_path();
if (!new_unveiled_path)

View file

@ -25,7 +25,7 @@ KResultOr<FlatPtr> Process::sys$utime(Userspace<const char*> user_path, size_t p
// Not a bug!
buf = { now, now };
}
return VFS::the().utime(path.value()->view(), current_directory(), buf.actime, buf.modtime);
return VirtualFileSystem::the().utime(path.value()->view(), current_directory(), buf.actime, buf.modtime);
}
}

View file

@ -18,7 +18,7 @@ UNMAP_AFTER_INIT void SyncTask::spawn()
Process::create_kernel_process(syncd_thread, "SyncTask", [] {
dbgln("SyncTask is running");
for (;;) {
VFS::the().sync();
VirtualFileSystem::the().sync();
(void)Thread::current()->sleep(Time::from_seconds(1));
}
});

View file

@ -148,7 +148,7 @@ extern "C" [[noreturn]] UNMAP_AFTER_INIT void init()
PCI::initialize();
PCISerialDevice::detect();
VFS::initialize();
VirtualFileSystem::initialize();
dmesgln("Starting SerenityOS...");
@ -252,11 +252,11 @@ void init_stage2(void*)
SB16::detect();
StorageManagement::initialize(kernel_command_line().root_device(), kernel_command_line().is_force_pio());
if (!VFS::the().mount_root(StorageManagement::the().root_filesystem())) {
PANIC("VFS::mount_root failed");
if (!VirtualFileSystem::the().mount_root(StorageManagement::the().root_filesystem())) {
PANIC("VirtualFileSystem::mount_root failed");
}
Process::current()->set_root_directory(VFS::the().root_custody());
Process::current()->set_root_directory(VirtualFileSystem::the().root_custody());
load_kernel_symbol_table();