Mount.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2018-2023, 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(NonnullRefPtr<FileSystem> guest_fs, RefPtr<Custody> host_custody, int flags)
  12. : m_guest_fs(move(guest_fs))
  13. , m_guest(m_guest_fs->root_inode())
  14. , m_host_custody(move(host_custody))
  15. , m_flags(flags)
  16. {
  17. }
  18. Mount::Mount(NonnullRefPtr<Inode> source, NonnullRefPtr<Custody> host_custody, int flags)
  19. : m_guest_fs(source->fs())
  20. , m_guest(move(source))
  21. , m_host_custody(move(host_custody))
  22. , m_flags(flags)
  23. {
  24. }
  25. ErrorOr<NonnullOwnPtr<KString>> Mount::absolute_path() const
  26. {
  27. if (!m_host_custody)
  28. return KString::try_create("/"sv);
  29. return m_host_custody->try_serialize_absolute_path();
  30. }
  31. RefPtr<Inode> Mount::host()
  32. {
  33. if (!m_host_custody)
  34. return nullptr;
  35. return m_host_custody->inode();
  36. }
  37. RefPtr<Inode const> Mount::host() const
  38. {
  39. if (!m_host_custody)
  40. return nullptr;
  41. return m_host_custody->inode();
  42. }
  43. RefPtr<Custody const> Mount::host_custody() const
  44. {
  45. return m_host_custody;
  46. }
  47. RefPtr<Custody> Mount::host_custody()
  48. {
  49. return m_host_custody;
  50. }
  51. }