2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2022-08-17 15:30:21 -03:00
|
|
|
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-05-30 12:46:08 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-11-07 20:51:39 -03:00
|
|
|
#include <AK/Error.h>
|
2021-08-15 14:02:48 -03:00
|
|
|
#include <AK/IntrusiveList.h>
|
2022-08-20 20:04:35 -03:00
|
|
|
#include <AK/RefPtr.h>
|
2020-02-15 22:15:33 -03:00
|
|
|
#include <Kernel/Forward.h>
|
2021-05-28 06:21:00 -03:00
|
|
|
#include <Kernel/KString.h>
|
2021-12-28 19:23:25 -03:00
|
|
|
#include <Kernel/Library/ListedRefCounted.h>
|
2022-08-17 15:30:21 -03:00
|
|
|
#include <Kernel/Locking/SpinlockProtected.h>
|
2019-05-30 12:46:08 -03:00
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2022-08-20 20:04:35 -03:00
|
|
|
class Custody final : public ListedRefCounted<Custody, LockType::Spinlock> {
|
2019-05-30 12:46:08 -03:00
|
|
|
public:
|
2022-08-20 20:04:35 -03:00
|
|
|
static ErrorOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
|
2019-05-30 12:46:08 -03:00
|
|
|
|
|
|
|
|
~Custody();
|
|
|
|
|
|
2022-08-20 20:04:35 -03:00
|
|
|
RefPtr<Custody> parent() { return m_parent; }
|
|
|
|
|
RefPtr<Custody const> parent() const { return m_parent; }
|
2019-05-30 12:46:08 -03:00
|
|
|
Inode& inode() { return *m_inode; }
|
2021-07-10 19:51:38 -03:00
|
|
|
Inode const& inode() const { return *m_inode; }
|
2021-05-28 06:21:00 -03:00
|
|
|
StringView name() const { return m_name->view(); }
|
2021-11-07 20:51:39 -03:00
|
|
|
ErrorOr<NonnullOwnPtr<KString>> try_serialize_absolute_path() const;
|
2019-05-30 13:58:59 -03:00
|
|
|
|
2020-01-11 12:25:26 -03:00
|
|
|
int mount_flags() const { return m_mount_flags; }
|
2020-05-28 11:56:25 -03:00
|
|
|
bool is_readonly() const;
|
2020-01-11 12:25:26 -03:00
|
|
|
|
2019-05-30 12:46:08 -03:00
|
|
|
private:
|
2021-05-28 06:21:00 -03:00
|
|
|
Custody(Custody* parent, NonnullOwnPtr<KString> name, Inode&, int mount_flags);
|
2019-05-30 12:46:08 -03:00
|
|
|
|
2022-08-20 20:04:35 -03:00
|
|
|
RefPtr<Custody> m_parent;
|
2021-05-28 06:21:00 -03:00
|
|
|
NonnullOwnPtr<KString> m_name;
|
2022-08-19 15:53:40 -03:00
|
|
|
NonnullLockRefPtr<Inode> m_inode;
|
2020-01-11 12:25:26 -03:00
|
|
|
int m_mount_flags { 0 };
|
2021-08-15 14:02:48 -03:00
|
|
|
|
|
|
|
|
mutable IntrusiveListNode<Custody> m_all_custodies_list_node;
|
|
|
|
|
|
|
|
|
|
public:
|
2021-09-09 09:00:59 -03:00
|
|
|
using AllCustodiesList = IntrusiveList<&Custody::m_all_custodies_list_node>;
|
2022-08-17 15:30:21 -03:00
|
|
|
static SpinlockProtected<Custody::AllCustodiesList>& all_instances();
|
2019-05-30 12:46:08 -03:00
|
|
|
};
|
2020-02-15 21:27:42 -03:00
|
|
|
|
|
|
|
|
}
|