mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:28:11 +00:00
Kernel: Remove most String usage from storage_name() API
This change is another minor step towards removing `AK::String` from the Kernel. Instead of dynamically allocating the storage_name we can instead allocate it via a KString in the factory for each device, and then push the device name down into the StorageDevice base class. We don't have a way of doing `AK::String::formatted(..)` with a KString at the moment, so cleaning that up will be left for a later day.
This commit is contained in:
parent
3a945051fc
commit
70ad18fbcd
8 changed files with 45 additions and 40 deletions
|
@ -15,14 +15,20 @@ namespace Kernel {
|
|||
|
||||
NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
|
||||
{
|
||||
auto device_or_error = DeviceManagement::try_create_device<RamdiskDevice>(controller, move(region), major, minor);
|
||||
// FIXME: Try to not hardcode a maximum of 16 partitions per drive!
|
||||
size_t drive_index = minor / 16;
|
||||
// FIXME: We need a way of formatting strings with KString!
|
||||
auto device_name = String::formatted("ramdisk{}", drive_index);
|
||||
auto device_name_kstring = KString::must_create(device_name.view());
|
||||
|
||||
auto device_or_error = DeviceManagement::try_create_device<RamdiskDevice>(controller, move(region), major, minor, move(device_name_kstring));
|
||||
// FIXME: Find a way to propagate errors
|
||||
VERIFY(!device_or_error.is_error());
|
||||
return device_or_error.release_value();
|
||||
}
|
||||
|
||||
RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
|
||||
: StorageDevice(controller, major, minor, 512, region->size() / 512)
|
||||
RamdiskDevice::RamdiskDevice(const RamdiskController& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor, NonnullOwnPtr<KString> device_name)
|
||||
: StorageDevice(controller, major, minor, 512, region->size() / 512, move(device_name))
|
||||
, m_region(move(region))
|
||||
{
|
||||
dmesgln("Ramdisk: Device #{} @ {}, Capacity={}", minor, m_region->vaddr(), max_addressable_block() * 512);
|
||||
|
@ -59,11 +65,4 @@ void RamdiskDevice::start_request(AsyncBlockDeviceRequest& request)
|
|||
}
|
||||
}
|
||||
|
||||
String RamdiskDevice::storage_name() const
|
||||
{
|
||||
// FIXME: Try to not hardcode a maximum of 16 partitions per drive!
|
||||
size_t drive_index = minor() / 16;
|
||||
return String::formatted("ramdisk{}", drive_index);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue