git-svn-id: https://spexeah.com:8443/svn/Asuro@594 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
parent
db57eb7cd8
commit
2d902a1380
@ -247,6 +247,7 @@ begin
|
||||
storagemanagement.register_device(@storageDevice1);
|
||||
end;
|
||||
end;
|
||||
|
||||
pop_trace();
|
||||
end;
|
||||
|
||||
|
@ -62,7 +62,7 @@ type
|
||||
|
||||
byteArray8 = array[0..7] of char;
|
||||
|
||||
TDirectory = bitpacked record
|
||||
TDirectory = packed record
|
||||
fileName : array[0..7] of char;
|
||||
fileExtension : array[0..2] of char;
|
||||
attributes : uint8;
|
||||
@ -100,6 +100,9 @@ var
|
||||
procedure init;
|
||||
procedure create_volume(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32);
|
||||
procedure detect_volumes(disk : PStorage_Device);
|
||||
//function writeDirectory(volume : PStorage_volume; directory : pchar; attributes : uint32) : uint8; // need to handle parent table cluster overflow, need to take attributes
|
||||
//function readDirectory(volume : PStorage_volume; directory : pchar; listPtr : PLinkedListBase) : uint8; //returns: 0 = success, 1 = dir not exsist, 2 = not directory, 3 = error
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
@ -124,12 +127,14 @@ var
|
||||
bootRecord : TBootRecord;
|
||||
fatSize : uint32;
|
||||
begin
|
||||
push_trace('fat32.readFat');
|
||||
bootRecord := readBootRecord(volume);
|
||||
fatSize:= bootrecord.fatSize;
|
||||
buffer:= puint32(kalloc(fatSize));
|
||||
volume^.device^.readcallback(volume^.device, volume^.sectorStart + 2 + (cluster * 32 div volume^.sectorSize), 1, buffer);
|
||||
readFat:= buffer[cluster];
|
||||
kfree(buffer);
|
||||
pop_trace();
|
||||
end;
|
||||
|
||||
procedure writeFat(volume : PStorage_volume; cluster : uint32; value : uint32); // untested, but should work
|
||||
@ -138,6 +143,7 @@ var
|
||||
bootRecord : TBootRecord;
|
||||
fatSize : uint32;
|
||||
begin
|
||||
push_trace('writefat');
|
||||
bootRecord := readBootRecord(volume);
|
||||
fatSize:= bootrecord.fatSize;
|
||||
buffer:= puint32(kalloc(fatSize));
|
||||
@ -145,6 +151,7 @@ begin
|
||||
buffer[cluster]:= value;
|
||||
volume^.device^.writeCallback(volume^.device, volume^.sectorStart + 2 + (cluster * 32 div volume^.sectorSize), 1, buffer);
|
||||
kfree(buffer);
|
||||
pop_trace();
|
||||
end;
|
||||
|
||||
|
||||
@ -155,7 +162,7 @@ var
|
||||
clusters : PLinkedListBase;
|
||||
dirElm : void;
|
||||
buffer : puint32;
|
||||
bufferI : puint32;
|
||||
//buffer : puint32;
|
||||
bootRecord : TBootRecord;
|
||||
clusterInfo : uint32;
|
||||
cc : uint32;
|
||||
@ -167,6 +174,7 @@ var
|
||||
str : pchar;
|
||||
targetStr : pchar;
|
||||
dir : PDirectory;
|
||||
clusterAllocSize : uint32;
|
||||
begin
|
||||
push_trace('fat32.readDirectory');
|
||||
|
||||
@ -195,11 +203,7 @@ begin
|
||||
|
||||
//build list of clusters for current directory table
|
||||
while true do begin
|
||||
console.writestring('cluster: ');
|
||||
console.writeintln(cc);
|
||||
clusterInfo:= readFat(volume, cc);
|
||||
console.writestring('info: ');
|
||||
console.writehexln(clusterInfo);
|
||||
if clusterInfo = $FFFFFFF7 then begin
|
||||
readDirectory:= 3; //ERROR
|
||||
break;
|
||||
@ -219,47 +223,55 @@ begin
|
||||
end;
|
||||
|
||||
//load clusters into buffer
|
||||
buffer:= puint32(kalloc( (clusterByteSize * (LL_size(clusters) - 1)) + 1));
|
||||
bufferI := buffer;
|
||||
clusterAllocSize:= (clusterByteSize * (LL_size(clusters))) + 1;
|
||||
buffer:= puint32(kalloc(clusterAllocSize));
|
||||
//buffer := buffer;
|
||||
for i:= 0 to LL_size(clusters) - 1 do begin
|
||||
cc:= uint32(LL_Get(clusters, i)^);
|
||||
device^.readcallback(device, volume^.sectorStart + 1 + fatSectorSize + (bootRecord.spc * cc), bootrecord.spc, puint32(buffer + (i * clusterByteSize)) );
|
||||
device^.readcallback(device, volume^.sectorStart + 1 + fatSectorSize + (bootRecord.spc * cc), bootrecord.spc, @buffer[i * (clusterByteSize div 4)] );
|
||||
end;
|
||||
|
||||
if dirI = LL_size(directories) - 1 then break;
|
||||
if LL_size(directories) = 0 then break;
|
||||
|
||||
//get elements in the directory table
|
||||
i:=0;
|
||||
while true do begin
|
||||
dir:= PDirectory(bufferI);
|
||||
if dir^.fileName[0] = char(0) then break; //need to check if I have found the right directoy and set cc if not last
|
||||
if (dir^.attributes and $10) = $10 then begin // is a directory;
|
||||
str:= dir^.fileName;
|
||||
dir:= PDirectory(buffer);
|
||||
console.writestringln(dir[i].fileName);
|
||||
|
||||
if dir[i].fileName[0] = char(0) then break; //need to check if I have found the right directoy and set cc if not last
|
||||
if (dir[i].attributes and $10) = $10 then begin // is a directory;
|
||||
str:= dir[i].fileName;
|
||||
str[9]:= char(0);
|
||||
if stringEquals(str, targetStr) then begin //need to get current folder searching for
|
||||
cc:= dir^.clusterLow;
|
||||
cc:= cc or (dir^.clusterHigh shl 16);
|
||||
cc:= dir[i].clusterLow;
|
||||
cc:= cc or (dir[i].clusterHigh shl 16);
|
||||
end;
|
||||
end;
|
||||
|
||||
dirElm:= LL_Add(rootTable);
|
||||
PDirectory(dirElm)^:= PDirectory(bufferI)^;
|
||||
bufferI:= puint32(bufferI + 8);
|
||||
//dirElm:= LL_Add(rootTable);
|
||||
//PDirectory(dirElm)^:= dir[i];
|
||||
i+=1;
|
||||
end;
|
||||
|
||||
//set CC
|
||||
dirI += 1;
|
||||
end;
|
||||
|
||||
i:=0;
|
||||
while true do begin
|
||||
dir:= PDirectory(bufferI);
|
||||
if dir^.fileName[0] = char(0) then break;
|
||||
dirElm:= LL_Add(rootTable);
|
||||
PDirectory(dirElm)^:= PDirectory(bufferI)^;
|
||||
bufferI:= puint32(bufferI + 8);
|
||||
dir:= PDirectory(buffer);
|
||||
if dir[i].fileName[0] = char(0) then break;
|
||||
|
||||
dirElm:= LL_Add(listPtr);
|
||||
PDirectory(dirElm)^:= dir[i];
|
||||
i+=1;
|
||||
end;
|
||||
|
||||
kfree(buffer);
|
||||
listPtr := rootTable;
|
||||
//listPtr := rootTable;
|
||||
//console.writeintln(uint32(listPtr));
|
||||
|
||||
// while true do begin // I need to be inside another loop
|
||||
// if PDirectory(buffer)^.fileName[0] = char(0) then break;
|
||||
@ -275,7 +287,7 @@ begin
|
||||
pop_trace();
|
||||
end;
|
||||
|
||||
function writeDirectory(volume : PStorage_volume; directory : pchar; attributes : uint32) : uint8; // need to handle parent table cluster overflow, need to take attributes
|
||||
function writeDirectory(volume : PStorage_volume; directory : pchar; dirName : pchar; attributes : uint32) : uint8; // need to handle parent table cluster overflow, need to take attributes
|
||||
var
|
||||
dirAddr : PLinkedListBase;
|
||||
dirList : PLinkedListBase;
|
||||
@ -295,6 +307,7 @@ var
|
||||
meArray : byteArray8 = ('.', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
|
||||
parentArray : byteArray8 = ('.', '.', ' ', ' ', ' ', ' ', ' ', ' ');
|
||||
begin
|
||||
push_trace('fat32.writeDirectory');
|
||||
dirAddr := stringToLL(directory, '/');
|
||||
//dirList := LL_New(sizeof(TDirectory));
|
||||
bootRecord := readBootRecord(volume);
|
||||
@ -302,31 +315,45 @@ begin
|
||||
buffer := puint32(kalloc(sizeof(volume^.sectorSize)));
|
||||
dataStart:= (bootrecord.fatSize) + 1 + volume^.sectorStart;
|
||||
|
||||
console.writestringln('1');
|
||||
|
||||
//find un allocated cluster
|
||||
while not foundCluster do begin
|
||||
volume^.device^.readcallback(volume^.device, volume^.sectorStart + 2 + (i * 32 div volume^.sectorSize), 1, buffer);
|
||||
for ii:=0 to 127 do begin
|
||||
if puint32(buffer + ii)^ = 0 then begin //found unallocated cluster
|
||||
emptyCluster:= (i * 16) + ii;
|
||||
emptyCluster:= (i * 32) + ii;
|
||||
foundCluster:= true;
|
||||
break;
|
||||
end;
|
||||
end;
|
||||
i+= 1;
|
||||
end;
|
||||
kfree(buffer);
|
||||
|
||||
console.writestring('Writtifng new dir to: '); /////////////////////////////////////////////////////////////
|
||||
console.writehexln(emptyCluster);
|
||||
|
||||
//write fat
|
||||
writeFat(volume, emptyCluster, $FFFFFFF8);
|
||||
|
||||
//find directory table
|
||||
for i:=0 to LL_size(dirAddr) - 2 do begin //construct address for parent directory
|
||||
str2:= pchar( puint32(LL_Get(dirAddr, i))^ );
|
||||
str:= stringConcat(str, str2);
|
||||
end;
|
||||
console.writestringln('1.1');
|
||||
// //find directory table
|
||||
// for i:=0 to LL_size(dirAddr) - 2 do begin //construct address for parent directory
|
||||
// console.writestringln('1.2');
|
||||
// str2:= pchar( puint32(LL_Get(dirAddr, i))^ );
|
||||
// console.writestringln('1.3');
|
||||
// str:= stringConcat(str, str2);
|
||||
// end;
|
||||
str:= directory;
|
||||
dirList:= LL_New(sizeof(TDirectory));
|
||||
console.writestringln(str);
|
||||
writeDirectory:= readDirectory(volume, str, dirList); //hope str is correct, maybe need /
|
||||
console.writestringln('1.4');
|
||||
console.writeintln(LL_size(dirlist));
|
||||
targetDirectory:= PDirectory(LL_Get(dirList, 0));
|
||||
prevDirCluster:= targetDirectory^.clusterLow or (targetDirectory^.clusterHigh shl 16);
|
||||
console.writestringln('1.5');
|
||||
prevDirCluster:= targetDirectory^.clusterLow or uint32(targetDirectory^.clusterHigh shl 16);
|
||||
console.writestringln('2');
|
||||
|
||||
buffer:= puint32(kalloc(volume^.sectorSize)); //nope, need write one sector, the right sector
|
||||
//size of dirlist TDIRECTORY (byte size of cluster) / 32 = max no of directories per cluster
|
||||
@ -355,7 +382,7 @@ begin
|
||||
if buffer^ = 0 then begin //found empty slot
|
||||
str:= pchar(LL_Get(dirAddr, LL_size(dirAddr) - 1));
|
||||
|
||||
PDirectory(buffer + ((sizeof(TDirectory) * i) DIV 4) )^.fileName:= byteArray8(str);
|
||||
PDirectory(buffer + ((sizeof(TDirectory) * i) DIV 4) )^.fileName:= byteArray8(dirName);
|
||||
PDirectory(buffer + ((sizeof(TDirectory) * i) DIV 4) )^.attributes:= attributes;
|
||||
PDirectory(buffer + ((sizeof(TDirectory) * i) DIV 4) )^.clusterLow:= emptyCluster;
|
||||
PDirectory(buffer + ((sizeof(TDirectory) * i) DIV 4) )^.clusterHigh:= emptyCluster shl 16;
|
||||
@ -371,7 +398,7 @@ begin
|
||||
//if directory
|
||||
if attributes = $10 then begin
|
||||
kfree(buffer);
|
||||
buffer:= puint32(kalloc(sizeof(TDirectory)));
|
||||
buffer:= puint32(kalloc(sizeof(TDirectory) * 2)); // should never be less than one sector
|
||||
i:=0;
|
||||
PDirectory(buffer + ((sizeof(TDirectory) * i) DIV 4) )^.fileName:= meArray;
|
||||
PDirectory(buffer + ((sizeof(TDirectory) * i) DIV 4) )^.attributes:= attributes;
|
||||
@ -387,6 +414,7 @@ begin
|
||||
device^.writecallback(device, datastart + emptyCluster, 1, buffer);
|
||||
end;
|
||||
kfree(buffer);
|
||||
pop_trace();
|
||||
end;
|
||||
|
||||
procedure readFile(volume : PStorage_volume; directory : pchar; byteCount : uint32; buffer : puint32);
|
||||
@ -406,6 +434,8 @@ begin
|
||||
filesystem.readcallback:= @readFile;
|
||||
filesystem.createcallback:= @create_volume;
|
||||
filesystem.detectcallback:= @detect_volumes;
|
||||
filesystem.createDirCallback:= @writeDirectory;
|
||||
filesystem.readDirCallback:= @readDirectory;
|
||||
storagemanagement.register_filesystem(@filesystem);
|
||||
end;
|
||||
|
||||
@ -514,6 +544,9 @@ var
|
||||
buffer : puint32;
|
||||
i : uint8;
|
||||
volume : PStorage_volume;
|
||||
|
||||
dir : PDirectory;
|
||||
dirs : PLinkedListBase;
|
||||
begin
|
||||
push_trace('detect volume');
|
||||
volume:= PStorage_volume(kalloc(sizeof(TStorage_Volume)));
|
||||
@ -533,7 +566,19 @@ begin
|
||||
storagemanagement.register_volume(disk, volume);
|
||||
end;
|
||||
|
||||
//readDirectory(volume, 'hello/word', nil);
|
||||
|
||||
// dirs:= LL_New(sizeof(TDirectory));
|
||||
// readDirectory(volume, '', dirs);
|
||||
|
||||
// for i:=0 to LL_size(dirs) - 1 do begin
|
||||
// dir:= PDirectory(LL_Get(dirs, i));
|
||||
// console.writestringln(pchar(dir^.fileName));
|
||||
// end;
|
||||
|
||||
//writeDirectory(volume, '', 'hello', $10);
|
||||
//writeDirectory(volume, '', 'poo', $10);
|
||||
//readDirectory(volume, '.', dirs);
|
||||
|
||||
pop_trace();
|
||||
end;
|
||||
|
||||
|
@ -33,15 +33,20 @@ type
|
||||
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);
|
||||
PPCreateDirHook = function(volume : PStorage_volume; directory : pchar; dirname : pchar; attributes : uint32) : uint8;
|
||||
PPReadDirHook = function(volume : PStorage_volume; directory : pchar; listPtr : PLinkedListBase) : uint8; //returns: 0 = success, 1 = dir not exsist, 2 = not directory, 3 = error
|
||||
|
||||
|
||||
PPHIOHook_ = procedure;
|
||||
|
||||
TFilesystem = record
|
||||
sName : pchar;
|
||||
writeCallback : PPIOHook;
|
||||
readCallback : PPIOHook;
|
||||
createCallback : PPCreateHook;
|
||||
detectCallback : PPDetectHook;
|
||||
writeCallback : PPIOHook;
|
||||
readCallback : PPIOHook;
|
||||
createCallback : PPCreateHook;
|
||||
detectCallback : PPDetectHook;
|
||||
createDirCallback : PPCreateDirHook;
|
||||
readDirCallback : PPReadDirHook;
|
||||
end;
|
||||
PFileSystem = ^TFilesystem;
|
||||
|
||||
@ -134,7 +139,7 @@ begin
|
||||
drive := stringToInt(getParam(1, params));
|
||||
console.writeintln(drive); // works
|
||||
if stringEquals(getParam(2, params), 'fat32') then begin
|
||||
PFilesystem(LL_Get(filesystems, 0))^.createCallback((PStorage_Device(LL_Get(storageDevices, drive))), 1000000, 1, spc); //todo check fs
|
||||
PFilesystem(LL_Get(filesystems, 0))^.createCallback((PStorage_Device(LL_Get(storageDevices, drive))), 10000, 1, spc); //todo check fs
|
||||
console.writestring('Drive ');
|
||||
//console.writeint(drive); // page faults
|
||||
console.writestringln(' formatted.');
|
||||
@ -149,6 +154,65 @@ begin
|
||||
pop_trace;
|
||||
end;
|
||||
|
||||
procedure mkdir_command(params : PParamList);
|
||||
var
|
||||
dir : pchar;
|
||||
device : PStorage_Device;
|
||||
volume : PStorage_Volume;
|
||||
error : uint32;
|
||||
begin
|
||||
if paramCount(params) > 0 then begin
|
||||
dir := getParam(0, params);
|
||||
device:= PStorage_Device(LL_Get(storageDevices, 0));
|
||||
volume:= PStorage_Volume(LL_Get(device^.volumes, 0));
|
||||
|
||||
//error:= volume^.filesystem^.createDirCallback(volume, dir, $10);
|
||||
if error <> 1 then console.writestringln('ERROR');
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure ls_command(params : PParamList);
|
||||
type
|
||||
TDirectory = bitpacked record
|
||||
fileName : array[0..7] of char;
|
||||
fileExtension : array[0..2] of char;
|
||||
attributes : uint8;
|
||||
reserved0 : uint8;
|
||||
timeFine : uint8;
|
||||
time : uint16;
|
||||
date : uint16;
|
||||
accessTime : uint16;
|
||||
clusterHigh : uint16;
|
||||
modifiedTime : uint16;
|
||||
modifiedDate : uint16;
|
||||
clusterLow : uint16;
|
||||
byteSize : uint32;
|
||||
end;
|
||||
PDirectory = ^TDirectory;
|
||||
var
|
||||
dirs : PLinkedListBase;
|
||||
dir : pchar;
|
||||
device : PStorage_Device;
|
||||
volume : PStorage_Volume;
|
||||
error : uint32;
|
||||
i : uint32;
|
||||
begin
|
||||
if paramCount(params) > 0 then begin
|
||||
dir := getParam(0, params);
|
||||
device:= PStorage_Device(LL_Get(storageDevices, 0));
|
||||
volume:= PStorage_Volume(LL_Get(device^.volumes, 0));
|
||||
|
||||
error:= volume^.filesystem^.readDirCallback(volume, dir, dirs);
|
||||
|
||||
if error <> 1 then console.writestringln('ERROR');
|
||||
|
||||
for i:=0 to LL_Size(dirs) - 1 do begin
|
||||
console.writestring(' ');
|
||||
console.writestringln(pchar( PDirectory(LL_Get(dirs, 0))^.filename ));
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure volume_command(params : PParamList);
|
||||
var
|
||||
i : uint32;
|
||||
@ -183,7 +247,8 @@ begin
|
||||
fileSystems:= ll_New(sizeof(TFilesystem));
|
||||
terminal.registerCommand('DISK', @disk_command, 'Disk utility');
|
||||
terminal.registerCommand('VOLUME', @volume_command, 'Volume utility');
|
||||
terminal.registerCommand('POO', @test_command, 'Volume utility');
|
||||
terminal.registerCommand('mkdir', @mkdir_command, 'Volume utility');
|
||||
terminal.registerCommand('ls', @ls_command, 'Volume utility');
|
||||
pop_trace();
|
||||
end;
|
||||
|
||||
|
@ -14,7 +14,7 @@ interface
|
||||
const
|
||||
KERNEL_VIRTUAL_BASE = $C0000000;
|
||||
KERNEL_PAGE_NUMBER = KERNEL_VIRTUAL_BASE SHR 22;
|
||||
BSOD_ENABLE = true;
|
||||
BSOD_ENABLE = false;
|
||||
TRACER_ENABLE = true;
|
||||
|
||||
type
|
||||
|
@ -118,18 +118,17 @@ var
|
||||
i : uint32;
|
||||
|
||||
begin
|
||||
push_trace('util.printmemory');
|
||||
buf:= puint8(source);
|
||||
for i:=0 to length do begin
|
||||
for i:=0 to length-1 do begin
|
||||
if offset_row and (i = 0) then begin
|
||||
console.writehex(source + (i * col));
|
||||
console.writehex(source + (i));
|
||||
console.writestring(': ');
|
||||
end;
|
||||
console.writehexpair(buf[i]);
|
||||
if ((i+1) MOD col) = 0 then begin
|
||||
console.writestringln(' ');
|
||||
if offset_row then begin
|
||||
console.writehex(source + (i * col));
|
||||
console.writehex(source + (i + 1));
|
||||
console.writestring(': ');
|
||||
end;
|
||||
end else begin
|
||||
@ -137,7 +136,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
console.writestringln(' ');
|
||||
pop_trace;
|
||||
end;
|
||||
|
||||
function hi(b : uint8) : uint8; [public, alias: 'util_hi'];
|
||||
|
Loading…
x
Reference in New Issue
Block a user