Started aadding file handle stuff to volume manager

This commit is contained in:
Aaron Hance 2022-09-28 16:04:51 +01:00
parent e490b95f1d
commit fcaafa0d12

View File

@ -63,6 +63,7 @@ type
end; end;
TStorage_Volume = record TStorage_Volume = record
volumeHandle : uint32;
device : PStorage_device; device : PStorage_device;
sectorStart : uint32; sectorStart : uint32;
sectorSize : uint32; sectorSize : uint32;
@ -82,11 +83,28 @@ type
// modifiedT : TDateTime; // modifiedT : TDateTime;
end; end;
TFilehandleEntry = record
volume : PStorage_Volume;
fileName : pchar;
fileHandle : uint32;
openMode : TOpenMode;
writeMode : TWriteMode;
lock : Boolean;
closed : Boolean;
end;
PFilehandleEntry = ^TFilehandleEntry;
var var
storageVolumes : PLinkedListBase; storageVolumes : PLinkedListBase;
filesystems : PlinkedListBase; filesystems : PlinkedListBase;
fileHandles : PLinkedListBase;
{ Returns the number of volumes }
procedure init(); procedure init();
procedure register_filesystem(filesystem : PFilesystem); procedure register_filesystem(filesystem : PFilesystem);
@ -224,6 +242,9 @@ begin
{ setup lists } { setup lists }
storageVolumes:= ll_New(sizeof(TFilesystem)); storageVolumes:= ll_New(sizeof(TFilesystem));
filesystems:= ll_New(sizeof(TFilesystem)); filesystems:= ll_New(sizeof(TFilesystem));
fileHandles:= ll_New(sizeof(TFilehandleEntry));
{ register commands }
terminal.registerCommand('volume', @volume_command, 'Volume utility'); terminal.registerCommand('volume', @volume_command, 'Volume utility');
end; end;
@ -368,4 +389,43 @@ begin
// if rootVolume = PStorage_Volume(0) then rootVolume:= volume; // if rootVolume = PStorage_Volume(0) then rootVolume:= volume;
end; end;
procedure openFile(Handle : uint32; Filename : PChar; OpenMode : TOpenMode; WriteMode : TWriteMode; lock : boolean; Error : PError);
var
fileHandleEntree : PFilehandleEntry;
fileHandle : uInt32;
i : uint32;
elm : void;
begin
push_trace('VolumeManager.openFile');
//check if file is already open and if it is locked, if openmode is not read only
if OpenMode <> omReadOnly then begin
for i:=0 to LL_Size(fileHandles) - 1 do begin
elm := LL_Get(fileHandles, i);
if stringEquals(PFilehandleEntry(elm)^.filename, Filename) then begin
if PFilehandleEntry(elm)^.locked and (not PFilehandleEntry(elm)^.closed) then begin
Error^ := eFileInUse;
exit;
end;
end;
end;
end;
//create filehandleentry
fileHandleEntree := PFilehandleEntry(kalloc(SizeOf(TFilehandleEntry)));
fileHandleEntree.fileName := Filename;
fileHandleEntree^.openMode := OpenMode;
fileHandleEntree^.writeMode := WriteMode;
fileHandleEntree^.lock := lock;
fileHandleEntree^.closed := false;
//create filehandle
fileHandle := LL_Size(fileHandles);
end;
end;
end. end.