2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-05-30 17:46:08 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
#include <AK/Error.h>
|
2021-08-15 19:02:48 +02:00
|
|
|
#include <AK/IntrusiveList.h>
|
2019-08-08 11:08:27 +02:00
|
|
|
#include <AK/RefPtr.h>
|
2020-02-16 02:15:33 +01:00
|
|
|
#include <Kernel/Forward.h>
|
2021-05-28 11:21:00 +02:00
|
|
|
#include <Kernel/KString.h>
|
2021-12-29 00:23:25 +02:00
|
|
|
#include <Kernel/Library/ListedRefCounted.h>
|
|
|
|
|
#include <Kernel/Locking/MutexProtected.h>
|
2019-05-30 17:46:08 +02:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2019-05-31 15:22:52 +02:00
|
|
|
// FIXME: Custody needs some locking.
|
2019-05-30 17:46:08 +02:00
|
|
|
|
2021-12-29 00:23:25 +02:00
|
|
|
class Custody : public ListedRefCounted<Custody, LockType::Mutex> {
|
2019-05-30 17:46:08 +02:00
|
|
|
public:
|
2021-11-08 00:51:39 +01:00
|
|
|
static ErrorOr<NonnullRefPtr<Custody>> try_create(Custody* parent, StringView name, Inode&, int mount_flags);
|
2019-05-30 17:46:08 +02:00
|
|
|
|
|
|
|
|
~Custody();
|
|
|
|
|
|
|
|
|
|
Custody* parent() { return m_parent.ptr(); }
|
2021-07-11 00:51:38 +02:00
|
|
|
Custody const* parent() const { return m_parent.ptr(); }
|
2019-05-30 17:46:08 +02:00
|
|
|
Inode& inode() { return *m_inode; }
|
2021-07-11 00:51:38 +02:00
|
|
|
Inode const& inode() const { return *m_inode; }
|
2021-05-28 11:21:00 +02:00
|
|
|
StringView name() const { return m_name->view(); }
|
2021-11-08 00:51:39 +01:00
|
|
|
ErrorOr<NonnullOwnPtr<KString>> try_serialize_absolute_path() const;
|
2019-05-30 18:58:59 +02: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 17:46:08 +02:00
|
|
|
private:
|
2021-05-28 11:21:00 +02:00
|
|
|
Custody(Custody* parent, NonnullOwnPtr<KString> name, Inode&, int mount_flags);
|
2019-05-30 17:46:08 +02:00
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<Custody> m_parent;
|
2021-05-28 11:21:00 +02:00
|
|
|
NonnullOwnPtr<KString> m_name;
|
2019-06-21 18:37:47 +02:00
|
|
|
NonnullRefPtr<Inode> m_inode;
|
2020-01-11 18:25:26 +03:00
|
|
|
int m_mount_flags { 0 };
|
2021-08-15 19:02:48 +02:00
|
|
|
|
|
|
|
|
mutable IntrusiveListNode<Custody> m_all_custodies_list_node;
|
|
|
|
|
|
|
|
|
|
public:
|
2021-09-09 16:30:59 +04:30
|
|
|
using AllCustodiesList = IntrusiveList<&Custody::m_all_custodies_list_node>;
|
2021-12-29 00:23:25 +02:00
|
|
|
static MutexProtected<Custody::AllCustodiesList>& all_instances();
|
2019-05-30 17:46:08 +02:00
|
|
|
};
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
|
}
|