Flatfs reading and writing files and directories done
This commit is contained in:
parent
f88a282893
commit
27177979a2
@ -340,7 +340,7 @@ begin
|
|||||||
console.writestringln('IDE (writePIO28) ERROR: Invalid LBA!');
|
console.writestringln('IDE (writePIO28) ERROR: Invalid LBA!');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
push_trace('IDE.readPIO28.2');
|
// push_trace('IDE.readPIO28.2');
|
||||||
|
|
||||||
//Add last 4 bits of LBA to device port
|
//Add last 4 bits of LBA to device port
|
||||||
if IDEDevices[drive].isMaster then begin
|
if IDEDevices[drive].isMaster then begin
|
||||||
@ -352,7 +352,7 @@ begin
|
|||||||
device_select($F0 or ((LBA and $0F000000) shr 24)); //LBA primary slave
|
device_select($F0 or ((LBA and $0F000000) shr 24)); //LBA primary slave
|
||||||
end;
|
end;
|
||||||
|
|
||||||
push_trace('IDE.readPIO28.3');
|
// push_trace('IDE.readPIO28.3');
|
||||||
|
|
||||||
no_interrupt(device);
|
no_interrupt(device);
|
||||||
port_write(ATA_REG_ERROR, 0);
|
port_write(ATA_REG_ERROR, 0);
|
||||||
@ -363,7 +363,7 @@ begin
|
|||||||
port_write(ATA_REG_LBA1, (LBA and $0000FF00) shr 8);
|
port_write(ATA_REG_LBA1, (LBA and $0000FF00) shr 8);
|
||||||
port_write(ATA_REG_LBA2, (LBA and $00FF0000) shr 16);
|
port_write(ATA_REG_LBA2, (LBA and $00FF0000) shr 16);
|
||||||
|
|
||||||
push_trace('IDE.readPIO28.4');
|
// push_trace('IDE.readPIO28.4');
|
||||||
|
|
||||||
//send read command
|
//send read command
|
||||||
port_write(ATA_REG_COMMAND, ATA_CMD_READ_PIO);
|
port_write(ATA_REG_COMMAND, ATA_CMD_READ_PIO);
|
||||||
@ -381,7 +381,7 @@ begin
|
|||||||
i:= i + 2;
|
i:= i + 2;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
push_trace('IDE.readPIO28.5');
|
// push_trace('IDE.readPIO28.5');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure writePIO28(drive : uint8; LBA : uint32; buffer : puint8);
|
procedure writePIO28(drive : uint8; LBA : uint32; buffer : puint8);
|
||||||
|
@ -64,6 +64,7 @@ procedure detect_volumes(disk : PStorage_Device);
|
|||||||
function read_directory(volume : PStorage_Volume; directory : pchar; status : PuInt32) : PLinkedListBase;
|
function read_directory(volume : PStorage_Volume; directory : pchar; status : PuInt32) : PLinkedListBase;
|
||||||
procedure write_directory(volume : PStorage_Volume; directory : pchar; status : PuInt32);
|
procedure write_directory(volume : PStorage_Volume; directory : pchar; status : PuInt32);
|
||||||
procedure write_file(volume : PStorage_Volume; fileName : pchar; data : PuInt32; size : uint32; status : PuInt32);
|
procedure write_file(volume : PStorage_Volume; fileName : pchar; data : PuInt32; size : uint32; status : PuInt32);
|
||||||
|
procedure read_file(volume : PStorage_Volume; fileName : pchar; data : PuInt32; status : PuInt32);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -138,7 +139,14 @@ begin
|
|||||||
write_directory(volume, '/logs', status);
|
write_directory(volume, '/logs', status);
|
||||||
write_directory(volume, '/logs/test', status);
|
write_directory(volume, '/logs/test', status);
|
||||||
write_file(volume, '/logs/log.txt', PuInt32(data), 1, status);
|
write_file(volume, '/logs/log.txt', PuInt32(data), 1, status);
|
||||||
//read_directory(volume, '/logs', status);
|
write_file(volume, '/logs/log2.txt', PuInt32(data), 1, status);
|
||||||
|
write_file(volume, '/logs/log3.txt', PuInt32(data), 1, status);
|
||||||
|
read_directory(volume, '/logs', status);
|
||||||
|
|
||||||
|
kfree(puint32(data));
|
||||||
|
|
||||||
|
read_file(volume, '/logs/log.txt', PuInt32(data), status);
|
||||||
|
writestringlnWND(pchar(data), getterminalhwnd());
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure write_directory(volume : PStorage_Volume; directory : pchar; status : PuInt32);
|
procedure write_directory(volume : PStorage_Volume; directory : pchar; status : PuInt32);
|
||||||
@ -228,67 +236,52 @@ var
|
|||||||
|
|
||||||
compString : PChar;
|
compString : PChar;
|
||||||
afterString : PChar;
|
afterString : PChar;
|
||||||
|
slash : PChar;
|
||||||
compStringLength : uint32;
|
compStringLength : uint32;
|
||||||
|
|
||||||
fileCount : uint32 = 1000;
|
fileCount : uint32 = 1000;
|
||||||
|
|
||||||
|
slashArray : array[0..1] of char = '/';
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
||||||
writeStringlnWnd('read_directory', getTerminalHWND());
|
|
||||||
redrawWindows();
|
|
||||||
|
|
||||||
compString := pchar(kalloc(60));
|
compString := pchar(kalloc(60));
|
||||||
memset(uint32(compString), 0, 60);
|
memset(uint32(compString), 0, 60);
|
||||||
|
|
||||||
afterString := pchar(kalloc(60));
|
afterString := pchar(kalloc(60));
|
||||||
memset(uint32(afterString), 0, 60);
|
memset(uint32(afterString), 0, 60);
|
||||||
|
|
||||||
|
slash := stringNew(2);
|
||||||
|
memcpy(uint32(@slashArray), uint32(slash), 1);
|
||||||
|
|
||||||
directories := STRLL_New();
|
directories := STRLL_New();
|
||||||
|
|
||||||
fileEntrys := PFile_Entry(Kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
fileEntrys := PFile_Entry(Kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
||||||
push_trace('read_directory.b4_read');
|
|
||||||
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntrys));
|
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntrys));
|
||||||
push_trace('read_directory.after_read');
|
|
||||||
|
|
||||||
writeStringlnWnd('read_directory_1', getTerminalHWND());
|
|
||||||
redrawWindows();
|
|
||||||
|
|
||||||
for i := 0 to fileCount - 1 do begin
|
for i := 0 to fileCount - 1 do begin
|
||||||
// if fileEntrys[i].attribues and $10 = $10 then begin
|
|
||||||
writeStringlnWnd('read_directory_loop1', getTerminalHWND());
|
|
||||||
redrawWindows();
|
|
||||||
|
|
||||||
writestringlnWND(fileEntrys[i].name, getterminalhwnd());
|
|
||||||
|
|
||||||
push_trace('read_directory.loop1');
|
|
||||||
|
|
||||||
if uint32(fileEntrys[i].name[0]) = 0 then begin
|
if uint32(fileEntrys[i].name[0]) = 0 then begin
|
||||||
writestringlnWND('fileEntry^.name = nil', getterminalhwnd());
|
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
push_trace('read_directory.loop2');
|
|
||||||
|
|
||||||
compString := stringSub(fileEntrys[i].name, 0, stringSize(directory));
|
compString := stringSub(fileEntrys[i].name, 0, stringSize(directory));
|
||||||
afterString := stringSub(fileEntrys[i].name, stringSize(directory), stringSize(fileEntrys[i].name)-1);
|
afterString := stringSub(fileEntrys[i].name, stringSize(directory), stringSize(fileEntrys[i].name)-1);
|
||||||
|
|
||||||
writeStringlnWnd('read_directory_loop2', getTerminalHWND());
|
writestringlnWND(afterString, getterminalhwnd());
|
||||||
redrawWindows();
|
|
||||||
|
|
||||||
push_trace('read_directory.loop3');
|
push_trace('read_directory_2');
|
||||||
|
|
||||||
if stringEquals(compString, directory) and
|
if stringEquals(compString, directory) and
|
||||||
(not stringContains(afterString, '/')) then begin
|
(not stringContains(afterString, slash)) then begin
|
||||||
|
|
||||||
console.writestringlnWND(afterString, getTerminalHWND());
|
writestringlnWND(fileEntrys[i].name, getterminalhwnd());
|
||||||
STRLL_Add(directories, afterString);
|
STRLL_Add(directories, afterString);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
// end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
push_trace('read_directory.after_loop');
|
push_trace('read_directory_3');
|
||||||
|
|
||||||
Kfree(puint32(fileEntrys));
|
Kfree(puint32(fileEntrys));
|
||||||
|
|
||||||
@ -347,6 +340,8 @@ end;
|
|||||||
function find_free_space(volume : PStorage_Volume; size : uint32; status : PuInt32) : uint32;
|
function find_free_space(volume : PStorage_Volume; size : uint32; status : PuInt32) : uint32;
|
||||||
var
|
var
|
||||||
fileEntrys : PFile_Entry;
|
fileEntrys : PFile_Entry;
|
||||||
|
confirmedFileEntrys : PFile_Entry;
|
||||||
|
confirmedFileEntrysCount : uint32 = 0;
|
||||||
fileEntry : PFile_Entry;
|
fileEntry : PFile_Entry;
|
||||||
i : uint32;
|
i : uint32;
|
||||||
fileCount : uint32 = 1000;
|
fileCount : uint32 = 1000;
|
||||||
@ -354,39 +349,51 @@ var
|
|||||||
baseAddress : uint32;
|
baseAddress : uint32;
|
||||||
begin
|
begin
|
||||||
fileEntrys := PFile_Entry(Kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
fileEntrys := PFile_Entry(Kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
||||||
push_trace('find_free_space.before_read');
|
confirmedFileEntrys := PFile_Entry(Kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
||||||
|
memset(uint32(fileEntrys), 0, sizeof(TFile_Entry) * fileCount + 512);
|
||||||
|
memset(uint32(confirmedFileEntrys), 0, sizeof(TFile_Entry) * fileCount + 512);
|
||||||
|
|
||||||
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntrys));
|
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntrys));
|
||||||
push_trace('find_free_space.after_read');
|
|
||||||
|
|
||||||
baseAddress := volume^.sectorStart + 2 + ( (fileCount * sizeof(TFile_Entry)) div 512);
|
baseAddress := volume^.sectorStart + 2 + ( (fileCount * sizeof(TFile_Entry)) div 512);
|
||||||
|
|
||||||
|
for i := 0 to fileCount - 1 do begin
|
||||||
|
if fileEntrys[i].attribues <> 0 then begin
|
||||||
|
confirmedFileEntrys[confirmedFileEntrysCount] := fileEntrys[i];
|
||||||
|
confirmedFileEntrysCount := confirmedFileEntrysCount + 1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
//sort file table by start address using quicksort
|
//sort file table by start address using quicksort
|
||||||
//quicksort_start(fileEntrys, 0, fileCount - 1);
|
quicksort_start(confirmedFileEntrys, 0, confirmedFileEntrysCount - 1);
|
||||||
|
|
||||||
//find free space big enough to fit size //TODO: make this work
|
//find free space big enough to fit size //TODO: make this work
|
||||||
for i := 0 to fileCount - 1 do begin
|
for i := 0 to confirmedFileEntrysCount - 1 do begin
|
||||||
|
|
||||||
if fileEntrys[i+1].start = 0 then begin
|
if confirmedFileEntrys[i+1].attribues = 0 then begin
|
||||||
|
|
||||||
if fileEntrys[i].size = 0 then begin
|
if confirmedFileEntrys[i].size = 0 then begin
|
||||||
find_free_space := baseAddress;
|
find_free_space := baseAddress;
|
||||||
break;
|
break;
|
||||||
end else begin
|
end else begin
|
||||||
find_free_space := baseAddress + fileEntrys[i].start;
|
find_free_space := confirmedFileEntrys[i].start + confirmedFileEntrys[i].size;
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if fileEntrys[i+1].start - (fileEntrys[i].start + fileEntrys[i].size) > size+1 then begin
|
if confirmedFileEntrys[i].size <> 0 then begin
|
||||||
find_free_space := fileEntrys[i].start + fileEntrys[i].size;
|
if confirmedFileEntrys[i+1].start - (confirmedFileEntrys[i].start + confirmedFileEntrys[i].size) > size+1 then begin
|
||||||
|
find_free_space := confirmedFileEntrys[i].start + confirmedFileEntrys[i].size;
|
||||||
status^ := 0;
|
status^ := 0;
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
Kfree(puint32(fileEntrys));
|
Kfree(puint32(fileEntrys));
|
||||||
|
Kfree(puint32(confirmedFileEntrys));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure write_file(volume : PStorage_Volume; fileName : pchar; data : PuInt32; size : uint32; status : PuInt32);
|
procedure write_file(volume : PStorage_Volume; fileName : pchar; data : PuInt32; size : uint32; status : PuInt32);
|
||||||
@ -408,7 +415,6 @@ var
|
|||||||
|
|
||||||
elm : puint32;
|
elm : puint32;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
push_trace('flatfs.write_file');
|
push_trace('flatfs.write_file');
|
||||||
|
|
||||||
//load file table
|
//load file table
|
||||||
@ -417,11 +423,8 @@ begin
|
|||||||
|
|
||||||
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntries));
|
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntries));
|
||||||
|
|
||||||
push_trace('flatfs.write_file.after_read');
|
|
||||||
|
|
||||||
//check if file exists else find free entry
|
//check if file exists else find free entry
|
||||||
for i := 0 to fileCount - 1 do begin
|
for i := 0 to fileCount - 1 do begin
|
||||||
//fileEntry^ := fileEntries[i];
|
|
||||||
|
|
||||||
if stringEquals(fileEntries[i].name, fileName) then begin
|
if stringEquals(fileEntries[i].name, fileName) then begin
|
||||||
exsists := true;
|
exsists := true;
|
||||||
@ -439,25 +442,11 @@ begin
|
|||||||
//if entry is directory then exit
|
//if entry is directory then exit
|
||||||
if fileEntries[p].attribues and $10 = $10 then begin
|
if fileEntries[p].attribues and $10 = $10 then begin
|
||||||
status^ := 1;
|
status^ := 1;
|
||||||
|
|
||||||
writestringlnWND('write_file: file is directory', getTerminalHWND());
|
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
push_trace('flatfs.write_file.after_loop');
|
|
||||||
|
|
||||||
// //allocate file table
|
|
||||||
// buffer := PuInt32(Kalloc(512));
|
|
||||||
// memset(uint32(buffer), 0, 512);
|
|
||||||
|
|
||||||
// //read file table cointaining entry of interest
|
// //read file table cointaining entry of interest
|
||||||
position := (p * sizeof(TFile_Entry)) div 512;
|
position := (p * sizeof(TFile_Entry)) div 512;
|
||||||
// volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1 + position, 1, buffer);
|
|
||||||
|
|
||||||
//calculate entry offset into sector
|
|
||||||
// offset := (p * sizeof(TFile_Entry)) mod 512;
|
|
||||||
// offset := offset div sizeof(TFile_Entry);
|
|
||||||
|
|
||||||
//if file exists update entry else create new entry
|
//if file exists update entry else create new entry
|
||||||
if exsists then begin
|
if exsists then begin
|
||||||
@ -478,28 +467,79 @@ begin
|
|||||||
fileEntries[p].attribues := $01;
|
fileEntries[p].attribues := $01;
|
||||||
|
|
||||||
//add file name
|
//add file name
|
||||||
// fileEntry^.name := fileName;
|
|
||||||
memcpy(uint32(fileName), uint32(@fileEntries[p].name), 14);
|
memcpy(uint32(fileName), uint32(@fileEntries[p].name), 14);
|
||||||
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
writestringlnWND('write_file: writing file', getTerminalHWND());
|
|
||||||
|
|
||||||
//fileEntries[i] := fileEntry^;
|
|
||||||
|
|
||||||
//write file table
|
//write file table
|
||||||
volume^.device^.writeCallback(volume^.device, volume^.sectorStart + 1 , 1, puint32(@fileEntries[position])); /////
|
volume^.device^.writeCallback(volume^.device, volume^.sectorStart + 1 , 1, puint32(@fileEntries[position]));
|
||||||
|
|
||||||
writeIntLnWND(fileEntries[p].start, getTerminalHWND());
|
|
||||||
|
|
||||||
//write file
|
//write file
|
||||||
volume^.device^.writeCallback(volume^.device, fileEntries[p].start, size, data);
|
volume^.device^.writeCallback(volume^.device, fileEntries[p].start, size, data);
|
||||||
|
|
||||||
//free buffer
|
//free buffer
|
||||||
Kfree(puint32(buffer));
|
|
||||||
Kfree(puint32(fileEntries));
|
Kfree(puint32(fileEntries));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure read_file(volume : PStorage_Volume; fileName : pchar; data : PuInt32; status : PuInt32);
|
||||||
|
var
|
||||||
|
directories : PLinkedListBase;
|
||||||
|
i : uint32;
|
||||||
|
p : uint32;
|
||||||
|
|
||||||
|
fileEntries : PFile_Entry;
|
||||||
|
fileEntry : PFile_Entry;
|
||||||
|
|
||||||
|
fileCount : uint32 = 1000;
|
||||||
|
exsists : boolean = false;
|
||||||
|
|
||||||
|
size : uint32;
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
//load file table
|
||||||
|
fileEntries := PFile_Entry(Kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
||||||
|
memset(uint32(fileEntries), 0, sizeof(TFile_Entry) * fileCount);
|
||||||
|
|
||||||
|
volume^.device^.readCallback(volume^.device, volume^.sectorStart + 1, sizeof(TFile_Entry) * fileCount div 512, puint32(fileEntries));
|
||||||
|
|
||||||
|
//check if file exists else exit
|
||||||
|
for i := 0 to fileCount - 1 do begin
|
||||||
|
|
||||||
|
if stringEquals(fileEntries[i].name, fileName) then begin
|
||||||
|
exsists := true;
|
||||||
|
p:= i;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
//if entry is directory then exit
|
||||||
|
if fileEntries[p].attribues and $10 = $10 then begin
|
||||||
|
status^ := 1;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//if entry is not found exit
|
||||||
|
if fileEntries[i].attribues = 0 then begin
|
||||||
|
exsists := false;
|
||||||
|
p:= i;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
//file size rounded up to nearest 512
|
||||||
|
size := (fileEntries[p].size + 511) and -512;
|
||||||
|
|
||||||
|
//read file
|
||||||
|
data := Kalloc(size);
|
||||||
|
volume^.device^.readCallback(volume^.device, fileEntries[p].start, size, data);
|
||||||
|
|
||||||
|
//free buffer
|
||||||
|
Kfree(puint32(fileEntries));
|
||||||
|
|
||||||
|
status^ := 0;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure detect_volumes(disk : PStorage_Device);
|
procedure detect_volumes(disk : PStorage_Device);
|
||||||
var
|
var
|
||||||
buffer : puint32;
|
buffer : puint32;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user