Update to LibHac v0.14.3 (#2925)

* Update to LibHac v0.14.3

* Fix loading NCAs that don't have a data partition
This commit is contained in:
Alex Barney 2021-12-23 09:55:50 -07:00 committed by GitHub
parent cb43cc7e32
commit aa932a6df1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 554 additions and 406 deletions

View file

@ -23,11 +23,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
try
{
LocalStorage storage = new LocalStorage(pfsPath, FileAccess.Read, FileMode.Open);
ReferenceCountedDisposable<LibHac.Fs.Fsa.IFileSystem> nsp = new(new PartitionFileSystem(storage));
using SharedRef<LibHac.Fs.Fsa.IFileSystem> nsp = new(new PartitionFileSystem(storage));
ImportTitleKeysFromNsp(nsp.Target, context.Device.System.KeySet);
ImportTitleKeysFromNsp(nsp.Get, context.Device.System.KeySet);
openedFileSystem = new IFileSystem(FileSystemInterfaceAdapter.CreateShared(ref nsp));
using SharedRef<LibHac.FsSrv.Sf.IFileSystem> adapter = FileSystemInterfaceAdapter.CreateShared(ref nsp.Ref(), true);
openedFileSystem = new IFileSystem(ref adapter.Ref());
}
catch (HorizonResultException ex)
{
@ -51,9 +53,11 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
}
LibHac.Fs.Fsa.IFileSystem fileSystem = nca.OpenFileSystem(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel);
var sharedFs = new ReferenceCountedDisposable<LibHac.Fs.Fsa.IFileSystem>(fileSystem);
using var sharedFs = new SharedRef<LibHac.Fs.Fsa.IFileSystem>(fileSystem);
openedFileSystem = new IFileSystem(FileSystemInterfaceAdapter.CreateShared(ref sharedFs));
using SharedRef<LibHac.FsSrv.Sf.IFileSystem> adapter = FileSystemInterfaceAdapter.CreateShared(ref sharedFs.Ref(), true);
openedFileSystem = new IFileSystem(ref adapter.Ref());
}
catch (HorizonResultException ex)
{
@ -89,13 +93,15 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\');
Result result = nsp.OpenFile(out LibHac.Fs.Fsa.IFile ncaFile, filename.ToU8Span(), OpenMode.Read);
using var ncaFile = new UniqueRef<LibHac.Fs.Fsa.IFile>();
Result result = nsp.OpenFile(ref ncaFile.Ref(), filename.ToU8Span(), OpenMode.Read);
if (result.IsFailure())
{
return (ResultCode)result.Value;
}
return OpenNcaFs(context, fullPath, ncaFile.AsStorage(), out openedFileSystem);
return OpenNcaFs(context, fullPath, ncaFile.Release().AsStorage(), out openedFileSystem);
}
catch (HorizonResultException ex)
{
@ -110,11 +116,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
foreach (DirectoryEntryEx ticketEntry in nsp.EnumerateEntries("/", "*.tik"))
{
Result result = nsp.OpenFile(out LibHac.Fs.Fsa.IFile ticketFile, ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
using var ticketFile = new UniqueRef<LibHac.Fs.Fsa.IFile>();
Result result = nsp.OpenFile(ref ticketFile.Ref(), ticketEntry.FullPath.ToU8Span(), OpenMode.Read);
if (result.IsSuccess())
{
Ticket ticket = new Ticket(ticketFile.AsStream());
Ticket ticket = new Ticket(ticketFile.Get.AsStream());
keySet.ExternalKeySet.Add(new RightsId(ticket.RightsId), new AccessKey(ticket.GetTitleKey(keySet)));
}

View file

@ -1,15 +1,16 @@
using LibHac;
using LibHac.Common;
using LibHac.Sf;
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
class IDirectory : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDirectory> _baseDirectory;
private SharedRef<LibHac.FsSrv.Sf.IDirectory> _baseDirectory;
public IDirectory(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDirectory> directory)
public IDirectory(ref SharedRef<LibHac.FsSrv.Sf.IDirectory> directory)
{
_baseDirectory = directory;
_baseDirectory = SharedRef<LibHac.FsSrv.Sf.IDirectory>.CreateMove(ref directory);
}
[CommandHipc(0)]
@ -21,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
byte[] entryBuffer = new byte[bufferLen];
Result result = _baseDirectory.Target.Read(out long entriesRead, new OutBuffer(entryBuffer));
Result result = _baseDirectory.Get.Read(out long entriesRead, new OutBuffer(entryBuffer));
context.Memory.Write(bufferPosition, entryBuffer);
context.ResponseData.Write(entriesRead);
@ -33,7 +34,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
// GetEntryCount() -> u64
public ResultCode GetEntryCount(ServiceCtx context)
{
Result result = _baseDirectory.Target.GetEntryCount(out long entryCount);
Result result = _baseDirectory.Get.GetEntryCount(out long entryCount);
context.ResponseData.Write(entryCount);
@ -44,7 +45,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
if (isDisposing)
{
_baseDirectory?.Dispose();
_baseDirectory.Destroy();
}
}
}

View file

@ -1,4 +1,5 @@
using LibHac;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Sf;
using Ryujinx.Common;
@ -7,11 +8,11 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
class IFile : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFile> _baseFile;
private SharedRef<LibHac.FsSrv.Sf.IFile> _baseFile;
public IFile(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFile> baseFile)
public IFile(ref SharedRef<LibHac.FsSrv.Sf.IFile> baseFile)
{
_baseFile = baseFile;
_baseFile = SharedRef<LibHac.FsSrv.Sf.IFile>.CreateMove(ref baseFile);
}
[CommandHipc(0)]
@ -28,7 +29,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
byte[] data = new byte[context.Request.ReceiveBuff[0].Size];
Result result = _baseFile.Target.Read(out long bytesRead, offset, new OutBuffer(data), size, readOption);
Result result = _baseFile.Get.Read(out long bytesRead, offset, new OutBuffer(data), size, readOption);
context.Memory.Write(position, data);
@ -53,14 +54,14 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
context.Memory.Read(position, data);
return (ResultCode)_baseFile.Target.Write(offset, new InBuffer(data), size, writeOption).Value;
return (ResultCode)_baseFile.Get.Write(offset, new InBuffer(data), size, writeOption).Value;
}
[CommandHipc(2)]
// Flush()
public ResultCode Flush(ServiceCtx context)
{
return (ResultCode)_baseFile.Target.Flush().Value;
return (ResultCode)_baseFile.Get.Flush().Value;
}
[CommandHipc(3)]
@ -69,14 +70,14 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
long size = context.RequestData.ReadInt64();
return (ResultCode)_baseFile.Target.SetSize(size).Value;
return (ResultCode)_baseFile.Get.SetSize(size).Value;
}
[CommandHipc(4)]
// GetSize() -> u64 fileSize
public ResultCode GetSize(ServiceCtx context)
{
Result result = _baseFile.Target.GetSize(out long size);
Result result = _baseFile.Get.GetSize(out long size);
context.ResponseData.Write(size);
@ -87,7 +88,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
if (isDisposing)
{
_baseFile?.Dispose();
_baseFile.Destroy();
}
}
}

