Serenity Operating System
1/*
2 * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#pragma once
8
9#include <AK/IntrusiveList.h>
10#include <Kernel/FileSystem/SysFS/Component.h>
11#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/BlockDevicesDirectory.h>
12#include <Kernel/FileSystem/SysFS/Subsystems/DeviceIdentifiers/CharacterDevicesDirectory.h>
13#include <Kernel/KString.h>
14
15namespace Kernel {
16
17class SysFSDeviceIdentifiersDirectory;
18class SysFSSymbolicLinkDeviceComponent final
19 : public SysFSSymbolicLink
20 , public LockWeakable<SysFSSymbolicLinkDeviceComponent> {
21 friend class SysFSComponentRegistry;
22
23public:
24 static ErrorOr<NonnullLockRefPtr<SysFSSymbolicLinkDeviceComponent>> try_create(SysFSCharacterDevicesDirectory const& parent_directory, Device const& device, SysFSComponent const& pointed_component);
25 static ErrorOr<NonnullLockRefPtr<SysFSSymbolicLinkDeviceComponent>> try_create(SysFSBlockDevicesDirectory const& parent_directory, Device const& device, SysFSComponent const& pointed_component);
26
27 virtual StringView name() const override { return m_major_minor_formatted_device_name->view(); }
28 bool is_block_device() const { return m_block_device; }
29
30private:
31 SysFSSymbolicLinkDeviceComponent(SysFSCharacterDevicesDirectory const& parent_directory, NonnullOwnPtr<KString> major_minor_formatted_device_name, Device const&, SysFSComponent const& pointed_component);
32 SysFSSymbolicLinkDeviceComponent(SysFSBlockDevicesDirectory const& parent_directory, NonnullOwnPtr<KString> major_minor_formatted_device_name, Device const&, SysFSComponent const& pointed_component);
33
34 IntrusiveListNode<SysFSSymbolicLinkDeviceComponent, NonnullLockRefPtr<SysFSSymbolicLinkDeviceComponent>> m_list_node;
35 bool const m_block_device { false };
36 NonnullOwnPtr<KString> m_major_minor_formatted_device_name;
37};
38
39}