Custody.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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/IntrusiveList.h>
  8. #include <AK/RefCounted.h>
  9. #include <AK/RefPtr.h>
  10. #include <AK/String.h>
  11. #include <Kernel/API/KResult.h>
  12. #include <Kernel/Forward.h>
  13. #include <Kernel/Heap/SlabAllocator.h>
  14. #include <Kernel/KString.h>
  15. namespace Kernel {
  16. // FIXME: Custody needs some locking.
  17. class Custody : public RefCountedBase {
  18. MAKE_SLAB_ALLOCATED(Custody)
  19. public:
  20. bool unref() const;
  21. static KResultOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
  22. ~Custody();
  23. Custody* parent() { return m_parent.ptr(); }
  24. Custody const* parent() const { return m_parent.ptr(); }
  25. Inode& inode() { return *m_inode; }
  26. Inode const& inode() const { return *m_inode; }
  27. StringView name() const { return m_name->view(); }
  28. OwnPtr<KString> try_create_absolute_path() const;
  29. String absolute_path() const;
  30. int mount_flags() const { return m_mount_flags; }
  31. bool is_readonly() const;
  32. private:
  33. Custody(Custody* parent, NonnullOwnPtr<KString> name, Inode&, int mount_flags);
  34. RefPtr<Custody> m_parent;
  35. NonnullOwnPtr<KString> m_name;
  36. NonnullRefPtr<Inode> m_inode;
  37. int m_mount_flags { 0 };
  38. mutable IntrusiveListNode<Custody> m_all_custodies_list_node;
  39. public:
  40. using AllCustodiesList = IntrusiveList<Custody, RawPtr<Custody>, &Custody::m_all_custodies_list_node>;
  41. };
  42. }