Serenity Operating System
at master 57 lines 1.4 kB view raw
1/* 2 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#include <Kernel/FileSystem/Custody.h> 8#include <Kernel/FileSystem/FileSystem.h> 9#include <Kernel/FileSystem/Inode.h> 10#include <Kernel/FileSystem/Mount.h> 11 12namespace Kernel { 13 14Mount::Mount(FileSystem& guest_fs, Custody* host_custody, int flags) 15 : m_guest(guest_fs.root_inode()) 16 , m_guest_fs(guest_fs) 17 , m_host_custody(host_custody) 18 , m_flags(flags) 19{ 20} 21 22Mount::Mount(Inode& source, Custody& host_custody, int flags) 23 : m_guest(source) 24 , m_guest_fs(source.fs()) 25 , m_host_custody(host_custody) 26 , m_flags(flags) 27{ 28} 29 30ErrorOr<NonnullOwnPtr<KString>> Mount::absolute_path() const 31{ 32 return m_host_custody.with([&](auto& host_custody) -> ErrorOr<NonnullOwnPtr<KString>> { 33 if (!host_custody) 34 return KString::try_create("/"sv); 35 return host_custody->try_serialize_absolute_path(); 36 }); 37} 38 39RefPtr<Inode> Mount::host() 40{ 41 return m_host_custody.with([](auto& host_custody) -> RefPtr<Inode> { 42 if (!host_custody) 43 return nullptr; 44 return &host_custody->inode(); 45 }); 46} 47 48RefPtr<Inode const> Mount::host() const 49{ 50 return m_host_custody.with([](auto& host_custody) -> RefPtr<Inode const> { 51 if (!host_custody) 52 return nullptr; 53 return &host_custody->inode(); 54 }); 55} 56 57}