summaryrefslogtreecommitdiff
path: root/Kernel/Storage/StorageDevice.cpp
diff options
context:
space:
mode:
authorDavid Isaksson <davidisaksson93@gmail.com>2021-10-08 22:20:26 +0200
committerAndreas Kling <kling@serenityos.org>2021-10-09 12:06:47 +0200
commit3b089032f4bacbfad8e8d15f13903e1a93d44847 (patch)
tree17e88d5b9ef2e57a4b3a974fd4ce41d9de3f5ad9 /Kernel/Storage/StorageDevice.cpp
parent88eb7a634f5563fa9795fc6f450e13e86d97dc00 (diff)
downloadserenity-3b089032f4bacbfad8e8d15f13903e1a93d44847.zip
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.
Diffstat (limited to 'Kernel/Storage/StorageDevice.cpp')
-rw-r--r--Kernel/Storage/StorageDevice.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/Kernel/Storage/StorageDevice.cpp b/Kernel/Storage/StorageDevice.cpp
index 217fc51810..4588f67617 100644
--- a/Kernel/Storage/StorageDevice.cpp
+++ b/Kernel/Storage/StorageDevice.cpp
@@ -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;
+ }
+}
+
}