View file

@ -1,21 +1,22 @@
using LibHac;
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSrv.Sf;
using Path = LibHac.FsSrv.Sf.Path;
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
class IFileSystem : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> _fileSystem;
private SharedRef<LibHac.FsSrv.Sf.IFileSystem> _fileSystem;
public IFileSystem(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> provider)
public IFileSystem(ref SharedRef<LibHac.FsSrv.Sf.IFileSystem> provider)
{
_fileSystem = provider;
_fileSystem = SharedRef<LibHac.FsSrv.Sf.IFileSystem>.CreateMove(ref provider);
}
public ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> GetBaseFileSystem()
public SharedRef<LibHac.FsSrv.Sf.IFileSystem> GetBaseFileSystem()
{
return _fileSystem;
return SharedRef<LibHac.FsSrv.Sf.IFileSystem>.CreateCopy(in _fileSystem);
}
[CommandHipc(0)]
@ -29,7 +30,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
long size = context.RequestData.ReadInt64();
return (ResultCode)_fileSystem.Target.CreateFile(in name, size, createOption).Value;
return (ResultCode)_fileSystem.Get.CreateFile(in name, size, createOption).Value;
}
[CommandHipc(1)]
@ -38,7 +39,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.DeleteFile(in name).Value;
return (ResultCode)_fileSystem.Get.DeleteFile(in name).Value;
}
[CommandHipc(2)]
@ -47,7 +48,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.CreateDirectory(in name).Value;
return (ResultCode)_fileSystem.Get.CreateDirectory(in name).Value;
}
[CommandHipc(3)]
@ -56,7 +57,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.DeleteDirectory(in name).Value;
return (ResultCode)_fileSystem.Get.DeleteDirectory(in name).Value;
}
[CommandHipc(4)]
@ -65,7 +66,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.DeleteDirectoryRecursively(in name).Value;
return (ResultCode)_fileSystem.Get.DeleteDirectoryRecursively(in name).Value;
}
[CommandHipc(5)]
@ -75,7 +76,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
ref readonly Path currentName = ref FileSystemProxyHelper.GetSfPath(context, index: 0);
ref readonly Path newName = ref FileSystemProxyHelper.GetSfPath(context, index: 1);
return (ResultCode)_fileSystem.Target.RenameFile(in currentName, in newName).Value;
return (ResultCode)_fileSystem.Get.RenameFile(in currentName, in newName).Value;
}
[CommandHipc(6)]
@ -85,7 +86,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
ref readonly Path currentName = ref FileSystemProxyHelper.GetSfPath(context, index: 0);
ref readonly Path newName = ref FileSystemProxyHelper.GetSfPath(context, index: 1);
return (ResultCode)_fileSystem.Target.RenameDirectory(in currentName, in newName).Value;
return (ResultCode)_fileSystem.Get.RenameDirectory(in currentName, in newName).Value;
}
[CommandHipc(7)]
@ -94,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
Result result = _fileSystem.Target.GetEntryType(out uint entryType, in name);
Result result = _fileSystem.Get.GetEntryType(out uint entryType, in name);
context.ResponseData.Write((int)entryType);
@ -108,12 +109,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
uint mode = context.RequestData.ReadUInt32();
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
using var file = new SharedRef<LibHac.FsSrv.Sf.IFile>();
Result result = _fileSystem.Target.OpenFile(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFile> file, in name, mode);
Result result = _fileSystem.Get.OpenFile(ref file.Ref(), in name, mode);
if (result.IsSuccess())
{
IFile fileInterface = new IFile(file);
IFile fileInterface = new IFile(ref file.Ref());
MakeObject(context, fileInterface);
}
@ -128,12 +130,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
uint mode = context.RequestData.ReadUInt32();
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
using var dir = new SharedRef<LibHac.FsSrv.Sf.IDirectory>();
Result result = _fileSystem.Target.OpenDirectory(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDirectory> dir, name, mode);
Result result = _fileSystem.Get.OpenDirectory(ref dir.Ref(), name, mode);
if (result.IsSuccess())
{
IDirectory dirInterface = new IDirectory(dir);
IDirectory dirInterface = new IDirectory(ref dir.Ref());
MakeObject(context, dirInterface);
}
@ -145,7 +148,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
// Commit()
public ResultCode Commit(ServiceCtx context)
{
return (ResultCode)_fileSystem.Target.Commit().Value;
return (ResultCode)_fileSystem.Get.Commit().Value;
}
[CommandHipc(11)]
@ -154,7 +157,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
Result result = _fileSystem.Target.GetFreeSpaceSize(out long size, in name);
Result result = _fileSystem.Get.GetFreeSpaceSize(out long size, in name);
context.ResponseData.Write(size);
@ -167,7 +170,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
Result result = _fileSystem.Target.GetTotalSpaceSize(out long size, in name);
Result result = _fileSystem.Get.GetTotalSpaceSize(out long size, in name);
context.ResponseData.Write(size);
@ -180,7 +183,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
return (ResultCode)_fileSystem.Target.CleanDirectoryRecursively(in name).Value;
return (ResultCode)_fileSystem.Get.CleanDirectoryRecursively(in name).Value;
}
[CommandHipc(14)]
@ -189,7 +192,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
Result result = _fileSystem.Target.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, in name);
Result result = _fileSystem.Get.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, in name);
context.ResponseData.Write(timestamp.Created);
context.ResponseData.Write(timestamp.Modified);
@ -209,7 +212,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
if (isDisposing)
{
_fileSystem?.Dispose();
_fileSystem.Destroy();
}
}
}

