Continued new volume management stuff.
This commit is contained in:
parent
97e1a18253
commit
da36f6fabb
@ -22,7 +22,8 @@ uses
|
||||
storagemanagement,
|
||||
strings,
|
||||
tracer,
|
||||
drivemanager;
|
||||
drivemanager,
|
||||
storagetypes;
|
||||
|
||||
type
|
||||
TPortMode = (P_READ, P_WRITE);
|
||||
@ -333,10 +334,14 @@ var
|
||||
device: uint8;
|
||||
data: uint16;
|
||||
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!');
|
||||
end;
|
||||
|
||||
push_trace('IDE.readPIO28.2');
|
||||
|
||||
//Add last 4 bits of LBA to device port
|
||||
if IDEDevices[drive].isMaster then begin
|
||||
device:= ATA_DEVICE_MASTER;
|
||||
@ -347,6 +352,8 @@ begin
|
||||
device_select($F0 or ((LBA and $0F000000) shr 24)); //LBA primary slave
|
||||
end;
|
||||
|
||||
push_trace('IDE.readPIO28.3');
|
||||
|
||||
no_interrupt(device);
|
||||
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_LBA2, (LBA and $00FF0000) shr 16);
|
||||
|
||||
push_trace('IDE.readPIO28.4');
|
||||
|
||||
//send read command
|
||||
port_write(ATA_REG_COMMAND, ATA_CMD_READ_PIO);
|
||||
if not is_ready() then exit;
|
||||
@ -371,6 +380,8 @@ begin
|
||||
|
||||
i:= i + 2;
|
||||
end;
|
||||
|
||||
push_trace('IDE.readPIO28.5');
|
||||
end;
|
||||
|
||||
procedure writePIO28(drive : uint8; LBA : uint32; buffer : puint8);
|
||||
@ -433,6 +444,7 @@ procedure dread(device : PStorage_device; LBA : uint32; sectorCount : uint32; bu
|
||||
var
|
||||
i : uint16;
|
||||
begin
|
||||
push_trace('IDE.dread');
|
||||
for i:=0 to sectorCount-1 do begin
|
||||
readPIO28(device^.controllerId0, LBA, puint8(@buffer[512*i]));
|
||||
end;
|
||||
|
@ -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
|
||||
|
||||
@ -19,44 +33,9 @@ uses
|
||||
tracer,
|
||||
rtc,
|
||||
MBR,
|
||||
serial;
|
||||
|
||||
type
|
||||
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;
|
||||
serial,
|
||||
volumemanager,
|
||||
storagetypes;
|
||||
|
||||
var
|
||||
storageDevices : PLinkedListBase; //index in this array is global drive id
|
||||
@ -148,7 +127,12 @@ begin
|
||||
end;
|
||||
|
||||
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
|
||||
end;
|
||||
|
||||
@ -167,8 +151,6 @@ begin
|
||||
setworkingdirectory('.');
|
||||
storageDevices:= ll_new(sizeof(TStorage_Device));
|
||||
|
||||
serial.sendString('HERE I DID THE INIT WAH DU HEK BRUH!!!!!!');
|
||||
|
||||
//register DISK command
|
||||
terminal.registerCommand('DISK', @drive_command, 'Disk utility');
|
||||
end;
|
||||
@ -183,16 +165,17 @@ begin
|
||||
|
||||
//add the drive to the list of storage devices.
|
||||
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
|
||||
PStorage_device(elm)^.id := LL_Size(storageDevices) - 1;
|
||||
|
||||
//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
|
||||
|
||||
volumemanager.check_for_volumes(PStorage_Device(elm));
|
||||
end;
|
||||
|
||||
{ Get the drive list }
|
||||
|
@ -10,14 +10,16 @@ interface
|
||||
|
||||
uses
|
||||
console,
|
||||
storagemanagement,
|
||||
util, terminal,
|
||||
util,
|
||||
terminal,
|
||||
lmemorymanager,
|
||||
strings,
|
||||
lists,
|
||||
tracer,
|
||||
serial,
|
||||
rtc;
|
||||
rtc,
|
||||
volumemanager,
|
||||
storagetypes;
|
||||
|
||||
type
|
||||
|
||||
@ -907,7 +909,7 @@ begin
|
||||
volume^.sectorSize:= PBootRecord(buffer)^.sectorSize;
|
||||
volume^.freeSectors:= 1000000; //TODO implement get free sectors need FSINFO implemented first
|
||||
volume^.filesystem := @filesystem;
|
||||
storagemanagement.register_volume(disk, volume);
|
||||
// storagemanagement.register_volume(disk, volume); TODO repalce with new thing
|
||||
end;
|
||||
|
||||
kfree(buffer);
|
||||
@ -917,6 +919,7 @@ procedure init();
|
||||
begin
|
||||
push_trace('fat32.init()');
|
||||
filesystem.sName:= 'FAT32';
|
||||
filesystem.system_id:= $00;
|
||||
filesystem.readDirCallback:= @readDirectoryGen;
|
||||
filesystem.createDirCallback:= @writeDirectoryGen;
|
||||
filesystem.createcallback:= @create_volume;
|
||||
@ -924,7 +927,7 @@ begin
|
||||
filesystem.writecallback:= @writeFile;
|
||||
filesystem.readcallback := @readFile;
|
||||
|
||||
storagemanagement.register_filesystem(@filesystem);
|
||||
volumemanager.register_filesystem(@filesystem);
|
||||
end;
|
||||
|
||||
end.
|
64
src/driver/storage/storagetypes.pas
Normal file
64
src/driver/storage/storagetypes.pas
Normal 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.
|
@ -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
|
||||
|
||||
@ -10,12 +24,14 @@ interface
|
||||
uses
|
||||
util,
|
||||
console,
|
||||
drivemanager,
|
||||
terminal,
|
||||
strings,
|
||||
lists,
|
||||
tracer,
|
||||
lmemorymanager,
|
||||
vfs,
|
||||
MBR;
|
||||
MBR,
|
||||
storagetypes;
|
||||
|
||||
type
|
||||
|
||||
@ -80,6 +96,55 @@ var
|
||||
|
||||
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 }
|
||||
procedure init();
|
||||
begin
|
||||
@ -87,13 +152,19 @@ begin
|
||||
|
||||
{ setup lists }
|
||||
storageVolumes:= ll_New(sizeof(TFilesystem));
|
||||
filesystems:= ll_New(sizeof(TFilesystem));
|
||||
filesystems:= ll_New(sizeof(TFilesystem));
|
||||
|
||||
terminal.registerCommand('volume', @volume_command, 'Volume utility');
|
||||
end;
|
||||
|
||||
{ register a new type of filesystem }
|
||||
procedure register_filesystem(filesystem : PFilesystem); //TODO on init create null filesystem for empty partition
|
||||
var
|
||||
elm : void;
|
||||
begin
|
||||
//add filesystem
|
||||
elm := LL_add(filesystems);
|
||||
memcpy(uint32(filesystem), uInt32(elm), SizeOf(TFilesystem));
|
||||
|
||||
//check drives for volumes of new type
|
||||
end;
|
||||
@ -106,7 +177,9 @@ var
|
||||
i : uint32 = 0;
|
||||
elm : void;
|
||||
begin
|
||||
push_trace('VolumeManager.check_for_volumes');
|
||||
|
||||
bootrecord := PMaster_Boot_Record(kalloc(SizeOf(TMaster_Boot_Record)));
|
||||
drive^.readCallback(drive, 0, 1, puint32(bootrecord));
|
||||
|
||||
//TODO multipe partition entries
|
||||
@ -117,6 +190,12 @@ begin
|
||||
storageVolume.sectorStart := bootrecord^.partition_0.LBA_start;
|
||||
storageVolume.sectorCount := bootrecord^.partition_0.sector_count;
|
||||
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
|
||||
for i:=0 to LL_Size(filesystems) - 1 do begin
|
||||
@ -125,11 +204,16 @@ begin
|
||||
storageVolume.filesystem := PFilesystem(LL_Get(filesystems, i));
|
||||
end;
|
||||
end;
|
||||
push_trace('VolumeManager.init3');
|
||||
|
||||
//add volume to list
|
||||
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));
|
||||
|
||||
end;
|
||||
|
||||
end;
|
||||
|
@ -217,7 +217,7 @@ begin
|
||||
TMR_0_ISR.hook(uint32(@bios_data_area.tick_update));
|
||||
|
||||
{ Filsystems }
|
||||
// fat32.init();
|
||||
fat32.init();
|
||||
|
||||
{ Device Drivers }
|
||||
tracer.push_trace('kmain.DEVDRV');
|
||||
|
Loading…
x
Reference in New Issue
Block a user