git-svn-id: https://spexeah.com:8443/svn/Asuro@755 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c

This commit is contained in:
aaron 2018-10-27 06:30:17 +00:00
parent 6a47590418
commit a50e770c1a
5 changed files with 222 additions and 25 deletions

View File

@ -813,6 +813,8 @@ const
DefaultWND = 0; //< The Window assigned for output when no Window is specified. (Default). DefaultWND = 0; //< The Window assigned for output when no Window is specified. (Default).
implementation implementation
uses
lmemorymanager, strings, keyboard, serial, terminal;
type type
{ Properties pertaining to the raw screen matrix. } { Properties pertaining to the raw screen matrix. }
@ -935,9 +937,6 @@ var
MouseCursorEnabled : Boolean = true; MouseCursorEnabled : Boolean = true;
OpenTerminal : Boolean = false; OpenTerminal : Boolean = false;
uses
lmemorymanager, strings, keyboard, serial, terminal;
function getWindowColorPtr : puint32; function getWindowColorPtr : puint32;
begin begin
getWindowColorPtr:= @Window_Border.Attributes; getWindowColorPtr:= @Window_Border.Attributes;

View File

@ -351,7 +351,7 @@ begin
end; //drive error end; //drive error
end; end;
for ii:=0 to 127 do begin //read data for ii:=0 to 127 do begin //write data
outw($1F0, Puint32(buffer + ((i * 512) + (ii * 32) DIV 32) )^); outw($1F0, Puint32(buffer + ((i * 512) + (ii * 32) DIV 32) )^);
while true do if (inw($1f7) and (1 shl 7)) = 0 then break; //Wait until drive not busy while true do if (inw($1f7) and (1 shl 7)) = 0 then break; //Wait until drive not busy
outb($1F7, $E7); outb($1F7, $E7);

View File

