mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fill out SaveDataFileSystemServiceImpl.Configuration
This commit is contained in:
parent
433e7bb98e
commit
3bf8826a5b
8 changed files with 86 additions and 14 deletions
|
@ -315,7 +315,7 @@ namespace LibHac.Boot
|
|||
|
||||
int start = IsModern ? 6 : 0;
|
||||
int end = IsModern ? 0x20 : 6;
|
||||
Decryptor decryptor = IsModern ? Crypto.Aes.DecryptCbc128 : (Decryptor)Crypto.Aes.DecryptCtr128;
|
||||
Decryptor decryptor = IsModern ? Crypto.Aes.DecryptCbc128 : Crypto.Aes.DecryptCtr128;
|
||||
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@ using LibHac.FsSrv.FsCreator;
|
|||
using LibHac.FsSrv.Impl;
|
||||
using LibHac.FsSrv.Sf;
|
||||
using LibHac.FsSrv.Storage;
|
||||
using LibHac.FsSystem;
|
||||
using LibHac.Sm;
|
||||
|
||||
namespace LibHac.FsSrv
|
||||
|
@ -14,6 +15,10 @@ namespace LibHac.FsSrv
|
|||
private const ulong SpeedEmulationProgramIdMinimum = 0x100000000000000;
|
||||
private const ulong SpeedEmulationProgramIdMaximum = 0x100000000001FFF;
|
||||
|
||||
private const int BufferManagerHeapSize = 1024 * 1024 * 14;
|
||||
private const int BufferManagerCacheSize = 1024;
|
||||
private const int BufferManagerBlockSize = 0x4000;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="FileSystemServer"/> with the provided <see cref="FileSystemServerConfig"/>.
|
||||
/// </summary>
|
||||
|
@ -57,6 +62,17 @@ namespace LibHac.FsSrv
|
|||
private static FileSystemProxyConfiguration InitializeFileSystemProxy(FileSystemServer server,
|
||||
FileSystemServerConfig config)
|
||||
{
|
||||
var random = new Random();
|
||||
RandomDataGenerator randomGenerator = buffer =>
|
||||
{
|
||||
random.NextBytes(buffer);
|
||||
return Result.Success;
|
||||
};
|
||||
|
||||
var bufferManager = new FileSystemBufferManager();
|
||||
Memory<byte> heapBuffer = GC.AllocateArray<byte>(BufferManagerHeapSize, true);
|
||||
bufferManager.Initialize(BufferManagerCacheSize, heapBuffer, BufferManagerBlockSize);
|
||||
|
||||
var saveDataIndexerManager = new SaveDataIndexerManager(server.Hos.Fs, Fs.SaveData.SaveIndexerId,
|
||||
new ArrayPoolMemoryResource(), new SdHandleManager(), false);
|
||||
|
||||
|
@ -93,7 +109,7 @@ namespace LibHac.FsSrv
|
|||
|
||||
var ncaFsServiceConfig = new NcaFileSystemServiceImpl.Configuration();
|
||||
ncaFsServiceConfig.BaseFsService = baseFsService;
|
||||
ncaFsServiceConfig.HostFsCreator = config.FsCreators.HostFileSystemCreator;
|
||||
ncaFsServiceConfig.LocalFsCreator = config.FsCreators.LocalFileSystemCreator;
|
||||
ncaFsServiceConfig.TargetManagerFsCreator = config.FsCreators.TargetManagerFileSystemCreator;
|
||||
ncaFsServiceConfig.PartitionFsCreator = config.FsCreators.PartitionFileSystemCreator;
|
||||
ncaFsServiceConfig.RomFsCreator = config.FsCreators.RomFileSystemCreator;
|
||||
|
@ -109,12 +125,16 @@ namespace LibHac.FsSrv
|
|||
|
||||
var saveFsServiceConfig = new SaveDataFileSystemServiceImpl.Configuration();
|
||||
saveFsServiceConfig.BaseFsService = baseFsService;
|
||||
saveFsServiceConfig.HostFsCreator = config.FsCreators.HostFileSystemCreator;
|
||||
saveFsServiceConfig.TimeService = timeService;
|
||||
saveFsServiceConfig.LocalFsCreator = config.FsCreators.LocalFileSystemCreator;
|
||||
saveFsServiceConfig.TargetManagerFsCreator = config.FsCreators.TargetManagerFileSystemCreator;
|
||||
saveFsServiceConfig.SaveFsCreator = config.FsCreators.SaveDataFileSystemCreator;
|
||||
saveFsServiceConfig.EncryptedFsCreator = config.FsCreators.EncryptedFileSystemCreator;
|
||||
saveFsServiceConfig.ProgramRegistryService = programRegistryService;
|
||||
saveFsServiceConfig.ShouldCreateDirectorySaveData = () => true;
|
||||
saveFsServiceConfig.BufferManager = bufferManager;
|
||||
saveFsServiceConfig.GenerateRandomData = randomGenerator;
|
||||
saveFsServiceConfig.IsPseudoSaveData = () => true;
|
||||
saveFsServiceConfig.MaxSaveFsCacheCount = 1;
|
||||
saveFsServiceConfig.SaveIndexerManager = saveDataIndexerManager;
|
||||
saveFsServiceConfig.FsServer = server;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
public IPartitionFileSystemCreator PartitionFileSystemCreator { get; set; }
|
||||
public IStorageOnNcaCreator StorageOnNcaCreator { get; set; }
|
||||
public IFatFileSystemCreator FatFileSystemCreator { get; set; }
|
||||
public IHostFileSystemCreator HostFileSystemCreator { get; set; }
|
||||
public ILocalFileSystemCreator LocalFileSystemCreator { get; set; }
|
||||
public ITargetManagerFileSystemCreator TargetManagerFileSystemCreator { get; set; }
|
||||
public ISubDirectoryFileSystemCreator SubDirectoryFileSystemCreator { get; set; }
|
||||
public IBuiltInStorageCreator BuiltInStorageCreator { get; set; }
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace LibHac.FsSrv.FsCreator
|
||||
{
|
||||
public interface IHostFileSystemCreator
|
||||
public interface ILocalFileSystemCreator
|
||||
{
|
||||
Result Create(out IFileSystem fileSystem, bool someBool);
|
||||
Result Create(out IFileSystem fileSystem, string path, bool openCaseSensitive);
|
|
@ -42,7 +42,7 @@ namespace LibHac.FsSrv
|
|||
public struct Configuration
|
||||
{
|
||||
public BaseFileSystemServiceImpl BaseFsService;
|
||||
public IHostFileSystemCreator HostFsCreator;
|
||||
public ILocalFileSystemCreator LocalFsCreator;
|
||||
public ITargetManagerFileSystemCreator TargetManagerFsCreator;
|
||||
public IPartitionFileSystemCreator PartitionFsCreator;
|
||||
public IRomFileSystemCreator RomFsCreator;
|
||||
|
|
|
@ -336,6 +336,7 @@ namespace LibHac.FsSrv
|
|||
return rc;
|
||||
}
|
||||
|
||||
// Allow access when opening a directory save FS on a dev console
|
||||
if (extraData.OwnerId == 0 && extraData.DataSize == 0 && extraData.JournalSize == 0 &&
|
||||
programInfo.AccessControl.CanCall(OperationType.DebugSaveData))
|
||||
{
|
||||
|
|
|
@ -34,17 +34,17 @@ namespace LibHac.FsSrv
|
|||
public struct Configuration
|
||||
{
|
||||
public BaseFileSystemServiceImpl BaseFsService;
|
||||
// Time service
|
||||
public IHostFileSystemCreator HostFsCreator;
|
||||
public TimeServiceImpl TimeService;
|
||||
public ILocalFileSystemCreator LocalFsCreator;
|
||||
public ITargetManagerFileSystemCreator TargetManagerFsCreator;
|
||||
public ISaveDataFileSystemCreator SaveFsCreator;
|
||||
public IEncryptedFileSystemCreator EncryptedFsCreator;
|
||||
public ProgramRegistryServiceImpl ProgramRegistryService;
|
||||
// Buffer manager
|
||||
public IBufferManager BufferManager;
|
||||
public RandomDataGenerator GenerateRandomData;
|
||||
public SaveDataTransferCryptoConfiguration SaveTransferCryptoConfig;
|
||||
// Max save FS cache size
|
||||
public Func<bool> ShouldCreateDirectorySaveData;
|
||||
public int MaxSaveFsCacheCount;
|
||||
public Func<bool> IsPseudoSaveData;
|
||||
public ISaveDataIndexerManager SaveIndexerManager;
|
||||
|
||||
// LibHac additions
|
||||
|
@ -316,7 +316,7 @@ namespace LibHac.FsSrv
|
|||
var sb = new U8StringBuilder(saveDataPathBuffer);
|
||||
sb.Append((byte)'/').AppendFormat(saveDataId, 'x', 16);
|
||||
|
||||
if (_config.ShouldCreateDirectorySaveData())
|
||||
if (_config.IsPseudoSaveData())
|
||||
{
|
||||
return Utility.EnsureDirectory(fileSystem.Target, new U8Span(saveDataPathBuffer));
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ namespace LibHac.FsSystem
|
|||
public void DecrementCacheCount() => _cacheCount--;
|
||||
public int GetCacheSize() => _cacheSize;
|
||||
public void AddCacheSize(int diff) => _cacheSize += diff;
|
||||
|
||||
public void SubtractCacheSize(int diff)
|
||||
{
|
||||
Assert.SdkRequiresGreaterEqual(_cacheSize, diff);
|
||||
|
@ -350,6 +351,36 @@ namespace LibHac.FsSystem
|
|||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
public Result Initialize(int maxCacheCount, Memory<byte> heapBuffer, int blockSize)
|
||||
{
|
||||
Result rc = CacheTable.Initialize(maxCacheCount);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = BuddyHeap.Initialize(heapBuffer, blockSize);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
TotalSize = (int)BuddyHeap.GetTotalFreeSize();
|
||||
PeakFreeSize = TotalSize;
|
||||
PeakTotalAllocatableSize = TotalSize;
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result Initialize(int maxCacheCount, Memory<byte> heapBuffer, int blockSize, int maxOrder)
|
||||
{
|
||||
Result rc = CacheTable.Initialize(maxCacheCount);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = BuddyHeap.Initialize(heapBuffer, blockSize, maxOrder);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
TotalSize = (int)BuddyHeap.GetTotalFreeSize();
|
||||
PeakFreeSize = TotalSize;
|
||||
PeakTotalAllocatableSize = TotalSize;
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result Initialize(int maxCacheCount, Memory<byte> heapBuffer, int blockSize, Memory<byte> workBuffer)
|
||||
{
|
||||
// Note: We can't use an external buffer for the cache handle table since it contains managed pointers,
|
||||
|
@ -368,6 +399,25 @@ namespace LibHac.FsSystem
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result Initialize(int maxCacheCount, Memory<byte> heapBuffer, int blockSize, int maxOrder,
|
||||
Memory<byte> workBuffer)
|
||||
{
|
||||
// Note: We can't use an external buffer for the cache handle table since it contains managed pointers,
|
||||
// so pass the work buffer directly to the buddy heap.
|
||||
|
||||
Result rc = CacheTable.Initialize(maxCacheCount);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = BuddyHeap.Initialize(heapBuffer, blockSize, maxOrder, workBuffer);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
TotalSize = (int)BuddyHeap.GetTotalFreeSize();
|
||||
PeakFreeSize = TotalSize;
|
||||
PeakTotalAllocatableSize = TotalSize;
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Buffer DoAllocateBuffer(int size, BufferAttribute attribute)
|
||||
{
|
||||
lock (Locker)
|
||||
|
@ -393,6 +443,7 @@ namespace LibHac.FsSystem
|
|||
// No cached buffers left to deallocate.
|
||||
return Buffer.Empty;
|
||||
}
|
||||
|
||||
DeallocateBufferImpl(deallocateBuffer);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue