more improvements

This commit is contained in:
2026-03-15 23:58:52 +00:00
parent 4810617922
commit 5d7aacc28f
17 changed files with 2417 additions and 457 deletions
+1 -1
View File
@@ -1860,7 +1860,7 @@ begin
if (error = eNone) and (nfctx^.handle <> 0) then begin
{ WriteFileAsync needs a non-nil buffer; Length=0 so it is never read }
driver.storage.vfs.WriteFileAsync(nfctx^.handle, 0,
puint8(@nfctx^.err), 0, @fb_newfile_written, nfctx);
puint8(@nfctx^.err), 0, nil, @fb_newfile_written, nfctx);
end else begin
if nfctx^.handle <> 0 then
driver.storage.vfs.CloseFile(nfctx^.handle);
+7 -3
View File
@@ -27,8 +27,8 @@ uses
core.strings, arch.x86.bda;
const
FILE_SIZE = 10 * 1024 * 1024; { 10 MB }
CHUNK_SIZE = 4096*64; { MB per is 4k*64 = 256 KB, so 40 chunks total }
FILE_SIZE = 25 * 1024 * 1024; { 25 MB }
CHUNK_SIZE = 4096*128; { MB per is 4k*128 = 512 KB, so 50 chunks total }
TICK_HZ = 1024; { timer ISR frequency }
DEFAULT_PATH : pchar = '/disk/vol0/IOTEST.BIN';
@@ -89,7 +89,7 @@ begin
verBuf := puint8(kalloc(CHUNK_SIZE));
{ ==================== WRITE PHASE ==================== }
io.stdio.bufWriteStr(stdout_buf, 'Writing 10 MB to ');
io.stdio.bufWriteStr(stdout_buf, 'Writing 25 MB to ');
io.stdio.bufWriteStrLn(stdout_buf, path);
fh := OpenFile(path, omCreate, @fErr);
@@ -131,7 +131,9 @@ begin
end;
end;
t1 := arch.x86.bda.Counters.c32;
io.stdio.bufWriteStrLn(stdout_buf, 'Closing write handle...');
CloseFile(fh);
io.stdio.bufWriteStrLn(stdout_buf, 'Write handle closed.');
if ok then begin
elapsed := t1 - t0;
@@ -215,7 +217,9 @@ begin
end;
end;
t1 := arch.x86.bda.Counters.c32;
io.stdio.bufWriteStrLn(stdout_buf, 'Closing read handle...');
CloseFile(fh);
io.stdio.bufWriteStrLn(stdout_buf, 'Read handle closed.');
if ok then begin
elapsed := t1 - t0;
File diff suppressed because it is too large Load Diff
@@ -269,6 +269,9 @@ type
port : PHBA_Port;
device_type : TDeviceType;
ata_info : TIdentResponse;
supportsNCQ : boolean;
queueDepth : uint32; { safe active depth for this device }
slotCount : uint32; { controller slot count from CAP.NCS + 1 }
command_list : PHBA_CMD_HEADER;
fis : PHBA_FIS;
command_table: PHBA_CMD_TABLE;
@@ -335,4 +338,3 @@ end;
// end;
end.
@@ -86,7 +86,8 @@ end;
Returns actual bytes copied. }
function rd_ReadOffset(volume : PStorage_Volume; directory : pchar;
fileName : pchar; offset : uint32;
buffer : puint32; byteCount : uint32) : uint32;
buffer : puint32; byteCount : uint32;
ctx : pointer) : uint32;
var
clean : pchar;
idx : sint32;
@@ -45,10 +45,12 @@ const
ATA_CMD_READ_PIO_EXT = $24;
ATA_CMD_READ_DMA = $C8;
ATA_CMD_READ_DMA_EXT = $25;
ATA_CMD_READ_FPDMA_QUEUED = $60;
ATA_CMD_WRITE_PIO = $30;
ATA_CMD_WRITE_PIO_EXT = $34;
ATA_CMD_WRITE_DMA = $CA;
ATA_CMD_WRITE_DMA_EXT = $35;
ATA_CMD_WRITE_FPDMA_QUEUED = $61;
ATA_CMD_CACHE_FLUSH = $E7;
ATA_CMD_CACHE_FLUSH_EXT = $EA;
ATA_CMD_PACKET = $A0;
@@ -146,4 +148,4 @@ type
implementation
end.
end.
@@ -37,6 +37,7 @@ type
PFileDescriptor = ^TFileDescriptor;
TFileDescriptor = record
InUse : boolean;
AsyncRefs : uint32; { in-flight async ops using this descriptor }
Volume : PStorage_Volume;
Directory : pchar; { directory path within the volume }
FileName : pchar; { filename within that directory }
@@ -45,6 +46,8 @@ type
DataSize : uint32; { cached file size in bytes (from fileSizeCallback) }
DeviceOps : pointer; { PVFSDeviceOps — non-nil for device FDs }
DeviceData : pointer; { opaque data passed to device callbacks }
FSPrivate : pointer; { opaque FS-level per-file metadata (from openFileCallback) }
FSCloseHook : pointer; { procedure(pointer) — frees FSPrivate on close }
end;
PFDTable = ^TFDTable;
@@ -68,6 +71,9 @@ function fd_alloc(table : PFDTable) : uint32;
{ Get a pointer to the descriptor for a 1-based handle.
Returns nil if handle is out of range or the slot is not in use. }
function fd_get(table : PFDTable; handle : uint32) : PFileDescriptor;
function fd_begin_async(entry : PFileDescriptor) : boolean;
procedure fd_end_async(entry : PFileDescriptor);
function fd_has_async(entry : PFileDescriptor) : boolean;
{ Close a single file descriptor: free its buffers and core.strings,
mark the slot as not-in-use.
@@ -94,11 +100,20 @@ begin
fd_table_new := tbl;
end;
type
TFSPrivateClose = procedure(data : pointer);
procedure fd_free_entry(entry : PFileDescriptor);
begin
if entry = nil then exit;
if not entry^.InUse then exit;
{ Free FS-level per-file metadata first }
if (entry^.FSPrivate <> nil) and (entry^.FSCloseHook <> nil) then
TFSPrivateClose(entry^.FSCloseHook)(entry^.FSPrivate);
entry^.FSPrivate := nil;
entry^.FSCloseHook := nil;
if entry^.Directory <> nil then begin
kfree(void(entry^.Directory));
entry^.Directory := nil;
@@ -113,6 +128,7 @@ begin
end;
entry^.InUse := false;
entry^.AsyncRefs := 0;
entry^.DataSize := 0;
entry^.DeviceOps := nil;
entry^.DeviceData := nil;
@@ -148,6 +164,34 @@ begin
fd_get := @table^.Entries[handle - 1];
end;
function fd_begin_async(entry : PFileDescriptor) : boolean;
begin
fd_begin_async := false;
if entry = nil then exit;
asm pushf; cli end;
if entry^.InUse then begin
entry^.AsyncRefs := entry^.AsyncRefs + 1;
fd_begin_async := true;
end;
asm popf end;
end;
procedure fd_end_async(entry : PFileDescriptor);
begin
if entry = nil then exit;
asm pushf; cli end;
if entry^.AsyncRefs > 0 then
entry^.AsyncRefs := entry^.AsyncRefs - 1;
asm popf end;
end;
function fd_has_async(entry : PFileDescriptor) : boolean;
begin
fd_has_async := false;
if entry = nil then exit;
fd_has_async := entry^.AsyncRefs > 0;
end;
function fd_close(table : PFDTable; handle : uint32) : boolean;
begin
fd_close := false;
@@ -14,7 +14,7 @@
{
Driver->Storage->IORequest - I/O request allocation and lifecycle helpers.
Provides heap allocation/free for TIORequest records used by the
Provides fixed-pool allocation/free for TIORequest records used by the
submit_io / complete_io path in driver.storage.mgr.pas.
@author(Aaron Hance <[email protected]>)
@@ -27,7 +27,7 @@ uses
memory.heap,
driver.storage.types;
{ Allocate a new TIORequest on the heap and initialise its core fields.
{ Allocate a new TIORequest from the fixed request pool and initialise its core fields.
Caller, State, Error and ByteCount are zeroed (caller fills as needed). }
function ioreq_alloc(reqType : TIORequestType;
device : PStorage_Device;
@@ -35,16 +35,90 @@ function ioreq_alloc(reqType : TIORequestType;
sectors : uint32;
buf : pointer) : PIORequest;
{ Free a heap-allocated TIORequest. Safe to call with nil. }
{ Return a pooled TIORequest to the free list. Safe to call with nil. }
procedure ioreq_free(req : PIORequest);
{ Copy an existing TIORequest into a new heap allocation (deep copy of the
{ Copy an existing TIORequest into a new pooled allocation (deep copy of the
record, NOT the buffer it points to). Used by dispatch_next to create an
ISR-safe copy from the CFIFO value-element. }
function ioreq_copy(src : PIORequest) : PIORequest;
implementation
const
IOREQ_POOL_CAPACITY = 512;
IOREQ_REQ_OFFSET = sizeof(pointer);
type
PIORequestPoolNode = ^TIORequestPoolNode;
TIORequestPoolNode = record
Next : PIORequestPoolNode;
Req : TIORequest;
end;
var
ioreqPoolReady : boolean;
ioreqPoolBuf : pointer;
ioreqFreeList : PIORequestPoolNode;
procedure ioreq_pool_init();
var
i : uint32;
base : uint32;
node : PIORequestPoolNode;
begin
if ioreqPoolReady then exit;
ioreqPoolBuf := kalloc(IOREQ_POOL_CAPACITY * sizeof(TIORequestPoolNode));
if ioreqPoolBuf = nil then exit;
ioreqFreeList := nil;
base := uint32(ioreqPoolBuf);
if IOREQ_POOL_CAPACITY > 0 then
for i := 0 to IOREQ_POOL_CAPACITY - 1 do begin
node := PIORequestPoolNode(base + (i * sizeof(TIORequestPoolNode)));
node^.Next := ioreqFreeList;
ioreqFreeList := node;
end;
ioreqPoolReady := true;
end;
function ioreq_take() : PIORequest;
var
node : PIORequestPoolNode;
begin
if not ioreqPoolReady then
ioreq_pool_init();
if not ioreqPoolReady then begin
ioreq_take := nil;
exit;
end;
asm pushf; cli end;
node := ioreqFreeList;
if node <> nil then
ioreqFreeList := node^.Next;
asm popf end;
if node = nil then
ioreq_take := nil
else
ioreq_take := @node^.Req;
end;
procedure ioreq_release(req : PIORequest);
var
node : PIORequestPoolNode;
begin
if req = nil then exit;
node := PIORequestPoolNode(uint32(req) - IOREQ_REQ_OFFSET);
asm pushf; cli end;
node^.Next := ioreqFreeList;
ioreqFreeList := node;
asm popf end;
end;
function ioreq_alloc(reqType : TIORequestType;
device : PStorage_Device;
lba : uint32;
@@ -53,7 +127,7 @@ function ioreq_alloc(reqType : TIORequestType;
var
req : PIORequest;
begin
req := PIORequest(kalloc(SizeOf(TIORequest)));
req := ioreq_take();
if req = nil then begin
ioreq_alloc := nil;
exit;
@@ -75,15 +149,14 @@ end;
procedure ioreq_free(req : PIORequest);
begin
if req <> nil then
kfree(void(req));
ioreq_release(req);
end;
function ioreq_copy(src : PIORequest) : PIORequest;
var
dst : PIORequest;
begin
dst := PIORequest(kalloc(SizeOf(TIORequest)));
dst := ioreq_take();
if dst = nil then begin
ioreq_copy := nil;
exit;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+26 -9
View File
@@ -134,9 +134,11 @@ type
{ === I/O callback type === }
{ Async I/O completion callback — fired from ISR context when a request finishes.
{ Completion callback used across storage/VFS async APIs.
error = eNone on success; specific code on failure.
userdata is the opaque pointer passed by the submitter. }
userdata is the opaque pointer passed by the submitter.
Context is API-specific: some callers complete from ISR context, others
from task/worker context, and some may invoke the callback immediately. }
TIOCallback = procedure(error : TError; userdata : pointer);
{ Filesystem callback core.types }
@@ -150,16 +152,29 @@ type
PPIdentifyHook = function(volume : PStorage_Volume) : boolean;
PPRenameFileHook = procedure(volume : PStorage_Volume; filePath : pchar; newName : pchar; status : puint32);
{ Offset-based read: reads byteCount bytes starting at byte offset into the file.
Returns the number of bytes actually read. }
PPReadOffsetHook = function(volume : PStorage_Volume; directory : pchar; fileName : pchar; offset : uint32; buffer : puint32; byteCount : uint32) : uint32;
Returns the number of bytes actually read. ctx is the opaque per-file
context returned by openFileCallback (nil when called without a handle). }
PPReadOffsetHook = function(volume : PStorage_Volume; directory : pchar; fileName : pchar; offset : uint32; buffer : puint32; byteCount : uint32; ctx : pointer) : uint32;
{ Offset-based write: writes byteCount bytes starting at byte offset into the file.
Returns the number of bytes actually written.
Filesystems that do not implement this leave the field nil; VFS returns 0
for stream-mode writes on volume FDs. }
PPWriteOffsetHook = function(volume : PStorage_Volume; directory : pchar; fileName : pchar; offset : uint32; buffer : puint32; byteCount : uint32) : uint32;
PPWriteOffsetHook = function(volume : PStorage_Volume; directory : pchar; fileName : pchar; offset : uint32; buffer : puint32; byteCount : uint32; ctx : pointer) : uint32;
{ Async offset-based read/write hooks. Implementations must return immediately
and fire callback when the transfer completes. BytesRead/BytesWritten may be
nil; if provided, implementations store the actual completed byte count. }
PPReadOffsetAsyncHook = procedure(volume : PStorage_Volume; directory : pchar; fileName : pchar; offset : uint32; buffer : puint32; byteCount : uint32; ctx : pointer; bytesRead : puint32; callback : TIOCallback; callbackData : pointer);
PPWriteOffsetAsyncHook = procedure(volume : PStorage_Volume; directory : pchar; fileName : pchar; offset : uint32; buffer : puint32; byteCount : uint32; ctx : pointer; bytesWritten : puint32; callback : TIOCallback; callbackData : pointer);
{ File size query: returns the size in bytes of the named file.
Returns 0 if the file does not exist or has zero length. }
PPFileSizeHook = function(volume : PStorage_Volume; directory : pchar; fileName : pchar) : uint32;
{ Per-file open hook: called by VFS on OpenFile to create FS-level cached
metadata. Returns an opaque pointer stored in the FD and passed as ctx
to read/write hooks. Also returns the current file size through the
var parameter. Returning nil is legal (disables per-call fast-path). }
PPOpenFileHook = function(volume : PStorage_Volume; directory : pchar; fileName : pchar; var fileSize : uint32) : pointer;
{ Per-file close hook: frees the context allocated by openFileCallback. }
PPCloseFileHook = procedure(ctx : pointer);
{ === Async filesystem hook core.types ===
Each mirrors the corresponding sync hook but receives a TIOCallback + callbackData.
@@ -168,8 +183,6 @@ type
PPLinkedListBase = ^PLinkedListBase; { needed for PPReadDirAsyncHook parameter }
PPCreateDirAsyncHook = procedure(volume : PStorage_Volume; directory : pchar; dirname : pchar; attributes : uint32; status : puint32; callback : TIOCallback; callbackData : pointer);
PPReadDirAsyncHook = procedure(volume : PStorage_Volume; directory : pchar; resultList : PPLinkedListBase; status : puint32; callback : TIOCallback; callbackData : pointer);
PPDeleteFileAsyncHook = procedure(volume : PStorage_Volume; filePath : pchar; status : puint32; callback : TIOCallback; callbackData : pointer);
PPDeleteDirAsyncHook = procedure(volume : PStorage_Volume; path : pchar; status : puint32; callback : TIOCallback; callbackData : pointer);
{ === I/O Request core.types === }
@@ -233,15 +246,19 @@ type
readOffsetCallback : PPReadOffsetHook;
{ Offset-based write for streaming mode — nil if not implemented }
writeOffsetCallback : PPWriteOffsetHook;
{ Async offset-based read/write for streaming mode — nil if not implemented }
readOffsetAsyncCallback : PPReadOffsetAsyncHook;
writeOffsetAsyncCallback : PPWriteOffsetAsyncHook;
{ File size query — returns size in bytes without loading the file }
fileSizeCallback : PPFileSizeHook;
{ Async format — nil if FS only supports synchronous create }
createAsyncCallback : PPCreateAsyncHook;
createDirAsyncCallback : PPCreateDirAsyncHook;
readDirAsyncCallback : PPReadDirAsyncHook;
deleteFileAsyncCallback : PPDeleteFileAsyncHook;
deleteDirAsyncCallback : PPDeleteDirAsyncHook;
renameFileCallback : PPRenameFileHook;
{ Per-file open/close — nil if FS does not cache per-file metadata }
openFileCallback : PPOpenFileHook;
closeFileCallback : PPCloseFileHook;
end;
{ Generic storage volume }
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -869,7 +869,8 @@ end;
function readFileAtOffset(volume : PStorage_Volume; directory : pchar;
fileName : pchar; offset : uint32;
buffer : puint32; byteCount : uint32) : uint32;
buffer : puint32; byteCount : uint32;
ctx : pointer) : uint32;
var
fileEntries : PFile_Entry;
fileCount : uint32;
@@ -649,7 +649,8 @@ end;
function readFileAtOffset(volume : PStorage_Volume; directory : pchar;
fileName : pchar; offset : uint32;
buffer : puint32; byteCount : uint32) : uint32;
buffer : puint32; byteCount : uint32;
ctx : pointer) : uint32;
var
buf : puint32;
pvd : PPVD;
@@ -530,8 +530,8 @@ begin
end;
end;
{ Write cached mbr to disk — buffer is the persistent cache }
driver.storage.mgr.storage_write_async(device, 0, 1, puint32(mbr), callback, callbackData);
{ Write cached mbr to disk through the storage manager's staged MBR path. }
driver.storage.mgr.write_mbr_async(device, mbr, callback, callbackData);
end;
procedure remove_partition_async(device : PStorage_Device; slot : uint32;
@@ -563,8 +563,8 @@ begin
if (oldPart.LBA_start <> 0) and (oldPart.sector_count <> 0) then
remove_volume_by_start(device, oldPart.LBA_start);
{ Write cached mbr to disk }
driver.storage.mgr.storage_write_async(device, 0, 1, puint32(mbr), callback, callbackData);
{ Write cached mbr to disk through the storage manager's staged MBR path. }
driver.storage.mgr.write_mbr_async(device, mbr, callback, callbackData);
end;
procedure init_disk_async(device : PStorage_Device;
@@ -594,8 +594,8 @@ begin
PMaster_Boot_Record(cache)^.boot_sector := $AA55;
device^.cachedMBR := pointer(cache);
{ Write to disk }
driver.storage.mgr.storage_write_async(device, 0, 1, cache, callback, callbackData);
{ Write to disk through the storage manager's staged MBR path. }
driver.storage.mgr.write_mbr_async(device, PMaster_Boot_Record(cache), callback, callbackData);
end;
{ ===================== Filesystem operations ===================== }
+1 -1
View File
@@ -19,7 +19,7 @@ const
PROCESS_STACK_SIZE = 8192;
{ Base quantum multiplier: quantum = Priority * BASE_QUANTUM ticks }
BASE_QUANTUM = 5;
BASE_QUANTUM = 1;
type
{ Forward declaration }