mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Add OpenFile and CloseFile methods to IReadOnlyFilesystem.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user