1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

Kernel: Add STORAGE_DEVICE_GET_SIZE ioctl request

This ioctl request makes it possible to get the size of a storage device
that has not yet been mounted.
This commit is contained in:
David Isaksson 2021-10-08 22:20:26 +02:00 committed by Andreas Kling
parent 88eb7a634f
commit 3b089032f4
3 changed files with 20 additions and 1 deletions

View file

@ -10,6 +10,7 @@
#include <Kernel/FileSystem/OpenFileDescription.h>
#include <Kernel/Storage/StorageDevice.h>
#include <Kernel/Storage/StorageManagement.h>
#include <LibC/sys/ioctl_numbers.h>
namespace Kernel {
@ -187,4 +188,17 @@ bool StorageDevice::can_write(const OpenFileDescription&, size_t offset) const
return offset < (max_addressable_block() * block_size());
}
KResult StorageDevice::ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg)
{
switch (request) {
case STORAGE_DEVICE_GET_SIZE: {
size_t disk_size = m_max_addressable_block * block_size();
return copy_to_user(Userspace<size_t*>(arg), &disk_size);
break;
}
default:
return EINVAL;
}
}
}