From 6476a774dc828ad1720fc4c5d266565ea192d84f Mon Sep 17 00:00:00 2001 From: aaronhance Date: Sat, 29 Jan 2022 22:21:10 +0000 Subject: [PATCH] More progress and fixes --- src/driver/storage/drivemanager.pas | 5 +- src/driver/storage/fat32.pas | 2 +- src/driver/storage/flatfs.pas | 2 +- src/driver/storage/storagemanagement.pas | 65 ++++-------------------- src/driver/storage/volumemanager.pas | 33 ++++++------ 5 files changed, 33 insertions(+), 74 deletions(-) diff --git a/src/driver/storage/drivemanager.pas b/src/driver/storage/drivemanager.pas index 29469d84..1ec75099 100644 --- a/src/driver/storage/drivemanager.pas +++ b/src/driver/storage/drivemanager.pas @@ -80,6 +80,7 @@ begin end; { initalise a drive with a MBR - TODO needs to be expanded for partitioning } +//this is now deprecated functionality moved to storagemanagment procedure init_drive_command(driveIndex : uint32); var bootrecord : PMaster_Boot_Record; @@ -94,7 +95,7 @@ begin drive := PStorage_device(LL_Get(storageDevices, driveIndex)); MBR.setup_partition(partition, 100, drive^.maxSectorCount-300); - bootrecord^.partition_0 := partition^; + bootrecord^.partition[0] := partition^; //write MBR and partition table to disk drive^.writeCallback(drive, 0, 1, puint32(bootrecord)); @@ -117,7 +118,7 @@ begin console.writestringlnWnd('Please provide valid arguments.', getTerminalHWND()); console.writestringlnWnd(' ls - for listing all drives', getTerminalHWND()); console.writestringlnWnd(' info [drive] - display formation for specified drive', getTerminalHWND()); - console.writestringlnWnd(' init [drive] - destructive, formats a drive with a blank partition', getTerminalHWND()); + console.writestringlnWnd(' init [drive] - DEPRECATED destructive, formats a drive with a blank partition', getTerminalHWND()); exit; end; diff --git a/src/driver/storage/fat32.pas b/src/driver/storage/fat32.pas index 22adb367..5f65475b 100644 --- a/src/driver/storage/fat32.pas +++ b/src/driver/storage/fat32.pas @@ -926,7 +926,7 @@ begin filesystem.detectcallback:= @detect_volumes; filesystem.writecallback:= @writeFile; filesystem.readcallback := @readFile; - filesystem.formatVolumeCallback := @create_volume; + // filesystem.formatVolumeCallback := @create_volume; volumemanager.register_filesystem(@filesystem); end; diff --git a/src/driver/storage/flatfs.pas b/src/driver/storage/flatfs.pas index c7175125..eaba5305 100644 --- a/src/driver/storage/flatfs.pas +++ b/src/driver/storage/flatfs.pas @@ -100,7 +100,7 @@ begin filesystem.detectcallback:= @detect_volumes; filesystem.writecallback:= @writeFile; filesystem.readcallback := @readFile; - filesystem.formatVolumeCallback := @create_volume; + // filesystem.formatVolumeCallback := @create_volume; volumemanager.register_filesystem(@filesystem); end; diff --git a/src/driver/storage/storagemanagement.pas b/src/driver/storage/storagemanagement.pas index 364ecf17..b2ffd709 100644 --- a/src/driver/storage/storagemanagement.pas +++ b/src/driver/storage/storagemanagement.pas @@ -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); diff --git a/src/driver/storage/volumemanager.pas b/src/driver/storage/volumemanager.pas index 9e32ce26..75f25663 100644 --- a/src/driver/storage/volumemanager.pas +++ b/src/driver/storage/volumemanager.pas @@ -44,11 +44,10 @@ type 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; PPHIOHook = procedure(volume : PStorage_device; addr : uint32; sectors : uint32; buffer : puint32); - PPCreateHook = procedure(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32); + PPCreateHook = procedure(disk : PStorage_Device; start : uint32; size : 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 - PPFormatVolumeHook = procedure(disk : PStorage_device; sectorCount : uint32; start : uint32; config : puint32); PPHIOHook_ = procedure; @@ -57,11 +56,10 @@ type system_id : uint8; writeCallback : PPWriteHook; readCallback : PPReadHook; - createCallback : PPCreateHook; - detectCallback : PPDetectHook; + createCallback : PPCreateHook; //create volume + detectCallback : PPDetectHook; //detect volume createDirCallback : PPCreateDirHook; readDirCallback : PPReadDirHook; - formatVolumeCallback : PPFormatVolumeHook; end; TStorage_Volume = record @@ -93,6 +91,7 @@ var procedure register_filesystem(filesystem : PFilesystem); procedure check_for_volumes(drive : PStorage_device); + procedure create_volume(disk : PStorage_device; filesystem : PChar; sectorStart : uint32; sectorCount : uint32); //IO functions @@ -105,7 +104,9 @@ var config : puint32; begin push_trace('VolumeManager.format_volume_command'); - + console.writestringlnWND('Not implimented, use disk format', getTerminalHWND()); + exit; + if paramCount(params) < 3 then begin console.writestringlnWND('Invalid arguments', getTerminalHWND()); end; @@ -122,7 +123,7 @@ begin //TODO check things exsist console.writestringlnWND('Staring volume formatting...', getTerminalHWND()); - filesystem^.formatVolumeCallback(volume^.device, volume^.sectorSize, volume^.sectorStart, config); + // filesystem^.formatVolumeCallback(volume^.device, volume^.sectorSize, volume^.sectorStart, config); console.writestringlnWND('Volume format finished.', getTerminalHWND()); end; @@ -253,12 +254,12 @@ begin drive^.readCallback(drive, 0, 1, puint32(bootrecord)); //TODO multipe partition entries - if bootrecord^.partition_0.LBA_start <> 0 then + if bootrecord^.partition[0].LBA_start <> 0 then begin //set volume information storageVolume.device := drive; - storageVolume.sectorStart := bootrecord^.partition_0.LBA_start; - storageVolume.sectorCount := bootrecord^.partition_0.sector_count; + storageVolume.sectorStart := bootrecord^.partition[0].LBA_start; + storageVolume.sectorCount := bootrecord^.partition[0].sector_count; storageVolume.sectorSize := drive^.sectorSize; storageVolume.freeSectors := 0; //TODO impliment storageVolume.filesystem := nil; @@ -270,7 +271,7 @@ begin //check for filesystem type for i:=0 to LL_Size(filesystems) - 1 do begin - if bootrecord^.partition_0.system_id = PFilesystem(LL_Get(filesystems, i))^.system_id then + if bootrecord^.partition[0].system_id = PFilesystem(LL_Get(filesystems, i))^.system_id then begin storageVolume.filesystem := PFilesystem(LL_Get(filesystems, i)); end; @@ -293,14 +294,16 @@ procedure create_volume(disk : PStorage_device; filesystem : PChar; sectorStart var volume : PStorage_Volume; elm : void; + i : uint16; + config : PuInt32; begin volume := PStorage_Volume(kalloc(SizeOf(TStorage_Volume))); volume^.device := disk; volume^.sectorStart := sectorStart; - volume^.sectorCount := sectorCount; + volume^.sectorCount := sectorCount - 10; //-10 is temp also in storagemanager volume^.sectorSize := disk^.sectorSize; - volume^.freeSectors := 0; //TODO impliment + volume^.freeSectors := 0; //setup by filesystem //find filesystem for i:=0 to LL_Size(filesystems) - 1 do begin @@ -310,7 +313,7 @@ begin end; //format volume - volume^.filesystem^.formatVolumeCallback(disk, sectorStart, sectorCount, 0); + volume^.filesystem^.createCallback(disk, sectorStart, sectorCount, config); //add volume to list elm := LL_Add(storageVolumes); @@ -330,7 +333,7 @@ begin elm := LL_Add(device^.volumes); PStorage_volume(elm)^:= volume^; - if rootVolume = PStorage_Volume(0) then rootVolume:= volume; + // if rootVolume = PStorage_Volume(0) then rootVolume:= volume; end; end. \ No newline at end of file