mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add FatFileSystemCreator
This commit is contained in:
parent
6c9e6e5203
commit
28a4deb93c
6 changed files with 137 additions and 6 deletions
31
src/LibHac/Common/FixedArrays/Array68.cs
Normal file
31
src/LibHac/Common/FixedArrays/Array68.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace LibHac.Common.FixedArrays;
|
||||
|
||||
public struct Array68<T>
|
||||
{
|
||||
public const int Length = 68;
|
||||
|
||||
private Array64<T> _0;
|
||||
private Array4<T> _64;
|
||||
|
||||
public ref T this[int i] => ref Items[i];
|
||||
|
||||
public Span<T> Items
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
|
||||
}
|
||||
|
||||
public readonly ReadOnlySpan<T> ItemsRo
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.ItemsRo), Length);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator ReadOnlySpan<T>(in Array68<T> value) => value.ItemsRo;
|
||||
}
|
15
src/LibHac/Fat/FatReport.cs
Normal file
15
src/LibHac/Fat/FatReport.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace LibHac.Fat;
|
||||
|
||||
public struct FatReport
|
||||
{
|
||||
public ushort FileCurrentOpenCount;
|
||||
public ushort FilePeakOpenCount;
|
||||
public ushort DirectoryCurrentOpenCount;
|
||||
public ushort DirectoryPeakOpenCount;
|
||||
}
|
||||
|
||||
public struct FatReportInfo
|
||||
{
|
||||
public ushort FilePeakOpenCount;
|
||||
public ushort DirectoryPeakOpenCount;
|
||||
}
|
|
@ -10,7 +10,10 @@ public struct FileSystemProxyErrorInfo
|
|||
public FatError FatFsError;
|
||||
public int RecoveredByInvalidateCacheCount;
|
||||
public int SaveDataIndexCount;
|
||||
public Array80<byte> Reserved;
|
||||
public FatReportInfo BisSystemFatReportInfo;
|
||||
public FatReportInfo BisUserFatReport;
|
||||
public FatReportInfo SdCardFatReport;
|
||||
public Array68<byte> Reserved;
|
||||
}
|
||||
|
||||
public struct StorageErrorInfo
|
||||
|
|
73
src/LibHac/FsSrv/FsCreator/FatFileSystemCreator.cs
Normal file
73
src/LibHac/FsSrv/FsCreator/FatFileSystemCreator.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fat;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.Os;
|
||||
|
||||
namespace LibHac.FsSrv.FsCreator;
|
||||
|
||||
/// <summary>
|
||||
/// Handles creating FAT file systems.
|
||||
/// </summary>
|
||||
/// <remarks>Based on FS 14.1.0 (nnSdk 14.3.0)</remarks>
|
||||
public class FatFileSystemCreator : IFatFileSystemCreator
|
||||
{
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private MemoryResource _allocator;
|
||||
private FatError _fatFsError;
|
||||
private SdkMutexType _fatErrorMutex;
|
||||
private FatReport _bisSystemReport;
|
||||
private FatReport _bisUserReport;
|
||||
private FatReport _sdCardReport;
|
||||
private SdkMutexType _fatReportMutex;
|
||||
|
||||
public FatFileSystemCreator(MemoryResource allocator)
|
||||
{
|
||||
_fatErrorMutex = new SdkMutexType();
|
||||
_fatReportMutex = new SdkMutexType();
|
||||
_allocator = allocator;
|
||||
|
||||
// Missing: Call nn::fat::SetMemoryResource
|
||||
}
|
||||
|
||||
public Result Create(ref SharedRef<IFileSystem> outFileSystem, ref SharedRef<IStorage> baseStorage,
|
||||
FatAttribute attribute, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result Format(ref SharedRef<IStorage> partitionStorage, FatAttribute attribute, FatFormatParam formatParam,
|
||||
int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void GetAndClearFatFsError(out FatError outFatError)
|
||||
{
|
||||
using var scopedLock = new ScopedLock<SdkMutexType>(ref _fatErrorMutex);
|
||||
|
||||
outFatError = _fatFsError;
|
||||
_fatFsError = default;
|
||||
}
|
||||
|
||||
public void GetAndClearFatReportInfo(out FatReportInfo outBisSystemFatReportInfo,
|
||||
out FatReportInfo outBisUserFatReportInfo, out FatReportInfo outSdCardFatReportInfo)
|
||||
{
|
||||
using var scopedLock = new ScopedLock<SdkMutexType>(ref _fatReportMutex);
|
||||
|
||||
outBisSystemFatReportInfo.FilePeakOpenCount = _bisSystemReport.FilePeakOpenCount;
|
||||
outBisSystemFatReportInfo.DirectoryPeakOpenCount = _bisSystemReport.DirectoryPeakOpenCount;
|
||||
outBisUserFatReportInfo.FilePeakOpenCount = _bisUserReport.FilePeakOpenCount;
|
||||
outBisUserFatReportInfo.DirectoryPeakOpenCount = _bisUserReport.DirectoryPeakOpenCount;
|
||||
outSdCardFatReportInfo.FilePeakOpenCount = _sdCardReport.FilePeakOpenCount;
|
||||
outSdCardFatReportInfo.DirectoryPeakOpenCount = _sdCardReport.DirectoryPeakOpenCount;
|
||||
|
||||
_bisSystemReport.FilePeakOpenCount = _bisSystemReport.FileCurrentOpenCount;
|
||||
_bisSystemReport.DirectoryPeakOpenCount = _bisSystemReport.DirectoryCurrentOpenCount;
|
||||
_bisUserReport.FilePeakOpenCount = _bisUserReport.FileCurrentOpenCount;
|
||||
_bisUserReport.DirectoryPeakOpenCount = _bisUserReport.DirectoryCurrentOpenCount;
|
||||
_sdCardReport.FilePeakOpenCount = _sdCardReport.FileCurrentOpenCount;
|
||||
_sdCardReport.DirectoryPeakOpenCount = _sdCardReport.DirectoryCurrentOpenCount;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using LibHac.Diag;
|
||||
using LibHac.Fs;
|
||||
using LibHac.FsSrv.FsCreator;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.Os;
|
||||
|
||||
|
@ -10,7 +11,7 @@ namespace LibHac.FsSrv;
|
|||
/// </summary>
|
||||
/// <remarks><para>This struct handles forwarding calls to the <see cref="StatusReportServiceImpl"/> object.
|
||||
/// No permissions are needed to call any of this struct's functions.</para>
|
||||
/// <para>Based on FS 13.1.0 (nnSdk 13.4.0)</para></remarks>
|
||||
/// <para>Based on FS 14.1.0 (nnSdk 14.3.0)</para></remarks>
|
||||
public readonly struct StatusReportService
|
||||
{
|
||||
private readonly StatusReportServiceImpl _serviceImpl;
|
||||
|
@ -40,7 +41,7 @@ public readonly struct StatusReportService
|
|||
/// <summary>
|
||||
/// Manages getting and resetting various status reports and statistics about parts of the FS service.
|
||||
/// </summary>
|
||||
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
|
||||
/// <remarks>Based on FS 14.1.0 (nnSdk 14.3.0)</remarks>
|
||||
public class StatusReportServiceImpl
|
||||
{
|
||||
private Configuration _config;
|
||||
|
@ -56,7 +57,7 @@ public class StatusReportServiceImpl
|
|||
{
|
||||
public NcaFileSystemServiceImpl NcaFileSystemServiceImpl;
|
||||
public SaveDataFileSystemServiceImpl SaveDataFileSystemServiceImpl;
|
||||
// Missing: FatFileSystemCreator (Not an IFatFileSystemCreator)
|
||||
public FatFileSystemCreator FatFileSystemCreator;
|
||||
public MemoryReport BufferManagerMemoryReport;
|
||||
public MemoryReport ExpHeapMemoryReport;
|
||||
public MemoryReport BufferPoolMemoryReport;
|
||||
|
@ -79,7 +80,12 @@ public class StatusReportServiceImpl
|
|||
out errorInfo.UnrecoverableDataCorruptionByRemountCount,
|
||||
out errorInfo.RecoveredByInvalidateCacheCount);
|
||||
|
||||
// Missing: GetFatInfo
|
||||
if (_config.FatFileSystemCreator is not null)
|
||||
{
|
||||
_config.FatFileSystemCreator.GetAndClearFatFsError(out errorInfo.FatFsError);
|
||||
_config.FatFileSystemCreator.GetAndClearFatReportInfo(out errorInfo.BisSystemFatReportInfo,
|
||||
out errorInfo.BisUserFatReport, out errorInfo.SdCardFatReport);
|
||||
}
|
||||
|
||||
Assert.SdkRequiresNotNull(_config.SaveDataFileSystemServiceImpl);
|
||||
|
||||
|
|
|
@ -213,7 +213,10 @@ public class TypeLayoutTests
|
|||
Assert.Equal(0x08, GetOffset(in s, in s.FatFsError));
|
||||
Assert.Equal(0x28, GetOffset(in s, in s.RecoveredByInvalidateCacheCount));
|
||||
Assert.Equal(0x2C, GetOffset(in s, in s.SaveDataIndexCount));
|
||||
Assert.Equal(0x30, GetOffset(in s, in s.Reserved));
|
||||
Assert.Equal(0x30, GetOffset(in s, in s.BisSystemFatReportInfo));
|
||||
Assert.Equal(0x34, GetOffset(in s, in s.BisUserFatReport));
|
||||
Assert.Equal(0x38, GetOffset(in s, in s.SdCardFatReport));
|
||||
Assert.Equal(0x3C, GetOffset(in s, in s.Reserved));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
Loading…
Reference in a new issue