Work on storage and flat file system

This commit is contained in:
Aaron committed 2022-02-01 05:07:52 +00:00
1 parent 24c371cab1
commit ff4c597ff3
7 files changed
+455 -33

No files matched your search

+4 -2
View File
@@ -446,7 +446,8 @@ var
begin
push_trace('IDE.dread');
for i:=0 to sectorCount-1 do begin
readPIO28(device^.controllerId0, LBA, puint8(@buffer[512*i]));
readPIO28(device^.controllerId0, LBA + i, puint8(@buffer[512*i]));
psleep(100)
end;
end;
@@ -455,7 +456,8 @@ var
i : uint16;
begin
for i:=0 to sectorCount-1 do begin
writePIO28(device^.controllerId0, LBA, puint8(@buffer[512*i]));
writePIO28(device^.controllerId0, LBA + i, puint8(@buffer[512*i]));
psleep(100)
end;
// writePIO28(device^.controllerId0, LBA, puint8(buffer));
end;
+38 -6
View File
@@ -95,18 +95,21 @@ var
i : uint32 = 0;
begin
push_trace('DriverManager.format_command');
//format <DRIVE_ID> <FILESYSTEM> <size>
spc:= puint32(kalloc(4));
spc^:= 1;
push_trace('DriverManager.format_command.0');
//get drive from index/id
driveIndex:= stringToInt( getParam(1, params) );
drive:= PStorage_Device(LL_Get(storageDevices, driveIndex));
filesystemString := getParam(2, params);
sectorCount := stringToInt( getParam(4, params) );
sectorCount := stringToInt( getParam(3, params) );
// if sector count is 0, use full drive
if sectorCount = 0 then begin
@@ -114,11 +117,14 @@ begin
end;
//create MBR if none, and partition table
mb := PMaster_Boot_Record(kalloc(sizeof(TMaster_Boot_Record)));
mb := PMaster_Boot_Record(kalloc(sizeof(TMaster_Boot_Record)*2));
memset(uint32(mb), 0, sizeof(TMaster_Boot_Record));
drive^.readCallback(drive, 0, 1, PuInt32(mb));
//check if MBR exists
if not mb^.boot_sector = $55AA then begin
if (mb^.boot_sector <> $55AA)then begin
writestringlnWND('Creating MBR', getTerminalHWND());
//create MBR
mb^.signature := $A570 + drive^.id;
@@ -130,6 +136,20 @@ begin
//write MBR
drive^.writeCallback(drive, 0, 1, puint32(mb));
end else begin
writestringlnWND('MBR already exists', getTerminalHWND());
//write first partiton sectorStart and sectorCount
writeintlnWND(mb^.partition[0].LBA_start, getTerminalHWND());
writeintlnWND(mb^.partition[0].sector_count, getTerminalHWND());
//create partition table
mbr.setup_partition(@mb^.partition[0], 2, sectorCount);
//write MBR
drive^.writeCallback(drive, 0, 1, puint32(mb));
end;
kfree(puint32(mb));
@@ -176,19 +196,23 @@ var
begin
push_trace('DriverManager.drive_command');
subcmd:= getParam(0, params);
push_trace('DriverManager.drive_command.0');
if ((paramCount(params) = 0)) then 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(' format [drive] [filesystem] [size (0 for max)] - destructive, formats a drive with MBR and volume', getTerminalHWND());
exit;
end;
push_trace('DriverManager.drive_command.1');
if( stringEquals(subcmd, 'ls') ) then begin
list_drive_command();
exit;
end;
push_trace('DriverManager.drive_command.2');
if( stringEquals(subcmd, 'info') ) then begin
console.writestringWnd('Disk: ', getTerminalHWND());
@@ -196,14 +220,22 @@ begin
console.writestringWnd('Capacity: ', getTerminalHWND());
console.writeintlnWND(1, getTerminalHWND());
//TODO impliement
exit
//TODO impliment
exit;
end;
if( stringEquals(subcmd, 'init') ) then begin
init_drive_command(stringToInt(getParam(1, params) ) );
exit
exit;
end;
push_trace('DriverManager.drive_command.3');
if( stringEquals(subcmd, 'format') ) then begin
format_command(params);
exit;
end;
push_trace('DriverManager.drive_command.4');
end;
{ Initialise the drive manager }
+20 -4
View File
@@ -91,7 +91,7 @@ var
filesystem : TFilesystem;
procedure init;
procedure create_volume(disk : PStorage_Device; sectors : uint32; start : uint32; config : puint32);
procedure create_volume(volume : PStorage_Volume; 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
@@ -753,7 +753,7 @@ 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(volume : PStorage_Volume; sectors : uint32; start : uint32; config : puint32);
var
buffer : puint32;
bt: puint32;
@@ -774,9 +774,18 @@ var
programFileArray : byteArray8 = ('P','R','O','G','R','A','M','S');
rootCluster : uint32 = 1;
sysArray : byteArray8 = ('S','Y','S','T','E','M',' ',' ');
progArray : byteArray8 = ('P','R','O','G','R','A','M','S');
userArray : byteArray8 = ('U','S','E','R',' ',' ',' ',' ');
status : puint32;
disk : PStorage_device;
begin //maybe increase buffer size by one?
push_trace('fat32.create_volume()');
disk := volume^.device;
// zeroBuffer:= puint32(kalloc( disk^.sectorSize * 4 ));
// memset(uint32(zeroBuffer), 0, disk^.sectorSize * 4);
@@ -813,7 +822,7 @@ begin //maybe increase buffer size by one?
bootRecord^.jmp2boot := $0; //TODO impliment boot jump
bootRecord^.OEMName := asuroArray;
bootRecord^.sectorSize := disk^.sectorsize;
bootRecord^.spc := config^;
bootRecord^.spc := 1;
bootRecord^.rsvSectors := 32; //32 is standard
bootRecord^.numFats := 1;
bootRecord^.mediaDescp := $F8;
@@ -875,8 +884,16 @@ begin //maybe increase buffer size by one?
disk^.writecallback(disk, dataStart + (config^ * rootCluster), 1, buffer);
memset(uint32(buffer), 0, disk^.sectorsize);
status := puint32(kalloc(sizeof(uint32)));
writeDirectory(volume, '', sysArray, $10, status, '');
kfree(buffer);
end;
procedure detect_volumes(disk : PStorage_Device);
@@ -926,7 +943,6 @@ begin
filesystem.detectcallback:= @detect_volumes;
filesystem.writecallback:= @writeFile;
filesystem.readcallback := @readFile;
// filesystem.formatVolumeCallback := @create_volume;
volumemanager.register_filesystem(@filesystem);
end;
File diff suppressed because it is too large. Load diff
+34 -3
View File
@@ -44,7 +44,7 @@ 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; start : uint32; size : uint32; config : puint32);
PPCreateHook = procedure(volume : PStorage_volume; 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
@@ -290,6 +290,22 @@ begin
end;
procedure remove_volume(list : PLinkedListBase; volume : PStorage_Volume);
var
i : uint32;
elm : void;
begin
for i:=0 to LL_Size(list) - 1 do begin
elm := LL_Get(list, i);
if (PStorage_Volume(elm)^.device = volume^.device)
and (PStorage_Volume(elm)^.sectorStart = volume^.sectorStart) then begin
LL_Delete(list, i);
break;
end;
end;
end;
procedure create_volume(disk : PStorage_device; filesystem : PChar; sectorStart : uint32; sectorCount : uint32);
var
volume : PStorage_Volume;
@@ -298,10 +314,12 @@ var
config : PuInt32;
begin
push_trace('VolumeManager.create_volume');
volume := PStorage_Volume(kalloc(SizeOf(TStorage_Volume)));
volume^.device := disk;
volume^.sectorStart := sectorStart;
volume^.sectorCount := sectorCount - 10; //-10 is temp also in storagemanager
volume^.sectorCount := sectorCount - 10;
volume^.sectorSize := disk^.sectorSize;
volume^.freeSectors := 0; //setup by filesystem
@@ -312,17 +330,30 @@ begin
end;
end;
//format volume
volume^.filesystem^.createCallback(disk, sectorStart, sectorCount, config);
volume^.filesystem^.createCallback(volume, sectorCount, sectorStart, config);
push_trace('VolumeManager.create_volume.2');
//remove volume from list of volumes
remove_volume(storageVolumes, volume);
//add volume to list
elm := LL_Add(storageVolumes);
memcpy(uint32(volume), uint32(elm), SizeOf(TStorage_Volume));
push_trace('VolumeManager.create_volume.3');
//remove volume from list of volumes on device
remove_volume(disk^.volumes, volume);
//add volume to device
elm := LL_Add(disk^.volumes);
memcpy(uint32(volume), uint32(elm), SizeOf(TStorage_Volume));
//free memory
kfree(puint32(volume));
end;
procedure register_volume(device : PStorage_Device; volume : PStorage_Volume);