Custody.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefCounted.h>
  8. #include <AK/RefPtr.h>
  9. #include <AK/String.h>
  10. #include <Kernel/Forward.h>
  11. #include <Kernel/Heap/SlabAllocator.h>
  12. #include <Kernel/KResult.h>
  13. #include <Kernel/KString.h>
  14. namespace Kernel {
  15. // FIXME: Custody needs some locking.
  16. class Custody : public RefCounted<Custody> {
  17. MAKE_SLAB_ALLOCATED(Custody)
  18. public:
  19. static KResultOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
  20. ~Custody();
  21. Custody* parent() { return m_parent.ptr(); }
  22. Custody const* parent() const { return m_parent.ptr(); }
  23. Inode& inode() { return *m_inode; }
  24. Inode const& inode() const { return *m_inode; }
  25. StringView name() const { return m_name->view(); }
  26. OwnPtr<KString> try_create_absolute_path() const;
  27. String absolute_path() const;
  28. int mount_flags() const { return m_mount_flags; }
  29. bool is_readonly() const;
  30. private:
  31. Custody(Custody* parent, NonnullOwnPtr<KString> name, Inode&, int mount_flags);
  32. RefPtr<Custody> m_parent;
  33. NonnullOwnPtr<KString> m_name;
  34. NonnullRefPtr<Inode> m_inode;
  35. int m_mount_flags { 0 };
  36. };
  37. }