Add OpenFile and CloseFile methods to IReadOnlyFilesystem.

This commit is contained in:
2022-12-19 00:26:55 +00:00
parent 4fb11eec25
commit 7e0dc0a251
19 changed files with 584 additions and 6 deletions

View File

@@ -28,6 +28,7 @@
using System;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.CommonTypes.Structs;
using Aaru.Helpers;
@@ -77,6 +78,50 @@ public sealed partial class CPM
return !_mounted ? ErrorNumber.AccessDenied : ErrorNumber.NotImplemented;
}
/// <inheritdoc />
public ErrorNumber OpenFile(string path, out IFileNode node)
{
node = null;
if(!_mounted)
return ErrorNumber.AccessDenied;
string[] pathElements = path.Split(new[]
{
'/'
}, StringSplitOptions.RemoveEmptyEntries);
if(pathElements.Length != 1)
return ErrorNumber.NotSupported;
if(!_fileCache.TryGetValue(pathElements[0].ToUpperInvariant(), out byte[] file))
return ErrorNumber.NoSuchFile;
node = new CpmFileNode
{
Path = path,
Length = file.Length,
Offset = 0,
_cache = file
};
return ErrorNumber.NoError;
}
/// <inheritdoc />
public ErrorNumber CloseFile(IFileNode node)
{
if(!_mounted)
return ErrorNumber.AccessDenied;
if(node is not CpmFileNode mynode)
return ErrorNumber.InvalidArgument;
mynode._cache = null;
return ErrorNumber.NoError;
}
/// <inheritdoc />
public ErrorNumber Read(string path, long offset, long size, ref byte[] buf)
{