this one seems to be doing all it should.
Any chance this might end up in the standard lib ? overhead is pretty small (just an array with pointers to the opened files).
class ExtSPIFlashFileSystem extends SPIFlashFileSystem
{
_openFileHandles = null;
constructor(start = null, end = null, flash = null)
{
_openFileHandles = {};
base.constructor(start, end , flash );
}
function open(fname, mode)
{
if (!(fname in _openFileHandles))
{
local handle = base.open(fname,mode);
_openFileHandles[fname] <- handle;
}
return _openFileHandles[fname];
}
function getFileHandle(fname)
{
if (fname in _openFileHandles)
return _openFileHandles[fname];
return null;
}
function _close(fileId, fileIdx, dirty)
{
base._close(fileId, fileIdx, dirty);
foreach(file in getFileList())
{
if (file.id == fileId)
{
delete _openFileHandles[file.fname];
}
}
}
}