From 383f36bad3908a54c3a906dd8b03c3a6284bccc4 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 13 Apr 2018 18:59:19 +0000 Subject: [PATCH] git-svn-id: https://spexeah.com:8443/svn/Asuro@517 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c --- src/driver/storage/IDE.pas | 2 +- src/driver/storage/fat32.pas | 53 +++++++++++++---- src/driver/storage/storagemanagement.pas | 74 +++++++++++++++++++++--- src/include/strings.pas | 45 +++++++++++++- 4 files changed, 155 insertions(+), 19 deletions(-) diff --git a/src/driver/storage/IDE.pas b/src/driver/storage/IDE.pas index d12b2958..b4a08b24 100644 --- a/src/driver/storage/IDE.pas +++ b/src/driver/storage/IDE.pas @@ -406,7 +406,7 @@ begin Puint32(buffer + ((i * 512) + (ii * 32) DIV 32))^ := uint32(inw($1F0)); //wrong for iii:=0 to 1000 do if(ii = iii) then begin end; if ii <> 127 then begin - Puint32(buffer + ((i * 512) + (ii * 32) DIV 32))^ := ((uint32(inw($1F0)) shl 16) or Puint32(buffer + ((i * 512) + (ii * 16) DIV 32))^); //wrong + Puint32(buffer + ((i * 512) + (ii * 32) DIV 32))^ := ((uint32(inw($1F0)) shl 16) or Puint32(buffer + ((i * 512) + (ii * 32) DIV 32))^); //wrong for iii:=0 to 1000 do if(ii = iii) then begin end end; end; diff --git a/src/driver/storage/fat32.pas b/src/driver/storage/fat32.pas index 52fba8b6..e5c9e3e0 100644 --- a/src/driver/storage/fat32.pas +++ b/src/driver/storage/fat32.pas @@ -13,7 +13,7 @@ unit FAT32; interface uses - console, storagemanagement, util, lmemorymanager; + console, storagemanagement, util, lmemorymanager, strings; type @@ -47,6 +47,7 @@ type volumeLabel : array[0..10] of uint8; identString : array[0..7] of char;// = 'FAT32 '; end; + PBootRecord = ^TBootRecord; byteArray8 = array[0..7] of char; @@ -77,9 +78,12 @@ type end; PFatVolumeInfo = ^TFatVolumeInfo; +var + filesystem : TFilesystem; + procedure init; procedure create_volume(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32); -procedure detect_volumes(disk : PStorage_Device; volumes : puint32); +procedure detect_volumes(disk : PStorage_Device); implementation @@ -88,23 +92,34 @@ begin console.outputln('DUMMY DRIVER', 'LOADED.') end; -procedure read(volume : PStorage_volume; directory : pchar; byteCount : uint32; buffer : puint32); +procedure readDirectory(volume : PStorage_volume; directory : pchar; buffer : puint32); +begin + //get location of first directory entre + + //check if it takes up more than one cluster + //read all entries +end; + +procedure writeDirectory(volume : PStorage_volume; directory : pchar; buffer : puint32); begin end; -procedure write(volume : PStorage_volume; directory : pchar; byteCount : uint32; buffer : puint32); +procedure readFile(volume : PStorage_volume; directory : pchar; byteCount : uint32; buffer : puint32); +begin + +end; + +procedure writeFile(volume : PStorage_volume; directory : pchar; byteCount : uint32; buffer : puint32); begin end; procedure init; -var - filesystem : TFilesystem; begin filesystem.sName:= 'FAT32'; - filesystem.writecallback:= @write; - filesystem.readcallback:= @read; + filesystem.writecallback:= @writeFile; + filesystem.readcallback:= @readFile; filesystem.createcallback:= @create_volume; filesystem.detectcallback:= @detect_volumes; storagemanagement.register_filesystem(@filesystem); @@ -197,9 +212,27 @@ begin end; -procedure detect_volumes(disk : PStorage_Device; volumes : puint32); +procedure detect_volumes(disk : PStorage_Device); +var + buffer : puint32; + i : uint8; + volume : PStorage_volume; begin - + volume:= PStorage_volume(kalloc(sizeof(TStorage_Volume))); + //check first address for MBR + //if found then add volume and use info to see if there is another volume + buffer := puint32(kalloc(512)); + memset(uint32(buffer), 0, 512); + disk^.readcallback(disk, 2, 1, buffer); + + if (puint32(buffer + (127))^ = $55AA) and (PBootRecord(buffer)^.bsignature = $29) then begin + console.writestringln('FAT32: volume found!'); + volume^.sectorStart:= 1; + 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); + end; end; end. \ No newline at end of file diff --git a/src/driver/storage/storagemanagement.pas b/src/driver/storage/storagemanagement.pas index d75a4a5a..9d9a18bf 100644 --- a/src/driver/storage/storagemanagement.pas +++ b/src/driver/storage/storagemanagement.pas @@ -32,7 +32,7 @@ type PPIOHook = procedure(volume : PStorage_volume; directory : pchar; byteCount : uint32; buffer : puint32); PPHIOHook = procedure(volume : PStorage_device; addr : uint32; sectors : uint32; buffer : puint32); PPCreateHook = procedure(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32); - PPDetectHook = procedure(disk : PStorage_Device; volumes : Puint32); + PPDetectHook = procedure(disk : PStorage_Device); PPHIOHook_ = procedure; @@ -50,8 +50,8 @@ type sectorSize : uint32; freeSectors : uint32; filesystem : PFilesystem; - filesystemInfo : Puint32; // type dependant on filesystem. can be null if not creating volume now - directory : PLinkedListBase; // type dependant on filesytem? + //filesystemInfo : Puint32; // type dependant on filesystem. can be null if not creating volume now + //directory : PLinkedListBase; // type dependant on filesytem? end; TStorage_Device = record @@ -61,7 +61,7 @@ type maxSectorCount : uint32; sectorSize : uint32; writable : boolean; - volumes : array[0..7] of TStorage_Volume; + volumes : PLinkedListBase; writeCallback : PPHIOHook; readCallback : PPHIOHook; end; @@ -79,12 +79,30 @@ function get_device_list() : PLinkedListBase; procedure register_filesystem(filesystem : PFilesystem); -//procedure register_volume(volume : TStorage_Volume); +procedure register_volume(device : PStorage_Device; volume : PStorage_Volume); //TODO write partition table implementation +procedure test_command(params : PParamList); +var + i : uint32; + elm : puint32; + str : pchar; + list : PLinkedListBase; +begin + str := getParam(0, params); + + list := stringToLL(str, '/'); + + for i:=0 to LL_Size(list) - 1 do begin + elm:= puint32(LL_Get(list, i)); + str := pchar(elm^); + console.writestringln(str); + end; +end; + procedure disk_command(params : PParamList); var i : uint8; @@ -130,12 +148,41 @@ begin pop_trace; end; +procedure volume_command(params : PParamList); +var + i : uint32; + ii : uint16; + device : PStorage_device; + volume : PStorage_volume; +begin + if stringEquals(getParam(0, params), 'ls') and (LL_Size(storageDevices) > 0) then begin + for i:=0 to LL_Size(storageDevices) - 1 do begin + device := PStorage_device(LL_Get(storageDevices, i)); + + if LL_Size(device^.volumes) > 0 then begin + for ii:= 0 to LL_Size(device^.volumes) - 1 do begin + volume:= PStorage_volume(LL_Get(device^.volumes, ii)); + console.writeint(i); + console.writestring(') Filesystem: '); + console.writestring(volume^.filesystem^.sName); + console.writestring(' Free Space: '); + console.writeintln(volume^.freeSectors * volume^.sectorSize DIV 1024 DIV 1024); + end; + end; + + end; + end; +end; + + procedure init(); begin push_trace('storagemanagement.init'); storageDevices:= ll_New(sizeof(TStorage_Device)); fileSystems:= ll_New(sizeof(TFilesystem)); - terminal.registerCommand('DISK', @disk_command, 'List physical storage devices'); + terminal.registerCommand('DISK', @disk_command, 'Disk utility'); + terminal.registerCommand('VOLUME', @volume_command, 'Volume utility'); + terminal.registerCommand('POO', @test_command, 'Volume utility'); pop_trace(); end; @@ -144,10 +191,15 @@ var i : uint8; elm : void; begin + elm:= LL_Add(storageDevices); PStorage_device(elm)^ := device^; + PStorage_Device(LL_Get(storageDevices, LL_Size(storageDevices) - 1))^.volumes := LL_New(sizeof(TStorage_Volume)); //check for volumes + for i:=0 to ll_size(filesystems) - 1 do begin + PFileSystem(LL_Get(filesystems, i))^.detectCallback(PStorage_Device(LL_Get(storageDevices, LL_Size(storageDevices) - 1))); + end; end; function get_device_list() : PLinkedListBase; @@ -155,13 +207,21 @@ begin get_device_list:= storageDevices; end; + procedure register_filesystem(filesystem : PFilesystem); var - i : uint8; elm : void; begin elm:= LL_Add(fileSystems); PFileSystem(elm)^ := filesystem^; end; +procedure register_volume(device : PStorage_Device; volume : PStorage_Volume); +var + elm : void; +begin + elm := LL_Add(device^.volumes); + PStorage_volume(elm)^:= volume^; +end; + end. \ No newline at end of file diff --git a/src/include/strings.pas b/src/include/strings.pas index d25135ca..52747d3c 100644 --- a/src/include/strings.pas +++ b/src/include/strings.pas @@ -13,7 +13,8 @@ interface uses util, - lmemorymanager; + lmemorymanager, + lists; function stringToUpper(str : pchar) : pchar; function stringToLower(str : pchar) : pchar; @@ -26,9 +27,13 @@ function stringContains(str : pchar; sub : pchar) : boolean; function stringToInt(str : pchar) : uint32; function intToString(i : uint32) : pchar; function boolToString(b : boolean; ext : boolean) : pchar; +function stringToLL(str : pchar; delimter : char) : PLinkedListBase; implementation +uses + console; + function stringToUpper(str : pchar) : pchar; var result : pchar; @@ -173,4 +178,42 @@ begin end; end; +function stringToLL(str : pchar; delimter : char) : PLinkedListBase; //todo implment function for freeing pointer lists +var + list : PLinkedListBase; + i : uint32 = 0; + out_str : pchar; + elm : puint32; + head : pchar; + tail : pchar; + size : uint32; + null_delim : boolean; + +begin + list := LL_New(sizeof(uint32)); + stringToLL:= list; + + head:= str; + tail:= head; + + null_delim:= false; + while not null_delim do begin + if (head^ = delimter) or (head^ = char(0)) then begin + if head^ = char(0) then null_delim:= true; + size:= uint32(head) - uint32(tail); + console.writeintln(size); + if size > 0 then begin + elm:= puint32(LL_Add(list)); + out_str:= stringNew(size); + memcpy(uint32(tail), uint32(out_str), size); + elm^:= uint32(out_str); + end; + tail:= head+1; + end else begin + console.writecharln(head^); + end; + inc(head); + end; +end; + end. \ No newline at end of file