Continued new volume management stuff.

This commit is contained in:
Aaron Hance 2021-06-25 01:48:20 +01:00
parent ba38f4fd19
commit 94b477d8f7
6 changed files with 202 additions and 56 deletions

View File

@ -22,7 +22,8 @@ uses
storagemanagement, storagemanagement,
strings, strings,
tracer, tracer,
drivemanager; drivemanager,
storagetypes;
type type
TPortMode = (P_READ, P_WRITE); TPortMode = (P_READ, P_WRITE);
@ -333,10 +334,14 @@ var
device: uint8; device: uint8;
data: uint16; data: uint16;
begin begin
if not validate_28bit_address(LBA) then begin push_trace('IDE.readPIO28');
if not validate_28bit_address(LBA) then begin
console.writestringln('IDE (writePIO28) ERROR: Invalid LBA!'); console.writestringln('IDE (writePIO28) ERROR: Invalid LBA!');
end; end;
push_trace('IDE.readPIO28.2');
//Add last 4 bits of LBA to device port //Add last 4 bits of LBA to device port
if IDEDevices[drive].isMaster then begin if IDEDevices[drive].isMaster then begin
device:= ATA_DEVICE_MASTER; device:= ATA_DEVICE_MASTER;
@ -347,6 +352,8 @@ begin
device_select($F0 or ((LBA and $0F000000) shr 24)); //LBA primary slave device_select($F0 or ((LBA and $0F000000) shr 24)); //LBA primary slave
end; end;
push_trace('IDE.readPIO28.3');
no_interrupt(device); no_interrupt(device);
port_write(ATA_REG_ERROR, 0); port_write(ATA_REG_ERROR, 0);
@ -356,6 +363,8 @@ begin
port_write(ATA_REG_LBA1, (LBA and $0000FF00) shr 8); port_write(ATA_REG_LBA1, (LBA and $0000FF00) shr 8);
port_write(ATA_REG_LBA2, (LBA and $00FF0000) shr 16); port_write(ATA_REG_LBA2, (LBA and $00FF0000) shr 16);
push_trace('IDE.readPIO28.4');
//send read command //send read command
port_write(ATA_REG_COMMAND, ATA_CMD_READ_PIO); port_write(ATA_REG_COMMAND, ATA_CMD_READ_PIO);
if not is_ready() then exit; if not is_ready() then exit;
@ -371,6 +380,8 @@ begin
i:= i + 2; i:= i + 2;
end; end;
push_trace('IDE.readPIO28.5');
end; end;
procedure writePIO28(drive : uint8; LBA : uint32; buffer : puint8); procedure writePIO28(drive : uint8; LBA : uint32; buffer : puint8);
@ -433,6 +444,7 @@ procedure dread(device : PStorage_device; LBA : uint32; sectorCount : uint32; bu
var var
i : uint16; i : uint16;
begin begin
push_trace('IDE.dread');
for i:=0 to sectorCount-1 do begin for i:=0 to sectorCount-1 do begin
readPIO28(device^.controllerId0, LBA, puint8(@buffer[512*i])); readPIO28(device^.controllerId0, LBA, puint8(@buffer[512*i]));
end; end;

View File

@ -1,3 +1,17 @@
// Copyright 2021 Aaron Hance
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{ {
Driver->Storage->DriveManager Physical storage device manager Driver->Storage->DriveManager Physical storage device manager
@ -19,44 +33,9 @@ uses
tracer, tracer,
rtc, rtc,
MBR, MBR,
serial; serial,
volumemanager,
type storagetypes;
TControllerType = (ControllerIDE, ControllerUSB, ControllerAHCI,
ControllerNET, ControllerRAM, rsvctr1, rsvctr2, rsvctr3);
PStorage_device = ^TStorage_Device;
PDrive_Error = ^TDrive_Error;
// PPWriteHook = procedure(volume : PStorage_volume; directory : pchar; entry : PDirectory_Entry; byteCount : uint32; buffer : puint32; statusOut : puint32);
// PPReadHook = function(volume : PStorage_Volume; directory : pchar; fileName : pchar; fileExtension : pchar; buffer : puint32; bytecount : puint32) : uint32;
// PPCreateHook = procedure(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32);
// PPDetectHook = procedure(disk : PStorage_Device);
// PPCreateDirHook = procedure(volume : PStorage_volume; directory : pchar; dirname : pchar; attributes : uint32; status : puint32);
// PPReadDirHook = function(volume : PStorage_volume; directory : pchar; status : puint32) : PLinkedListBase; //returns: 0 = success, 1 = dir not exsist, 2 = not directory, 3 = error //returns: 0 = success, 1 = dir not exsist, 2 = not directory, 3 = error
PPHIOHook = procedure(drive : PStorage_device; addr : uint32; sectors : uint32; buffer : puint32);
PPHIOHook_ = procedure;
{ Generic storage device }
TStorage_Device = record
id : uint8;
controller : TControllerType;
controllerId0 : uint32;
writable : boolean;
volumes : PLinkedListBase;
writeCallback : PPHIOHook;
readCallback : PPHIOHook;
maxSectorCount : uint32;
sectorSize : uint32;
end;
TDrive_Error = record
code : uint16;
description : pchar;
recoverable : boolean;
end;
var var
storageDevices : PLinkedListBase; //index in this array is global drive id storageDevices : PLinkedListBase; //index in this array is global drive id
@ -148,7 +127,12 @@ begin
end; end;
if( stringEquals(subcmd, 'info') ) then begin if( stringEquals(subcmd, 'info') ) then begin
//TODO unimplimented console.writestringWnd('Disk: ', getTerminalHWND());
console.writeintlnWND(1, getTerminalHWND());
console.writestringWnd('Capacity: ', getTerminalHWND());
console.writeintlnWND(1, getTerminalHWND());
//TODO impliement
exit exit
end; end;
@ -167,8 +151,6 @@ begin
setworkingdirectory('.'); setworkingdirectory('.');
storageDevices:= ll_new(sizeof(TStorage_Device)); storageDevices:= ll_new(sizeof(TStorage_Device));
serial.sendString('HERE I DID THE INIT WAH DU HEK BRUH!!!!!!');
//register DISK command //register DISK command
terminal.registerCommand('DISK', @drive_command, 'Disk utility'); terminal.registerCommand('DISK', @drive_command, 'Disk utility');
end; end;
@ -183,16 +165,17 @@ begin
//add the drive to the list of storage devices. //add the drive to the list of storage devices.
elm:= LL_Add(storageDevices); elm:= LL_Add(storageDevices);
PStorage_device(elm)^ := device^; //TODO memcopy //PStorage_device(elm)^ := device^; //TODO memcopy
memcpy(uint32(device), uint32(elm), SizeOf(TStorage_Device));
//set drive id in struct //set drive id in struct
PStorage_device(elm)^.id := LL_Size(storageDevices) - 1; PStorage_device(elm)^.id := LL_Size(storageDevices) - 1;
//create empty volume list for drive //create empty volume list for drive
// PStorage_Device(LL_Get(storageDevices, LL_Size(storageDevices) - 1))^.volumes := LL_New(sizeof(TStorage_Volume)); PStorage_device(elm)^.volumes := LL_New(sizeof(TStorage_Volume));
//TODO register with volume manager //TODO register with volume manager
volumemanager.check_for_volumes(PStorage_Device(elm));
end; end;
{ Get the drive list } { Get the drive list }

View File

@ -10,14 +10,16 @@ interface
uses uses
console, console,
storagemanagement, util,
util, terminal, terminal,
lmemorymanager, lmemorymanager,
strings, strings,
lists, lists,
tracer, tracer,
serial, serial,
rtc; rtc,
volumemanager,
storagetypes;
type type
@ -907,7 +909,7 @@ begin
volume^.sectorSize:= PBootRecord(buffer)^.sectorSize; volume^.sectorSize:= PBootRecord(buffer)^.sectorSize;
volume^.freeSectors:= 1000000; //TODO implement get free sectors need FSINFO implemented first volume^.freeSectors:= 1000000; //TODO implement get free sectors need FSINFO implemented first
volume^.filesystem := @filesystem; volume^.filesystem := @filesystem;
storagemanagement.register_volume(disk, volume); // storagemanagement.register_volume(disk, volume); TODO repalce with new thing
end; end;
kfree(buffer); kfree(buffer);
@ -917,6 +919,7 @@ procedure init();
begin begin
push_trace('fat32.init()'); push_trace('fat32.init()');
filesystem.sName:= 'FAT32'; filesystem.sName:= 'FAT32';
filesystem.system_id:= $00;
filesystem.readDirCallback:= @readDirectoryGen; filesystem.readDirCallback:= @readDirectoryGen;
filesystem.createDirCallback:= @writeDirectoryGen; filesystem.createDirCallback:= @writeDirectoryGen;
filesystem.createcallback:= @create_volume; filesystem.createcallback:= @create_volume;
@ -924,7 +927,7 @@ begin
filesystem.writecallback:= @writeFile; filesystem.writecallback:= @writeFile;
filesystem.readcallback := @readFile; filesystem.readcallback := @readFile;
storagemanagement.register_filesystem(@filesystem); volumemanager.register_filesystem(@filesystem);
end; end;
end. end.

View File

@ -0,0 +1,64 @@
// Copyright 2021 Aaron Hance
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{
Driver->Storage->Include->storagetypes - Structs & Data Shared Across Storage Drivers.
@author(Aaron Hance <ah@aaronhance.me>)
}
unit storagetypes;
interface
uses
lists;
type
TControllerType = (ControllerIDE, ControllerUSB, ControllerAHCI,
ControllerNET, ControllerRAM, rsvctr1, rsvctr2, rsvctr3);
PStorage_device = ^TStorage_Device;
PDrive_Error = ^TDrive_Error;
PPHIOHook = procedure(drive : PStorage_device; addr : uint32; sectors : uint32; buffer : puint32);
PPHIOHook_ = procedure;
byteArray8 = array[0..7] of char;
PByteArray8 = ^byteArray8;
{ Generic storage device }
TStorage_Device = record
id : uint8;
controller : TControllerType;
controllerId0 : uint32;
writable : boolean;
volumes : PLinkedListBase;
writeCallback : PPHIOHook;
readCallback : PPHIOHook;
maxSectorCount : uint32;
sectorSize : uint32;
end;
TDrive_Error = record
code : uint16;
description : pchar;
recoverable : boolean;
end;
implementation
end.

View File

@ -1,3 +1,17 @@
// Copyright 2021 Aaron Hance
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
{ {
Driver->Storage->VolumeManager Drive volume manager Driver->Storage->VolumeManager Drive volume manager
@ -10,12 +24,14 @@ interface
uses uses
util, util,
console, console,
drivemanager, terminal,
strings, strings,
lists, lists,
tracer, tracer,
lmemorymanager,
vfs, vfs,
MBR; MBR,
storagetypes;
type type
@ -80,6 +96,55 @@ var
implementation implementation
procedure list_volume_command();
var
i : uint32;
volume : PStorage_Volume;
begin
push_trace('VolumeManager.list_volume_command');
if LL_Size(storageVolumes) < 1 then begin
console.writestringlnWnd('No volumes found.', getTerminalHWND());
exit;
end;
console.writestringlnWnd('Volumes: ', getTerminalHWND());
for i:=0 to LL_Size(storageVolumes) - 1 do begin
volume := PStorage_Volume(LL_Get(storageVolumes, i));
console.writestringWnd(' ', getTerminalHWND());
console.writeintWnd(i, getTerminalHWND());
console.writestringWnd(' - Capacity: ', getTerminalHWND());
console.writeintWnd(uint32(volume^.sectorSize * volume^.sectorCount DIV 1024 DIV 1024), getTerminalHWND());
console.writestringWnd('MB System: ', getTerminalHWND());
console.writestringlnWnd(volume^.filesystem^.sName, getTerminalHWND());
end;
end;
procedure volume_command(params : PParamList);
var
i : uint16;
subcmd : pchar;
begin
push_trace('VolumeManager.volume_command');
subcmd:= getParam(0, params);
if ((paramCount(params) = 0)) then begin
console.writestringlnWnd('Please provide valid arguments.', getTerminalHWND());
console.writestringlnWnd(' ls - for listing all volumes', getTerminalHWND());
console.writestringlnWnd(' lsfs - for listing all filesystems', getTerminalHWND());
console.writestringlnWnd(' info [volume] - display formation for specified volume', getTerminalHWND());
console.writestringlnWnd(' format [volume] [filesystem] - destructive, formats a volume with a specified filesystem', getTerminalHWND());
exit;
end;
if( stringEquals(subcmd, 'ls') ) then begin
list_volume_command();
exit;
end;
end;
{ Initialise volume manager } { Initialise volume manager }
procedure init(); procedure init();
begin begin
@ -88,12 +153,18 @@ begin
{ setup lists } { setup lists }
storageVolumes:= ll_New(sizeof(TFilesystem)); storageVolumes:= ll_New(sizeof(TFilesystem));
filesystems:= ll_New(sizeof(TFilesystem)); filesystems:= ll_New(sizeof(TFilesystem));
terminal.registerCommand('volume', @volume_command, 'Volume utility');
end; end;
{ register a new type of filesystem } { register a new type of filesystem }
procedure register_filesystem(filesystem : PFilesystem); //TODO on init create null filesystem for empty partition procedure register_filesystem(filesystem : PFilesystem); //TODO on init create null filesystem for empty partition
var
elm : void;
begin begin
//add filesystem //add filesystem
elm := LL_add(filesystems);
memcpy(uint32(filesystem), uInt32(elm), SizeOf(TFilesystem));
//check drives for volumes of new type //check drives for volumes of new type
end; end;
@ -106,7 +177,9 @@ var
i : uint32 = 0; i : uint32 = 0;
elm : void; elm : void;
begin begin
push_trace('VolumeManager.check_for_volumes');
bootrecord := PMaster_Boot_Record(kalloc(SizeOf(TMaster_Boot_Record)));
drive^.readCallback(drive, 0, 1, puint32(bootrecord)); drive^.readCallback(drive, 0, 1, puint32(bootrecord));
//TODO multipe partition entries //TODO multipe partition entries
@ -117,6 +190,12 @@ begin
storageVolume.sectorStart := bootrecord^.partition_0.LBA_start; storageVolume.sectorStart := bootrecord^.partition_0.LBA_start;
storageVolume.sectorCount := bootrecord^.partition_0.sector_count; storageVolume.sectorCount := bootrecord^.partition_0.sector_count;
storageVolume.freeSectors := 0; //TODO impliment storageVolume.freeSectors := 0; //TODO impliment
push_trace('VolumeManager.init2');
if LL_Size(filesystems) < 1 then begin
console.writestringln('Failed to initalise storage system, no filesystems found, stopping!');
exit;
end;
//check for filesystem type //check for filesystem type
for i:=0 to LL_Size(filesystems) - 1 do begin for i:=0 to LL_Size(filesystems) - 1 do begin
@ -125,9 +204,14 @@ begin
storageVolume.filesystem := PFilesystem(LL_Get(filesystems, i)); storageVolume.filesystem := PFilesystem(LL_Get(filesystems, i));
end; end;
end; end;
push_trace('VolumeManager.init3');
//add volume to list //add volume to list
elm := LL_Add(storageVolumes); elm := LL_Add(storageVolumes);
memcpy(uint32(@storageVolume), uint32(elm), SizeOf(TStorage_Volume));
push_trace('VolumeManager.init4');
elm := LL_Add(drive^.volumes);
memcpy(uint32(@storageVolume), uint32(elm), SizeOf(TStorage_Volume)); memcpy(uint32(@storageVolume), uint32(elm), SizeOf(TStorage_Volume));
end; end;

View File

@ -217,7 +217,7 @@ begin
TMR_0_ISR.hook(uint32(@bios_data_area.tick_update)); TMR_0_ISR.hook(uint32(@bios_data_area.tick_update));
{ Filsystems } { Filsystems }
// fat32.init(); fat32.init();
{ Device Drivers } { Device Drivers }
tracer.push_trace('kmain.DEVDRV'); tracer.push_trace('kmain.DEVDRV');