View file

@ -1,4 +1,5 @@
using LibHac;
using LibHac.Common;
using LibHac.Sf;
using Ryujinx.HLE.HOS.Ipc;
@ -6,11 +7,11 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
class IStorage : DisposableIpcService
{
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IStorage> _baseStorage;
private SharedRef<LibHac.FsSrv.Sf.IStorage> _baseStorage;
public IStorage(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IStorage> baseStorage)
public IStorage(ref SharedRef<LibHac.FsSrv.Sf.IStorage> baseStorage)
{
_baseStorage = baseStorage;
_baseStorage = SharedRef<LibHac.FsSrv.Sf.IStorage>.CreateMove(ref baseStorage);
}
[CommandHipc(0)]
@ -32,7 +33,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
byte[] data = new byte[size];
Result result = _baseStorage.Target.Read((long)offset, new OutBuffer(data), (long)size);
Result result = _baseStorage.Get.Read((long)offset, new OutBuffer(data), (long)size);
context.Memory.Write(buffDesc.Position, data);
@ -46,7 +47,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
// GetSize() -> u64 size
public ResultCode GetSize(ServiceCtx context)
{
Result result = _baseStorage.Target.GetSize(out long size);
Result result = _baseStorage.Get.GetSize(out long size);
context.ResponseData.Write(size);
@ -57,7 +58,7 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
{
if (isDisposing)
{
_baseStorage?.Dispose();
_baseStorage.Destroy();
}
}
}