@ -499,7 +499,7 @@ begin
bufferPointer:= @PDirectory(buffer)[LL_size(directories)]; bufferPointer:= @PDirectory(buffer)[LL_size(directories)];
bufferPointer^.fileName:= cleanString(dirName, status); bufferPointer^.fileName:= cleanString(dirName, status);
bufferPointer^.attributes:= attributes; bufferPointer^.attributes:= attributes;
//if attributes = 0 then bufferPointer^.fileExtension:= fileExtension; if attributes = 0 then bufferPointer^.fileExtension:= fileExtension;
bufferPointer^.clusterLow:= cluster; bufferPointer^.clusterLow:= cluster;
bufferPointer^.clusterHigh:= uint16((cluster shr 16) and $0000FFFF); bufferPointer^.clusterHigh:= uint16((cluster shr 16) and $0000FFFF);
@ -537,6 +537,7 @@ var
dataStart : uint32; dataStart : uint32;
iterations : uint32; iterations : uint32;
bufferPointer : puint32; bufferPointer : puint32;
dataPosition : uint32;
i : uint32; i : uint32;
status : puint32; status : puint32;
@ -553,14 +554,14 @@ begin
for i:=0 to LL_size(directories) - 1 do begin for i:=0 to LL_size(directories) - 1 do begin
dir:= PDirectory(LL_get(directories, i)); dir:= PDirectory(LL_get(directories, i));
if (dir^.fileName = entry^.fileName) and (dir^.fileExtension = entry^.extension) then begin if (dir^.fileName = entry^.fileName) and (dir^.fileExtension = entry^.extension) then begin
exists:= true; exists:= true;
break; break;
end; end;
end; end;
push_trace('writefile.1'); push_trace('writefile.1');
if exists then begin if exists then begin //saving to existing file
startCluster:= uint32(dir^.clusterlow) or uint32(dir^.clusterhigh shl 16); startCluster:= uint32(dir^.clusterlow) or uint32(dir^.clusterhigh shl 16);
clusters:= getFatChain(volume, startCluster, bootRecord); //check no clusters and check if needs to be more or less, add/remove clusters clusters:= getFatChain(volume, startCluster, bootRecord); //check no clusters and check if needs to be more or less, add/remove clusters
clusterCount := LL_size(clusters); clusterCount := LL_size(clusters);
@ -588,7 +589,7 @@ begin
push_trace('writefile.1.2.1'); push_trace('writefile.1.2.1');
startCluster:= writeDirectory(volume, directory, entry^.fileName, 0, status, entry^.extension); startCluster:= writeDirectory(volume, directory, entry^.fileName, 0, status, entry^.extension);
clusterDifference:= (byteCount div bootRecord^.sectorsize) - 1; clusterDifference:= (byteCount div bootRecord^.sectorsize) div 4; //-1 is that needed?
push_trace('writefile.1.2.2'); push_trace('writefile.1.2.2');
for i:= startcluster to startCluster + clusterDifference - 1 do begin for i:= startcluster to startCluster + clusterDifference - 1 do begin
@ -598,20 +599,115 @@ begin
writeFat(volume, startcluster + clusterDifference, $FFFFFFF8, bootRecord); writeFat(volume, startcluster + clusterDifference, $FFFFFFF8, bootRecord);
//setup fat chain //setup fat chain
console.writestringWND('clust diff: ', getTerminalHWND());
console.writeintlnWND(clusterDifference, getTerminalHWND());
console.writestringWND('startclust: ', getTerminalHWND());
console.writeintlnWND(startcluster, getTerminalHWND());
end; end;
push_trace('writefile.2'); push_trace('writefile.2');
iterations:= (bytecount div bootRecord^.sectorSize) div 4; iterations:= (bytecount div bootRecord^.sectorSize) div bootRecord^.spc; //no of clusters
for i:=0 to byteCount div bootRecord^.sectorSize do begin for i:=0 to iterations do begin
bufferPointer:= @buffer[i * uint32(bootRecord^.sectorsize * 4)]; console.writestringlnWND('writting to file', getTerminalHWND());
volume^.device^.writecallback(volume^.device, dataStart + startCluster, 4, bufferPointer); dataPosition:= i * uint32(bootRecord^.sectorsize * 4); //needs to be bytes / 4
bufferPointer:= @buffer[dataPosition div 4]; //todo change to puint8
volume^.device^.writecallback(volume^.device, dataStart + (startCluster * bootRecord^.spc) + (i * 4), 1, bufferPointer); //i * 4 needs to be changed, TODO fix fucking IDE driver, it suks
volume^.device^.writecallback(volume^.device, dataStart + (startCluster * bootRecord^.spc) + (i * 4) + 1, 1, @bufferPointer[512 div 4]);
volume^.device^.writecallback(volume^.device, dataStart + (startCluster * bootRecord^.spc) + (i * 4) + 2, 1, @bufferPointer[1024 div 4]);
volume^.device^.writecallback(volume^.device, dataStart + (startCluster * bootRecord^.spc) + (i * 4) + 3, 1, @bufferPointer[1536 div 4]);
end; end;
kfree(puint32(bootRecord)); kfree(puint32(bootRecord));
end; end;
function readFile(volume : PStorage_Volume; directory : pchar; fileName : pchar; fileExtension : pchar; buffer : puint32; bytecount : puint32) : uint32;
var
bootRecord : PBootRecord;
directories : PLinkedListBase;
dir : PDirectory;
readbuffer : puint32;
data : puint32;
statusOut : puint32;
i : uint32;
exists : boolean = false;
cluster : uint32;
clusters: PLinkedListBase;
noClusters : uint32;
dataStart : uint32;
begin
bootRecord := readBootRecord(volume);
directories := readDirectory(volume, directory, statusOut);
datastart:= volume^.sectorStart + 1 + bootRecord^.FATSize + bootRecord^.rsvSectors;
for i:=0 to LL_Size(directories) -1 do begin
dir:= PDirectory(LL_Get(directories, i));
if (dir^.fileName = fileName) and (dir^.fileExtension = fileextension) then begin
exists:= true;
break;
end;
end;
if exists = false then begin
statusOut^ := 0; //TODO use right error codes
exit(0);
end else begin
cluster := dir^.clusterlow;
cluster := cluster or dir^.clusterhigh shl 16;
clusters := getFatChain(volume, cluster, bootRecord);
noClusters := LL_size(clusters);
data := puint32(kalloc(noClusters * bootRecord^.spc * bootRecord^.sectorSize));
memset(uint32(data), 0, noClusters * bootRecord^.spc * bootRecord^.sectorSize);
readbuffer := puint32(kalloc(bootRecord^.sectorSize));
memset(uint32(readbuffer), 0, bootRecord^.sectorSize);
for i:=0 to noClusters * bootRecord^.spc do begin
volume^.device^.readcallback(volume^.device, dataStart + (cluster + i), 1, readbuffer);
memcpy(uint32(readbuffer), uint32(@data[i*bootRecord^.sectorSize]), bootRecord^.sectorSize)
end;
kfree(readbuffer);
buffer := data;
readFile := noClusters * bootRecord^.spc * bootRecord^.sectorSize;
end;
end;
// function checkExists(volume : PStorage_Volume; directory : pchar; fileName : pchar; fileExtension : pchar; entry : PDirectory_Entry) : uint32;
// var
// bootRecord : PBootRecord;
// directories : PLinkedListBase;
// dir : PDirectory;
// genDir : PDirectory_Entry;
// data : puint32;
// statusOut : puint32;
// i : uint32;
// exists : boolean = false;
// begin
// bootRecord := readBootRecord(volume);
// directories := readDirectory(volume, directory, statusOut);
// datastart:= volume^.sectorStart + 1 + bootRecord^.FATSize + bootRecord^.rsvSectors;
// for i:=0 to LL_Size(directories) -1 do begin
// dir:= PDirectory(LL_Get(directories, i));
// if (dir^.fileName = entry^.fileName) and (dir^.fileExtension = entry^.extension) then begin
// exists:= true;
// break;
// end;
// end;
// PDirectory_Entry := PDirectory_Entry(kalloc(20));
// PDirectory_Entry^.fileName := pchar(@dir^.fileName);
// PDirectory_Entry^.extension := pchar(@dir^.fileExtension);
// end;
//TODO check directory commands for errors with a clean disk
procedure create_volume(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32); procedure create_volume(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32);
var var
buffer : puint32; buffer : puint32;
@ -631,16 +727,23 @@ var
mountFileArray : byteArray8 = ('M','O','U','N','T',' ',' ',' '); mountFileArray : byteArray8 = ('M','O','U','N','T',' ',' ',' ');
programFileArray : byteArray8 = ('P','R','O','G','R','A','M','S'); programFileArray : byteArray8 = ('P','R','O','G','R','A','M','S');
rootCluster : uint32 = 1; rootCluster : uint32 = 1;
begin
begin //maybe increase buffer size by one?
push_trace('fat32.create_volume()'); push_trace('fat32.create_volume()');
// zeroBuffer:= puint32(kalloc( disk^.sectorSize * 4 )); // zeroBuffer:= puint32(kalloc( disk^.sectorSize * 4 ));
// memset(uint32(zeroBuffer), 0, disk^.sectorSize * 4); // memset(uint32(zeroBuffer), 0, disk^.sectorSize * 4);
// console.writeintlnWND(disk^.sectorsize, getTerminalHWND());
// console.writehexlnWND(zeroBuffer[(disk^.sectorSize) - 1], getTerminalHWND());
// console.writehexlnWND(uint32(zeroBuffer), getTerminalHWND());
// console.redrawWindows();
// while true do begin // while true do begin
// if i > sectors then break; // if i > sectors then break;
// disk^.writecallback(disk, 1 + i, 1, zeroBuffer); // disk^.writecallback(disk, 1 + i, 1, zeroBuffer);
// i+=1;
// i+=1;
// end; // end;
// kfree(zeroBuffer); // kfree(zeroBuffer);
@ -650,8 +753,13 @@ begin
(* File Allocation Table *) (* File Allocation Table *)
(* Data Area *) (* Data Area *)
buffer:= puint32(kalloc(sizeof(TBootRecord))); // buffer:= puint32(kalloc(sizeof(TBootRecord)));
memset(uint32(buffer), 0, sizeof(TBootRecord)); // memset(uint32(buffer), 0, sizeof(TBootRecord));
// bootRecord:= PBootRecord(buffer);
buffer:= puint32(kalloc(2048));
memset(uint32(buffer), 0, 2048);
bootRecord:= PBootRecord(buffer); bootRecord:= PBootRecord(buffer);
FATSize:= ((sectors div config^) * 4) div disk^.sectorsize; FATSize:= ((sectors div config^) * 4) div disk^.sectorsize;
@ -686,7 +794,7 @@ begin
while true do begin while true do begin
if i > FATSize DIV 4 then break; if i > FATSize DIV 4 then break;
disk^.writecallback(disk, fatStart + i, 4, zeroBuffer); disk^.writecallback(disk, fatStart + i, 4, zeroBuffer);
i+=4; i+=1;
end; end;
kfree(buffer); kfree(buffer);
@ -764,6 +872,7 @@ begin
filesystem.createcallback:= @create_volume; filesystem.createcallback:= @create_volume;
filesystem.detectcallback:= @detect_volumes; filesystem.detectcallback:= @detect_volumes;
filesystem.writecallback:= @writeFile; filesystem.writecallback:= @writeFile;
filesystem.readcallback := @readFile;
storagemanagement.register_filesystem(@filesystem); storagemanagement.register_filesystem(@filesystem);
end; end;

