ladybird/Kernel/FileSystem/SysFS/Subsystems/Devices/Storage/Directory.cpp
Andreas Kling 11eee67b85 Kernel: Make self-contained locking smart pointers their own classes
Until now, our kernel has reimplemented a number of AK classes to
provide automatic internal locking:

- RefPtr
- NonnullRefPtr
- WeakPtr
- Weakable

This patch renames the Kernel classes so that they can coexist with
the original AK classes:

- RefPtr => LockRefPtr
- NonnullRefPtr => NonnullLockRefPtr
- WeakPtr => LockWeakPtr
- Weakable => LockWeakable

The goal here is to eventually get rid of the Lock* classes in favor of
using external locking.
2022-08-20 17:20:43 +02:00

53 lines
1.7 KiB
C++

/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/FileSystem/SysFS/RootDirectory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Devices/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Devices/Storage/DeviceDirectory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Devices/Storage/Directory.h>
#include <Kernel/Sections.h>
#include <Kernel/Storage/StorageDevice.h>
namespace Kernel {
static SysFSStorageDirectory* s_the { nullptr };
UNMAP_AFTER_INIT NonnullLockRefPtr<SysFSStorageDirectory> SysFSStorageDirectory::must_create(SysFSDevicesDirectory const& parent_directory)
{
auto directory = adopt_lock_ref(*new (nothrow) SysFSStorageDirectory(parent_directory));
s_the = directory;
return directory;
}
SysFSStorageDirectory& SysFSStorageDirectory::the()
{
VERIFY(s_the);
return *s_the;
}
void SysFSStorageDirectory::plug(Badge<StorageDevice>, StorageDeviceSysFSDirectory& new_device_directory)
{
MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> {
list.append(new_device_directory);
auto pointed_component_base_name = MUST(KString::try_create(new_device_directory.name()));
auto pointed_component_relative_path = MUST(new_device_directory.relative_path(move(pointed_component_base_name), 0));
return {};
}));
}
void SysFSStorageDirectory::unplug(Badge<StorageDevice>, SysFSDirectory& removed_device_directory)
{
MUST(m_child_components.with([&](auto& list) -> ErrorOr<void> {
list.remove(removed_device_directory);
return {};
}));
}
UNMAP_AFTER_INIT SysFSStorageDirectory::SysFSStorageDirectory(SysFSDevicesDirectory const& parent_directory)
: SysFSDirectory(parent_directory)
{
}
}