Update to LibHac 0.13.1 (#2328)
Update the LibHac dependency to version 0.13.1. This brings a ton of improvements and changes such as: - Refactor `FsSrv` to match the official refactoring done in FS. - Change how the `Horizon` and `HorizonClient` classes are handled. Each client created represents a different process with its own process ID and client state. - Add FS access control to handle permissions for FS service method calls. - Add FS program registry to keep track of the program ID, location and permissions of each process. - Add FS program index map info manager to track the program IDs and indexes of multi-application programs. - Add all FS IPC interfaces. - Rewrite `Fs.Fsa` code to be more accurate. - Rewrite a lot of `FsSrv` code to be more accurate. - Extend directory save data to store `SaveDataExtraData` - Extend directory save data to lock the save directory to allow only one accessor at a time. - Improve waiting and retrying when encountering access issues in `LocalFileSystem` and `DirectorySaveDataFileSystem`. - More `IFileSystemProxy` methods should work now. - Probably a bunch more stuff. On the Ryujinx side: - Forward most `IFileSystemProxy` methods to LibHac. - Register programs and program index map info when launching an application. - Remove hacks and workarounds for missing LibHac functionality. - Recreate missing save data extra data found on emulator startup. - Create system save data that wasn't indexed correctly on an older LibHac version. `FsSrv` now enforces access control for each process. When a process tries to open a save data file system, FS reads the save's extra data to determine who the save owner is and if the caller has permission to open the save data. Previously-created save data did not have extra data created when the save was created. With access control checks in place, this means that processes with no permissions (most games) wouldn't be able to access their own save data. The extra data can be partially created from data in the save data indexer, which should be enough for access control purposes.
This commit is contained in:
parent
04dce402ac
commit
19afb3209c
31 changed files with 1795 additions and 574 deletions
|
@ -1,21 +1,19 @@
|
|||
using LibHac;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using static Ryujinx.HLE.Utilities.StringUtils;
|
||||
using LibHac.FsSrv.Sf;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
||||
{
|
||||
class IFileSystem : IpcService
|
||||
class IFileSystem : DisposableIpcService
|
||||
{
|
||||
private LibHac.Fs.Fsa.IFileSystem _fileSystem;
|
||||
private ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> _fileSystem;
|
||||
|
||||
public IFileSystem(LibHac.Fs.Fsa.IFileSystem provider)
|
||||
public IFileSystem(ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> provider)
|
||||
{
|
||||
_fileSystem = provider;
|
||||
}
|
||||
|
||||
public LibHac.Fs.Fsa.IFileSystem GetBaseFileSystem()
|
||||
public ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystem> GetBaseFileSystem()
|
||||
{
|
||||
return _fileSystem;
|
||||
}
|
||||
|
@ -24,79 +22,79 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
|||
// CreateFile(u32 createOption, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path)
|
||||
public ResultCode CreateFile(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
CreateFileOptions createOption = (CreateFileOptions)context.RequestData.ReadInt32();
|
||||
int createOption = context.RequestData.ReadInt32();
|
||||
context.RequestData.BaseStream.Position += 4;
|
||||
|
||||
long size = context.RequestData.ReadInt64();
|
||||
|
||||
return (ResultCode)_fileSystem.CreateFile(name, size, createOption).Value;
|
||||
return (ResultCode)_fileSystem.Target.CreateFile(in name, size, createOption).Value;
|
||||
}
|
||||
|
||||
[CommandHipc(1)]
|
||||
// DeleteFile(buffer<bytes<0x301>, 0x19, 0x301> path)
|
||||
public ResultCode DeleteFile(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
return (ResultCode)_fileSystem.DeleteFile(name).Value;
|
||||
return (ResultCode)_fileSystem.Target.DeleteFile(in name).Value;
|
||||
}
|
||||
|
||||
[CommandHipc(2)]
|
||||
// CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
||||
public ResultCode CreateDirectory(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
return (ResultCode)_fileSystem.CreateDirectory(name).Value;
|
||||
return (ResultCode)_fileSystem.Target.CreateDirectory(in name).Value;
|
||||
}
|
||||
|
||||
[CommandHipc(3)]
|
||||
// DeleteDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
||||
public ResultCode DeleteDirectory(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
return (ResultCode)_fileSystem.DeleteDirectory(name).Value;
|
||||
return (ResultCode)_fileSystem.Target.DeleteDirectory(in name).Value;
|
||||
}
|
||||
|
||||
[CommandHipc(4)]
|
||||
// DeleteDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
||||
public ResultCode DeleteDirectoryRecursively(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
return (ResultCode)_fileSystem.DeleteDirectoryRecursively(name).Value;
|
||||
return (ResultCode)_fileSystem.Target.DeleteDirectoryRecursively(in name).Value;
|
||||
}
|
||||
|
||||
[CommandHipc(5)]
|
||||
// RenameFile(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
||||
public ResultCode RenameFile(ServiceCtx context)
|
||||
{
|
||||
U8Span oldName = ReadUtf8Span(context, 0);
|
||||
U8Span newName = ReadUtf8Span(context, 1);
|
||||
ref readonly Path currentName = ref FileSystemProxyHelper.GetSfPath(context, index: 0);
|
||||
ref readonly Path newName = ref FileSystemProxyHelper.GetSfPath(context, index: 1);
|
||||
|
||||
return (ResultCode)_fileSystem.RenameFile(oldName, newName).Value;
|
||||
return (ResultCode)_fileSystem.Target.RenameFile(in currentName, in newName).Value;
|
||||
}
|
||||
|
||||
[CommandHipc(6)]
|
||||
// RenameDirectory(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
||||
public ResultCode RenameDirectory(ServiceCtx context)
|
||||
{
|
||||
U8Span oldName = ReadUtf8Span(context, 0);
|
||||
U8Span newName = ReadUtf8Span(context, 1);
|
||||
ref readonly Path currentName = ref FileSystemProxyHelper.GetSfPath(context, index: 0);
|
||||
ref readonly Path newName = ref FileSystemProxyHelper.GetSfPath(context, index: 1);
|
||||
|
||||
return (ResultCode)_fileSystem.RenameDirectory(oldName, newName).Value;
|
||||
return (ResultCode)_fileSystem.Target.RenameDirectory(in currentName, in newName).Value;
|
||||
}
|
||||
|
||||
[CommandHipc(7)]
|
||||
// GetEntryType(buffer<bytes<0x301>, 0x19, 0x301> path) -> nn::fssrv::sf::DirectoryEntryType
|
||||
public ResultCode GetEntryType(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
Result result = _fileSystem.GetEntryType(out DirectoryEntryType entryType, name);
|
||||
Result result = _fileSystem.Target.GetEntryType(out uint entryType, in name);
|
||||
|
||||
context.ResponseData.Write((int)entryType);
|
||||
|
||||
|
@ -107,11 +105,11 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
|||
// OpenFile(u32 mode, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IFile> file
|
||||
public ResultCode OpenFile(ServiceCtx context)
|
||||
{
|
||||
OpenMode mode = (OpenMode)context.RequestData.ReadInt32();
|
||||
uint mode = context.RequestData.ReadUInt32();
|
||||
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
Result result = _fileSystem.OpenFile(out LibHac.Fs.Fsa.IFile file, name, mode);
|
||||
Result result = _fileSystem.Target.OpenFile(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFile> file, in name, mode);
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
|
@ -127,11 +125,11 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
|||
// OpenDirectory(u32 filter_flags, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IDirectory> directory
|
||||
public ResultCode OpenDirectory(ServiceCtx context)
|
||||
{
|
||||
OpenDirectoryMode mode = (OpenDirectoryMode)context.RequestData.ReadInt32();
|
||||
uint mode = context.RequestData.ReadUInt32();
|
||||
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
Result result = _fileSystem.OpenDirectory(out LibHac.Fs.Fsa.IDirectory dir, name, mode);
|
||||
Result result = _fileSystem.Target.OpenDirectory(out ReferenceCountedDisposable<LibHac.FsSrv.Sf.IDirectory> dir, name, mode);
|
||||
|
||||
if (result.IsSuccess())
|
||||
{
|
||||
|
@ -147,16 +145,16 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
|||
// Commit()
|
||||
public ResultCode Commit(ServiceCtx context)
|
||||
{
|
||||
return (ResultCode)_fileSystem.Commit().Value;
|
||||
return (ResultCode)_fileSystem.Target.Commit().Value;
|
||||
}
|
||||
|
||||
[CommandHipc(11)]
|
||||
// GetFreeSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalFreeSpace
|
||||
public ResultCode GetFreeSpaceSize(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
Result result = _fileSystem.GetFreeSpaceSize(out long size, name);
|
||||
Result result = _fileSystem.Target.GetFreeSpaceSize(out long size, in name);
|
||||
|
||||
context.ResponseData.Write(size);
|
||||
|
||||
|
@ -167,9 +165,9 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
|||
// GetTotalSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalSize
|
||||
public ResultCode GetTotalSpaceSize(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
Result result = _fileSystem.GetTotalSpaceSize(out long size, name);
|
||||
Result result = _fileSystem.Target.GetTotalSpaceSize(out long size, in name);
|
||||
|
||||
context.ResponseData.Write(size);
|
||||
|
||||
|
@ -180,18 +178,18 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
|||
// CleanDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
||||
public ResultCode CleanDirectoryRecursively(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
return (ResultCode)_fileSystem.CleanDirectoryRecursively(name).Value;
|
||||
return (ResultCode)_fileSystem.Target.CleanDirectoryRecursively(in name).Value;
|
||||
}
|
||||
|
||||
[CommandHipc(14)]
|
||||
// GetFileTimeStampRaw(buffer<bytes<0x301>, 0x19, 0x301> path) -> bytes<0x20> timestamp
|
||||
public ResultCode GetFileTimeStampRaw(ServiceCtx context)
|
||||
{
|
||||
U8Span name = ReadUtf8Span(context);
|
||||
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
||||
|
||||
Result result = _fileSystem.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, name);
|
||||
Result result = _fileSystem.Target.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, in name);
|
||||
|
||||
context.ResponseData.Write(timestamp.Created);
|
||||
context.ResponseData.Write(timestamp.Modified);
|
||||
|
@ -206,5 +204,13 @@ namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
|||
|
||||
return (ResultCode)result.Value;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
if (isDisposing)
|
||||
{
|
||||
_fileSystem?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue