Mount.cpp 1.4 KB

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