Here it is:
Code:
{$O-}
function TVirtualFileSystem.FindFile(aname: string; var afilerecord: TFileRecord): int64;
var
FileRecordEntry: TFileRecord;
buffer: pointer;
i,m,size: integer;
foundpos: integer;
OrigFilePos: int64;
begin
result :=0;
FileRecordEntry.filename := 'Not Found';
FileRecordEntry.filesize := 0;
FileRecordEntry.startblock := 0;
afilerecord :=FileRecordEntry;
foundpos:=0;
if aname = '/' then
begin
//read first dir entry
//TODO: can this be simplified by assuming a fixed /
self.ReadBlock(1,FileRecordEntry,0,SizeOf(TFileRecord));
//compare ( is the first entry realy an / )
if FileRecordEntry.filename = aname then
begin
result := foundpos * SizeOf(TFileRecord);
afilerecord := FileRecordEntry;
end;
end
else
begin
//browse through FileRecord(s) in virtual file stream
OrigFilePos:=FDir.FPosition;
FDir.FPosition :=0;
i:=0;
m:= (FDir.Size div SizeOf(TFileRecord));
while i<=m-1 do
begin
FDir.Read(FileRecordEntry, SizeOf(TFileRecord) );
//compare
if FileRecordEntry.filename = aname then
begin
result := FDir.FPosition-SizeOf(TFileRecord) ;
afilerecord := FileRecordEntry;
FDir.FPosition :=OrigFilePos;
break;
end;
i:=i+1;
end;
FDir.FPosition :=OrigFilePos;
end;
end;
{$O+}
and calling:
Code:
{$O-}
constructor TvfsFileStream.Create(aname: string; aVFSFileSystem: TObject);
var
FileRecordPos: int64;
begin
FileRecordPos := 0;
inherited Create();
FBlockList:=nil;
//determine if aVFSFileSystem is a TVirtualFileSystem
if aVFSFileSystem <nil> 0 then
begin
//TODO: overwrite current file (e.g. delete it dependend on fmode)
FSize:=FFileRecord.filesize;
FFirstBlock := FFileRecord.startblock;
end
else
begin
//new file
FFirstBlock := TVirtualFileSystem(self.FDataFileP).NextFreeBlock();
TVirtualFileSystem(self.FDataFileP).AddFile(aname,FFirstBlock , 0);
FSize:=0;
end;
FPosition:=0; //go to start of virtual file
//determine what blocks are used by virtual file (if any)
FBlockList:=TVirtualFileSystem(self.FDataFileP).GetBlockList(FFileRecord);
//some more for making a new virtual file
if FFilerecord.filename = 'Not Found' then
begin
FFileRecord.filename := aname;
FFileRecord.startblock :=TVirtualFileSystem(self.FDataFileP).NextFreeBlock();
end;
FPosition:=0; //go back to start of virtual file
end
else
Raise Exception.Create('aVFSFileSystem must be a TVirtualFileSystem');
end;
{$O+}
Now with {$O-} the lines do execute.
But as it turned out the cause of the program malfunctioning was due to another here unrelated part. I even wrote a comment there that i might not work ops: .
Now i think i can also remove the {$O-} again as the optimizer is clever enough not to break things only the breakpoints go slightly wrong.
Bookmarks