Skip to content

Commit

Permalink
Kernel: Remove AK::String usage from Storage/StorageManagement.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
bgianfo authored and awesomekling committed Oct 3, 2021
1 parent 7f88d50 commit 836c22e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions Kernel/Storage/StorageManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include <AK/Singleton.h>
#include <AK/StringView.h>
#include <AK/UUID.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Bus/PCI/Access.h>
Expand All @@ -25,6 +26,8 @@ namespace Kernel {
static Singleton<StorageManagement> s_the;
static Atomic<size_t> s_device_minor_number;

static constexpr StringView partition_uuid_prefix = "PARTUUID="sv;

UNMAP_AFTER_INIT StorageManagement::StorageManagement()
{
}
Expand All @@ -36,7 +39,7 @@ void StorageManagement::remove_device(StorageDevice& device)

bool StorageManagement::boot_argument_contains_partition_uuid()
{
return m_boot_argument.starts_with("PARTUUID=");
return m_boot_argument.starts_with(partition_uuid_prefix);
}

UNMAP_AFTER_INIT void StorageManagement::enumerate_controllers(bool force_pio)
Expand Down Expand Up @@ -120,7 +123,7 @@ UNMAP_AFTER_INIT void StorageManagement::enumerate_disk_partitions() const
UNMAP_AFTER_INIT void StorageManagement::determine_boot_device()
{
VERIFY(!m_controllers.is_empty());
if (m_boot_argument.starts_with("/dev/")) {
if (m_boot_argument.starts_with("/dev/"sv)) {
StringView storage_name = m_boot_argument.substring_view(5);
for (auto& storage_device : m_storage_devices) {
if (storage_device.storage_name() == storage_name) {
Expand All @@ -137,9 +140,9 @@ UNMAP_AFTER_INIT void StorageManagement::determine_boot_device()
UNMAP_AFTER_INIT void StorageManagement::determine_boot_device_with_partition_uuid()
{
VERIFY(!m_storage_devices.is_empty());
VERIFY(m_boot_argument.starts_with("PARTUUID="));
VERIFY(m_boot_argument.starts_with(partition_uuid_prefix));

auto partition_uuid = UUID(m_boot_argument.substring_view(strlen("PARTUUID=")));
auto partition_uuid = UUID(m_boot_argument.substring_view(partition_uuid_prefix.length()));

if (partition_uuid.to_string().length() != 36) {
PANIC("StorageManagement: Specified partition UUID is not valid");
Expand Down Expand Up @@ -189,7 +192,7 @@ NonnullRefPtr<FileSystem> StorageManagement::root_filesystem() const
return file_system;
}

UNMAP_AFTER_INIT void StorageManagement::initialize(String root_device, bool force_pio)
UNMAP_AFTER_INIT void StorageManagement::initialize(StringView root_device, bool force_pio)
{
VERIFY(s_device_minor_number == 0);
m_boot_argument = root_device;
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Storage/StorageManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class StorageManagement {
public:
StorageManagement();
static bool initialized();
void initialize(String boot_argument, bool force_pio);
void initialize(StringView boot_argument, bool force_pio);
static StorageManagement& the();

NonnullRefPtr<FileSystem> root_filesystem() const;
Expand All @@ -48,7 +48,7 @@ class StorageManagement {

RefPtr<BlockDevice> boot_block_device() const;

String m_boot_argument;
StringView m_boot_argument;
WeakPtr<BlockDevice> m_boot_block_device;
NonnullRefPtrVector<StorageController> m_controllers;
IntrusiveList<&StorageDevice::m_list_node> m_storage_devices;
Expand Down

0 comments on commit 836c22e

Please sign in to comment.