More progress and fixes

This commit is contained in:
2022-01-29 22:21:10 +00:00
parent e791edb02a
commit 6476a774dc
5 changed files with 33 additions and 74 deletions

View File

@ -33,14 +33,12 @@ uses
tracer,
rtc,
MBR,
volumemanager;
volumemanager,
storagetypes;
type
TControllerType = (ControllerIDE, ControllerUSB, ControllerAHCI, ControllerNET, ControllerRAM, rsvctr1, rsvctr2, rsvctr3);
TDirectory_Entry_Type = (directoryEntry, fileEntry, mountEntry);
PStorage_volume = ^TStorage_Volume;
PStorage_device = ^TStorage_Device;
APStorage_Volume = array[0..10] of PStorage_volume;
byteArray8 = array[0..7] of char;
PByteArray8 = ^byteArray8;
@ -56,42 +54,6 @@ type
PPHIOHook_ = procedure;
// TFilesystem = record
// sName : pchar;
// writeCallback : PPWriteHook;
// readCallback : PPReadHook;
// createCallback : PPCreateHook;
// detectCallback : PPDetectHook;
// createDirCallback : PPCreateDirHook;
// readDirCallback : PPReadDirHook;
// end;
// PFileSystem = ^TFilesystem;
// TStorage_Volume = record
// device : PStorage_device;
// sectorStart : uint32;
// sectorSize : uint32;
// freeSectors : uint32;
// filesystem : PFilesystem;
// { True if this drive contains the loaded OS }
// isBootDrive : boolean;
// end;
{ Generic storage device }
TStorage_Device = record
idx : uint8;
controller : TControllerType;
controllerId0 : uint32;
maxSectorCount : uint32;
sectorSize : uint32;
writable : boolean;
volumes : PLinkedListBase;
writeCallback : PPHIOHook;
readCallback : PPHIOHook;
hpc : uint16;
spt : uint16;
end;
APStorage_Device = array[0..255] of PStorage_device;
{ Generic directory entry }
@ -113,14 +75,6 @@ procedure init();
procedure register_device(device : PStorage_Device);
function get_device_list() : PLinkedListBase;
procedure register_filesystem(filesystem : PFilesystem);
// procedure register_volume(device : PStorage_Device; volume : PStorage_Volume);
//function writeNewFile(fileName : pchar; extension : pchar; buffer : puint32; size : uint32) : uint32;
//function readFile(fileName : pchar; extension : pchar; buffer : puint32; byteCount : puint32) : puint32;
//TODO write partition table
implementation
function controller_type_2_string(controllerType : TControllerType) : pchar;
@ -172,7 +126,6 @@ var
drive : PStorage_Device;
filesystemString : pchar;
filesystem : PFileSystem;
spc : puint32;
sectorCount : uint32;
@ -191,37 +144,39 @@ begin
driveIndex:= stringToInt( getParam(1, params) );
drive:= PStorage_Device(LL_Get(storageDevices, driveIndex));
filesystemString := getParam(2, params);
sectorCount := stringToInt( getParam(4, params) );
// if sector count is 0, use full drive
if sectorCount = 0 then begin
sectorCount = drive^.maxSectorCount - 10;
sectorCount := drive^.maxSectorCount - 10;
end;
//create MBR if none, and partition table
mb := PMaster_Boot_Record(kalloc(sizeof(TMaster_Boot_Record)));
mb := drive^.readCallback(drive, 0, 1);
drive^.readCallback(drive, 0, 1, PuInt32(mb));
//check if MBR exists
if not mb^.boot_sector = $55AA then begin
//create MBR
mb^.signature := $A570 + drive^.idx;
mb^.signature := $A570 + drive^.id;
mb^.boot_sector := $55AA;
//create partition table
mbr.setup_partition(@mb^.partition[0], 2, sectorCount);
//write MBR
disk^.writeCallback(drive, 0, 1, mb);
drive^.writeCallback(drive, 0, 1, puint32(mb));
end;
kfree(mb);
kfree(puint32(mb));
//setup volume
volumemanager.create_volume(drive, filesystemString, 2, sectorCount);
//todo change b4 adding in aniother filesytem
// PFilesystem(LL_Get(filesystems, 0))^.createCallback(drive, drive^.maxSectorCount-1, 1, spc);