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