mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05: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:
parent
88eb7a634f
commit
3b089032f4
3 changed files with 20 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,6 +50,9 @@ public:
|
|||
|
||||
virtual CommandSet command_set() const = 0;
|
||||
|
||||
// ^File
|
||||
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) final;
|
||||
|
||||
protected:
|
||||
StorageDevice(int, int, size_t, u64, NonnullOwnPtr<KString>);
|
||||
// ^DiskDevice
|
||||
|
|
|
@ -88,7 +88,8 @@ enum IOCtlNumber {
|
|||
KCOV_ENABLE,
|
||||
KCOV_DISABLE,
|
||||
SOUNDCARD_IOCTL_SET_SAMPLE_RATE,
|
||||
SOUNDCARD_IOCTL_GET_SAMPLE_RATE
|
||||
SOUNDCARD_IOCTL_GET_SAMPLE_RATE,
|
||||
STORAGE_DEVICE_GET_SIZE,
|
||||
};
|
||||
|
||||
#define TIOCGPGRP TIOCGPGRP
|
||||
|
@ -132,3 +133,4 @@ enum IOCtlNumber {
|
|||
#define FIONREAD FIONREAD
|
||||
#define SOUNDCARD_IOCTL_SET_SAMPLE_RATE SOUNDCARD_IOCTL_SET_SAMPLE_RATE
|
||||
#define SOUNDCARD_IOCTL_GET_SAMPLE_RATE SOUNDCARD_IOCTL_GET_SAMPLE_RATE
|
||||
#define STORAGE_DEVICE_GET_SIZE STORAGE_DEVICE_GET_SIZE
|
||||
|
|
Loading…
Add table
Reference in a new issue