44 lines
1.5 KiB
C
44 lines
1.5 KiB
C
// hal_disk.c - drive registry; drivers register themselves via IoRegisterDisk
|
|
#include "hal_api.h"
|
|
#include "io_driver.h"
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#define MAX_DRIVES 8
|
|
|
|
static DISK_DRIVER gDrives[MAX_DRIVES];
|
|
static bool gPresent[MAX_DRIVES];
|
|
|
|
KSTATUS IoRegisterDisk(uint8_t index, const DISK_DRIVER* driver) {
|
|
if (index >= MAX_DRIVES || !driver) return STATUS_INVALID_PARAMETER;
|
|
if (gPresent[index]) return STATUS_ALREADY_EXISTS;
|
|
gDrives[index] = *driver;
|
|
gPresent[index] = true;
|
|
return STATUS_SUCCESS;
|
|
}
|
|
|
|
static KSTATUS DiskRead(uint8_t drive, uint64_t lba,
|
|
uint32_t count, void* buf) {
|
|
if (drive >= MAX_DRIVES || !gPresent[drive]) return STATUS_NOT_FOUND;
|
|
return gDrives[drive].ReadSectors(lba, count, buf);
|
|
}
|
|
static KSTATUS DiskWrite(uint8_t drive, uint64_t lba,
|
|
uint32_t count, const void* buf) {
|
|
if (drive >= MAX_DRIVES || !gPresent[drive]) return STATUS_NOT_FOUND;
|
|
return gDrives[drive].WriteSectors(lba, count, buf);
|
|
}
|
|
static bool DiskPresent(uint8_t drive) {
|
|
return drive < MAX_DRIVES && gPresent[drive];
|
|
}
|
|
static uint64_t DiskSectorCount(uint8_t drive) {
|
|
if (drive >= MAX_DRIVES || !gPresent[drive]) return 0;
|
|
return gDrives[drive].SectorCount;
|
|
}
|
|
|
|
void HalDiskInitialize(HAL_DISK* out) {
|
|
out->ReadSectors = DiskRead;
|
|
out->WriteSectors = DiskWrite;
|
|
out->DrivePresent = DiskPresent;
|
|
out->DriveSectorCount = DiskSectorCount;
|
|
}
|