feat: support for USB mass storage devices, hotplugging
This commit is contained in:
@@ -234,8 +234,29 @@ namespace Montauk {
|
||||
buf->sectorSizePhys = bdev->SectorSize;
|
||||
dl_strcpy(buf->model, bdev->Model, 41);
|
||||
|
||||
switch (bdev->Kind) {
|
||||
case Drivers::Storage::BLOCK_KIND_SATA:
|
||||
buf->type = 1;
|
||||
break;
|
||||
case Drivers::Storage::BLOCK_KIND_SATAPI:
|
||||
buf->type = 2;
|
||||
break;
|
||||
case Drivers::Storage::BLOCK_KIND_NVME:
|
||||
buf->type = 3;
|
||||
buf->rpm = 1;
|
||||
break;
|
||||
case Drivers::Storage::BLOCK_KIND_USB_MSC:
|
||||
buf->type = 4;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Try to fill AHCI-specific fields if this is an AHCI device
|
||||
if (Drivers::Storage::Ahci::IsInitialized()) {
|
||||
if ((bdev->Kind == Drivers::Storage::BLOCK_KIND_SATA ||
|
||||
bdev->Kind == Drivers::Storage::BLOCK_KIND_SATAPI ||
|
||||
bdev->Kind == Drivers::Storage::BLOCK_KIND_UNKNOWN) &&
|
||||
Drivers::Storage::Ahci::IsInitialized()) {
|
||||
for (int p = 0; p < 32; p++) {
|
||||
auto* info = Drivers::Storage::Ahci::GetPortInfo(p);
|
||||
if (!info) continue;
|
||||
@@ -262,7 +283,8 @@ namespace Montauk {
|
||||
}
|
||||
|
||||
// For NVMe devices: set type=3 (NVMe), rpm=1 (SSD)
|
||||
if (buf->type == 0 && Drivers::Storage::Nvme::IsInitialized()) {
|
||||
if ((buf->type == 0 || bdev->Kind == Drivers::Storage::BLOCK_KIND_NVME) &&
|
||||
Drivers::Storage::Nvme::IsInitialized()) {
|
||||
for (int ns = 0; ns < Drivers::Storage::Nvme::GetNamespaceCount(); ns++) {
|
||||
auto* nsInfo = Drivers::Storage::Nvme::GetNamespaceInfo(ns);
|
||||
if (!nsInfo) continue;
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace Montauk {
|
||||
const char* entries[1];
|
||||
if (Fs::Vfs::VfsReadDir(resolved, entries, 1) < 0) return -1;
|
||||
} else {
|
||||
Fs::Vfs::BackendFile file = {-1, -1};
|
||||
Fs::Vfs::BackendFile file = {-1, -1, 0};
|
||||
if (Fs::Vfs::OpenBackendFile(resolved, file) < 0) return -1;
|
||||
Fs::Vfs::CloseBackendFile(file);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Montauk {
|
||||
auto* dev = Drivers::Storage::GetBlockDevice(blockDev);
|
||||
if (!dev) return -1;
|
||||
|
||||
if (lba + count > dev->SectorCount) return -1;
|
||||
if (lba >= dev->SectorCount || count > dev->SectorCount - lba) return -1;
|
||||
if (!UserMemory::Range((uint64_t)buffer, (uint64_t)count * dev->SectorSize, true)) return -1;
|
||||
|
||||
if (!dev->ReadSectors(dev->Ctx, lba, count, buffer)) return -1;
|
||||
@@ -78,7 +78,7 @@ namespace Montauk {
|
||||
auto* dev = Drivers::Storage::GetBlockDevice(blockDev);
|
||||
if (!dev) return -1;
|
||||
|
||||
if (lba + count > dev->SectorCount) return -1;
|
||||
if (lba >= dev->SectorCount || count > dev->SectorCount - lba) return -1;
|
||||
if (!UserMemory::Range((uint64_t)buffer, (uint64_t)count * dev->SectorSize, false)) return -1;
|
||||
|
||||
if (!dev->WriteSectors(dev->Ctx, lba, count, buffer)) return -1;
|
||||
@@ -88,6 +88,7 @@ namespace Montauk {
|
||||
|
||||
// Initialize a new GPT on a block device. Returns 0 on success, -1 on error.
|
||||
static int64_t Sys_GptInit(int blockDev) {
|
||||
Fs::FsProbe::UnmountPartitionsForBlockDevice(blockDev);
|
||||
return (int64_t)Drivers::Storage::Gpt::InitializeGpt(blockDev);
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ namespace Montauk {
|
||||
|
||||
struct DiskInfo {
|
||||
uint8_t port; // block device index
|
||||
uint8_t type; // 0=none, 1=SATA, 2=SATAPI, 3=NVMe
|
||||
uint8_t type; // 0=none, 1=SATA, 2=SATAPI, 3=NVMe, 4=USB mass storage
|
||||
uint8_t sataGen; // SATA gen (1/2/3)
|
||||
uint8_t _pad0;
|
||||
uint64_t sectorCount; // Total user-addressable sectors
|
||||
|
||||
Reference in New Issue
Block a user