getting ready
This commit is contained in:
1 parent
4e3acd6af7
commit
789fb7971a
25 files changed
+3142
-1093
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -20,7 +20,7 @@
|
||||
unit AHCITypes;
|
||||
interface
|
||||
uses
|
||||
console,
|
||||
syslog,
|
||||
drivermanagement,
|
||||
drivertypes,
|
||||
idetypes,
|
||||
|
||||
@@ -22,7 +22,7 @@ unit asfs;
|
||||
interface
|
||||
|
||||
uses
|
||||
console,
|
||||
syslog,
|
||||
lists,
|
||||
lmemorymanager,
|
||||
rtc,
|
||||
@@ -30,7 +30,7 @@ uses
|
||||
storagemanagement,
|
||||
storagemanager,
|
||||
strings,
|
||||
terminal,
|
||||
stdio,
|
||||
tracer,
|
||||
util;
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -27,8 +27,8 @@ uses
|
||||
strings,
|
||||
filesystemmanager,
|
||||
lists,
|
||||
console,
|
||||
terminal,
|
||||
syslog,
|
||||
stdio,
|
||||
storagemanager,
|
||||
storagetypes,
|
||||
lmemorymanager,
|
||||
@@ -148,7 +148,6 @@ begin
|
||||
kfree(puint32(data));
|
||||
|
||||
read_file(volume, '/logs/log.txt', PuInt32(data), status);
|
||||
writestringlnWND(pchar(data), getterminalhwnd());
|
||||
end;
|
||||
|
||||
procedure write_directory(volume : PStorage_Volume; directory : pchar; status : PuInt32);
|
||||
@@ -271,14 +270,12 @@ begin
|
||||
compString := stringSub(fileEntrys[i].name, 0, stringSize(directory));
|
||||
afterString := stringSub(fileEntrys[i].name, stringSize(directory), stringSize(fileEntrys[i].name)-1);
|
||||
|
||||
writestringlnWND(afterString, getterminalhwnd());
|
||||
|
||||
push_trace('read_directory_2');
|
||||
|
||||
if stringEquals(compString, directory) and
|
||||
(not stringContains(afterString, slash)) then begin
|
||||
|
||||
writestringlnWND(fileEntrys[i].name, getterminalhwnd());
|
||||
STRLL_Add(directories, afterString);
|
||||
end;
|
||||
end;
|
||||
@@ -542,6 +539,56 @@ begin
|
||||
status^ := 0;
|
||||
end;
|
||||
|
||||
{ Count free sectors on a FlatFS volume by scanning file entries. }
|
||||
function countFreeFlatFSSectors(volume : PStorage_Volume) : uint32;
|
||||
var
|
||||
buffer : puint32;
|
||||
diskInfo : PDisk_Info;
|
||||
sectorCount : uint32;
|
||||
fileCount : uint32;
|
||||
tableSectors : uint32;
|
||||
fileEntries : PFile_Entry;
|
||||
usedSectors : uint32;
|
||||
overhead : uint32;
|
||||
i : uint32;
|
||||
begin
|
||||
countFreeFlatFSSectors := 0;
|
||||
|
||||
buffer := puint32(kalloc(512));
|
||||
memset(uint32(buffer), 0, 512);
|
||||
storagemanager.storage_read(volume^.device, volume^.sectorStart, 1, buffer);
|
||||
|
||||
diskInfo := PDisk_Info(buffer);
|
||||
sectorCount := diskInfo^.sectorCount;
|
||||
fileCount := diskInfo^.fileCount;
|
||||
kfree(buffer);
|
||||
|
||||
if sectorCount = 0 then exit;
|
||||
|
||||
tableSectors := (fileCount * sizeof(TFile_Entry)) div 512;
|
||||
overhead := 2 + tableSectors; { header + boundary + file table }
|
||||
|
||||
usedSectors := 0;
|
||||
if fileCount > 0 then begin
|
||||
fileEntries := PFile_Entry(kalloc(sizeof(TFile_Entry) * fileCount + 512));
|
||||
memset(uint32(fileEntries), 0, sizeof(TFile_Entry) * fileCount);
|
||||
storagemanager.storage_read(volume^.device, volume^.sectorStart + 1,
|
||||
tableSectors, puint32(fileEntries));
|
||||
|
||||
for i := 0 to fileCount - 1 do begin
|
||||
if fileEntries[i].attribues <> 0 then
|
||||
usedSectors := usedSectors + fileEntries[i].size;
|
||||
end;
|
||||
|
||||
kfree(puint32(fileEntries));
|
||||
end;
|
||||
|
||||
if sectorCount > (overhead + usedSectors) then
|
||||
countFreeFlatFSSectors := sectorCount - overhead - usedSectors
|
||||
else
|
||||
countFreeFlatFSSectors := 0;
|
||||
end;
|
||||
|
||||
procedure detect_volumes(disk : PStorage_Device);
|
||||
var
|
||||
buffer : puint32;
|
||||
@@ -553,7 +600,7 @@ begin
|
||||
memset(uint32(buffer), 0, 512);
|
||||
|
||||
if (disk^.readCallback = nil) and (disk^.readCallbackAsync = nil) then begin
|
||||
console.writestringln('FlatFS: detect_volumes: device has no read callback.');
|
||||
syslog.writestringln('FlatFS: detect_volumes: device has no read callback.');
|
||||
kfree(buffer);
|
||||
exit;
|
||||
end;
|
||||
@@ -561,15 +608,15 @@ begin
|
||||
storagemanager.storage_read(disk, 2, 1, buffer);
|
||||
|
||||
if (PDisk_Info(buffer)^.signature = $0B00B1E5) then begin
|
||||
console.writestringln('FlatFS: volume found!');
|
||||
syslog.writestringln('FlatFS: volume found!');
|
||||
volume := PStorage_volume(kalloc(sizeof(TStorage_Volume)));
|
||||
memset(uint32(volume), 0, sizeof(TStorage_Volume));
|
||||
volume^.device := disk;
|
||||
volume^.sectorStart := 2;
|
||||
volume^.sectorSize := 512;
|
||||
volume^.sectorCount := PDisk_Info(buffer)^.sectorCount;
|
||||
volume^.freeSectors := 0; { TODO: implement free sector count }
|
||||
volume^.filesystem := @filesystem;
|
||||
volume^.freeSectors := countFreeFlatFSSectors(volume);
|
||||
volume^.isBootDrive := false;
|
||||
|
||||
volumemanager.register_volume(disk, volume);
|
||||
@@ -710,7 +757,6 @@ begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
function identify_volume(volume : PStorage_Volume) : boolean;
|
||||
var
|
||||
buffer : puint32;
|
||||
@@ -724,8 +770,10 @@ begin
|
||||
|
||||
storagemanager.storage_read(volume^.device, volume^.sectorStart, 1, buffer);
|
||||
|
||||
if (PDisk_Info(buffer)^.signature = $0B00B1E5) then
|
||||
if (PDisk_Info(buffer)^.signature = $0B00B1E5) then begin
|
||||
identify_volume := true;
|
||||
volume^.freeSectors := countFreeFlatFSSectors(volume);
|
||||
end;
|
||||
|
||||
kfree(buffer);
|
||||
end;
|
||||
|
||||
@@ -12,7 +12,7 @@ unit iso9660;
|
||||
interface
|
||||
|
||||
uses
|
||||
console,
|
||||
syslog,
|
||||
filesystemmanager,
|
||||
lists,
|
||||
lmemorymanager,
|
||||
|
||||
@@ -13,13 +13,13 @@ unit partitiontable;
|
||||
interface
|
||||
|
||||
uses
|
||||
console,
|
||||
syslog,
|
||||
lists,
|
||||
lmemorymanager,
|
||||
rtc,
|
||||
storagemanagement,
|
||||
strings,
|
||||
terminal,
|
||||
stdio,
|
||||
tracer,
|
||||
util;
|
||||
|
||||
|
||||
@@ -16,11 +16,13 @@ uses
|
||||
lmemorymanager,
|
||||
MBR,
|
||||
storagetypes,
|
||||
syslog,
|
||||
tracer,
|
||||
util;
|
||||
|
||||
var
|
||||
storageDevices : PDList;
|
||||
nextDeviceId : uint32;
|
||||
|
||||
procedure init();
|
||||
procedure register_device(device : PStorage_Device);
|
||||
@@ -40,17 +42,32 @@ procedure storage_write(device : PStorage_Device; addr : uint32; sectors : uint3
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
volumemanager;
|
||||
|
||||
procedure init();
|
||||
begin
|
||||
push_trace('StorageManager.init');
|
||||
storageDevices := DL_New(sizeof(TStorage_Device));
|
||||
nextDeviceId := 0;
|
||||
end;
|
||||
|
||||
procedure register_device(device : PStorage_Device);
|
||||
var
|
||||
storedDev : PStorage_Device;
|
||||
begin
|
||||
push_trace('StorageManager.register_device');
|
||||
device^.id := nextDeviceId;
|
||||
nextDeviceId := nextDeviceId + 1;
|
||||
DL_Add(storageDevices);
|
||||
DL_Set(storageDevices, DL_Size(storageDevices) - 1, puint32(device));
|
||||
|
||||
{ Get pointer to the DList copy so volumes reference the canonical device }
|
||||
storedDev := PStorage_Device(DL_Get(storageDevices, DL_Size(storageDevices) - 1));
|
||||
|
||||
{ Discover partitions and register volumes automatically }
|
||||
if storedDev^.maxSectorCount > 0 then
|
||||
volumemanager.discover_volumes(storedDev);
|
||||
end;
|
||||
|
||||
function get_device_list() : PDList;
|
||||
@@ -115,10 +132,7 @@ begin
|
||||
device^.readCallbackAsync(device, addr, sectors, buffer, @storage_sync_done, @done);
|
||||
asm sti end;
|
||||
while done = 0 do begin
|
||||
asm hlt end; { sleep until next interrupt }
|
||||
{ Fallback: if the hardware IRQ was not delivered through the PIC,
|
||||
poll the driver inline so the completion fires. }
|
||||
if (done = 0) and (device^.pollCallback <> nil) then
|
||||
if device^.pollCallback <> nil then
|
||||
device^.pollCallback();
|
||||
end;
|
||||
end else if device^.readCallback <> nil then
|
||||
@@ -134,8 +148,7 @@ begin
|
||||
device^.writeCallbackAsync(device, addr, sectors, buffer, @storage_sync_done, @done);
|
||||
asm sti end;
|
||||
while done = 0 do begin
|
||||
asm hlt end; { sleep until next interrupt }
|
||||
if (done = 0) and (device^.pollCallback <> nil) then
|
||||
if device^.pollCallback <> nil then
|
||||
device^.pollCallback();
|
||||
end;
|
||||
end else if device^.writeCallback <> nil then
|
||||
|
||||
+497
-487
File diff suppressed because it is too large.
Load diff
+108
-106
File diff suppressed because it is too large.
Load diff
@@ -13,7 +13,7 @@ unit volumemanager;
|
||||
interface
|
||||
|
||||
uses
|
||||
console,
|
||||
syslog,
|
||||
filesystemmanager,
|
||||
lists,
|
||||
lmemorymanager,
|
||||
@@ -21,7 +21,7 @@ uses
|
||||
storagemanager,
|
||||
storagetypes,
|
||||
strings,
|
||||
terminal,
|
||||
stdio,
|
||||
tracer,
|
||||
util;
|
||||
|
||||
|
||||
Reference in new issue
Block a user