View File

@ -35,6 +35,7 @@ type
PDirectory_Entry = ^TDirectory_Entry; PDirectory_Entry = ^TDirectory_Entry;
PPWriteHook = procedure(volume : PStorage_volume; directory : pchar; entry : PDirectory_Entry; byteCount : uint32; buffer : puint32; statusOut : puint32); 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); 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; sectors : uint32; start : uint32; config : puint32);
PPDetectHook = procedure(disk : PStorage_Device); PPDetectHook = procedure(disk : PStorage_Device);
@ -46,7 +47,7 @@ type
TFilesystem = record TFilesystem = record
sName : pchar; sName : pchar;
writeCallback : PPWriteHook; writeCallback : PPWriteHook;
//readCallback : PPIOHook; readCallback : PPReadHook;
createCallback : PPCreateHook; createCallback : PPCreateHook;
detectCallback : PPDetectHook; detectCallback : PPDetectHook;
createDirCallback : PPCreateDirHook; createDirCallback : PPCreateDirHook;
@ -100,6 +101,8 @@ function get_device_list() : PLinkedListBase;
procedure register_filesystem(filesystem : PFilesystem); procedure register_filesystem(filesystem : PFilesystem);
procedure register_volume(device : PStorage_Device; volume : PStorage_Volume); 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 //TODO write partition table
@ -349,16 +352,21 @@ var
buffer : puint32; buffer : puint32;
entry : TDirectory_Entry; entry : TDirectory_Entry;
error : puint32; error : puint32;
i : uint32 = 1;
fatArray : byteArray8 = ('F','A','T','3','2',' ',' ',' ');
begin begin
push_trace('txt_command'); push_trace('txt_command');
error:= puint32(kalloc(512)); error:= puint32(kalloc(512));
memset(uint32(buffer), 0, 512); buffer:= puint32(kalloc(2048));
pchar(buffer)^ := getParam(0, params)^; memset(uint32(buffer), 0, 2048);
entry.fileName:= 'file'; entry.fileName:= getParam(0, params);
entry.extension:= 'txt'; entry.extension:= 'txt';
entry.entryType:= TDirectory_Entry_Type.fileEntry; entry.entryType:= TDirectory_Entry_Type.fileEntry;
PByteArray8(buffer)^ := fatArray;
push_trace('txt_cmd_'); push_trace('txt_cmd_');
rootVolume^.filesystem^.writeCallback(rootVolume, '.', @entry, stringSize(pchar(buffer)), buffer, error); //need to change the function pointer to match and impiment it in the filesystem init. rootVolume^.filesystem^.writeCallback(rootVolume, '.', @entry, stringSize(pchar(buffer)), buffer, error); //need to change the function pointer to match and impiment it in the filesystem init.
end; end;
@ -418,4 +426,83 @@ begin
if rootVolume = PStorage_Volume(0) then rootVolume:= volume; if rootVolume = PStorage_Volume(0) then rootVolume:= volume;
end; end;
function writeNewFile(fileName : pchar; extension : pchar; buffer : puint32; size : uint32) : uint32;
var
entry : TDirectory_Entry;
error : puint32;
begin
push_trace('storagemanagment.writenewfile');
error:= puint32(kalloc(512));
entry.fileName:= fileName;
entry.extension:= extension;
entry.entryType:= TDirectory_Entry_Type.fileEntry;
rootVolume^.filesystem^.writeCallback(rootVolume, getWorkingDirectory(), @entry, size, buffer, error);
writeNewFile:= error^; //memory leak
end;
function cleanString(str : pchar) : pchar;
var
i : uint32;
ii: uint32;
begin
cleanString:= pchar(kalloc(10));
memset(uint32(cleanstring), 0, 10);
for i:=0 to 7 do begin
if str[i] = char(0) then begin
for ii:=i to 7 do begin
cleanString[ii]:= ' ';
end;
break;
end else begin
cleanString[i]:= str[i];
end;
end;
end;
function readFile(fileName : pchar; extension : pchar; buffer : puint32; byteCount : puint32) : puint32; //TODO add length param
var
error : puint32;
dirs : PLinkedListBase;
exists : boolean = false;
i : uint32;
cleanFileName : pchar;
otherCleanFileName : pchar;
begin
push_trace('storagemanagement.readfile');
bytecount := puint32(kalloc(4));
error := puint32(kalloc(4));
readfile:= error;
cleanFileName := cleanString(filename);
dirs := rootVolume^.filesystem^.readdirCallback(rootVolume, getWorkingDirectory(), error);
for i:=0 to LL_Size(dirs) -1 do begin
otherCleanFileName := cleanString(PDirectory_Entry(LL_get(dirs, i))^.filename); //TODO clean extension
writestringlnWND(otherCleanFileName, getTerminalHWND());
writestringlnWND(cleanFileName, getTerminalHWND());
if stringEquals(cleanFileName, otherCleanFileName) then begin
writestringlnWND('match found!', getTerminalHWND());
exists := true;
error^ := 0;
end;
kfree(puint32(otherCleanFileName));
end;
kfree(puint32(cleanFileName));
if exists = false then begin
// TODO error codes
error^ := 1;
exit;
end;
rootVolume^.filesystem^.readCallback(rootVolume, getWorkingDirectory(), fileName, extension, buffer, bytecount);
exit;
end;
end. end.

View File

@ -43,7 +43,8 @@ uses
netlog, netlog,
vmlog, vmlog,
vm, vm,
vmstate; vmstate,
edit;
procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall; procedure kmain(mbinfo: Pmultiboot_info_t; mbmagic: uint32); stdcall;
@ -217,7 +218,8 @@ begin
vmlog.init(); vmlog.init();
tracer.push_trace('kmain.VMSTATEINIT'); tracer.push_trace('kmain.VMSTATEINIT');
vmstate.init(); vmstate.init();
tracer.push_trace('kmain.EDIT');
edit.init();
terminal.run(); terminal.run();
{ Init Splash } { Init Splash }