Custody.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. namespace Kernel {
  14. // FIXME: Custody needs some locking.
  15. class Custody : public RefCounted<Custody> {
  16. MAKE_SLAB_ALLOCATED(Custody)
  17. public:
  18. static KResultOr<NonnullRefPtr<Custody>> create(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
  19. {
  20. auto custody = adopt_ref_if_nonnull(new Custody(parent, name, inode, mount_flags));
  21. if (!custody)
  22. return ENOMEM;
  23. return custody.release_nonnull();
  24. }
  25. ~Custody();
  26. Custody* parent() { return m_parent.ptr(); }
  27. const Custody* parent() const { return m_parent.ptr(); }
  28. Inode& inode() { return *m_inode; }
  29. const Inode& inode() const { return *m_inode; }
  30. const String& name() const { return m_name; }
  31. String absolute_path() const;
  32. int mount_flags() const { return m_mount_flags; }
  33. bool is_readonly() const;
  34. private:
  35. Custody(Custody* parent, const StringView& name, Inode&, int mount_flags);
  36. RefPtr<Custody> m_parent;
  37. String m_name;
  38. NonnullRefPtr<Inode> m_inode;
  39. int m_mount_flags { 0 };
  40. };
  41. }