diff options
| author | Ac_K <Acoustik666@gmail.com> | 2019-09-19 02:45:11 +0200 |
|---|---|---|
| committer | jduncanator <1518948+jduncanator@users.noreply.github.com> | 2019-09-19 10:45:11 +1000 |
| commit | a0720b5681852f3d786d77bd3793b0359dea321c (patch) | |
| tree | 9d8f61e540d1d1d827999902dad95e5c0c1e076e /Ryujinx.HLE/HOS/Services/FspSrv | |
| parent | 4af3101b22e6957d6aa48a2768566d658699f4ed (diff) | |
Refactoring HOS folder structure (#771)
* Refactoring HOS folder structure
Refactoring HOS folder structure:
- Added some subfolders when needed (Following structure decided in private).
- Added some `Types` folders when needed.
- Little cleanup here and there.
- Add services placeholders for every HOS services (close #766 and #753).
* Remove Types namespaces
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/FspSrv')
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/FspSrv/FileSystemHelper.cs | 144 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/FspSrv/FileSystemType.cs | 12 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/FspSrv/IDirectory.cs | 84 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/FspSrv/IFile.cs | 136 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/FspSrv/IFileSystem.cs | 324 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs | 271 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/FspSrv/IStorage.cs | 65 | ||||
| -rw-r--r-- | Ryujinx.HLE/HOS/Services/FspSrv/ResultCode.cs | 16 |
8 files changed, 0 insertions, 1052 deletions
diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/FileSystemHelper.cs b/Ryujinx.HLE/HOS/Services/FspSrv/FileSystemHelper.cs deleted file mode 100644 index d2e157f5..00000000 --- a/Ryujinx.HLE/HOS/Services/FspSrv/FileSystemHelper.cs +++ /dev/null @@ -1,144 +0,0 @@ -using LibHac; -using LibHac.Fs; -using LibHac.Fs.NcaUtils; -using Ryujinx.Common; -using Ryujinx.HLE.FileSystem; -using Ryujinx.HLE.Utilities; -using System.IO; - -namespace Ryujinx.HLE.HOS.Services.FspSrv -{ - static class FileSystemHelper - { - public static ResultCode LoadSaveDataFileSystem(ServiceCtx context, bool readOnly, out IFileSystem loadedFileSystem) - { - loadedFileSystem = null; - - SaveSpaceId saveSpaceId = (SaveSpaceId)context.RequestData.ReadInt64(); - ulong titleId = context.RequestData.ReadUInt64(); - UInt128 userId = context.RequestData.ReadStruct<UInt128>(); - long saveId = context.RequestData.ReadInt64(); - SaveDataType saveDataType = (SaveDataType)context.RequestData.ReadByte(); - SaveInfo saveInfo = new SaveInfo(titleId, saveId, saveDataType, saveSpaceId, userId); - string savePath = context.Device.FileSystem.GetSavePath(context, saveInfo); - - try - { - LocalFileSystem fileSystem = new LocalFileSystem(savePath); - LibHac.Fs.IFileSystem saveFileSystem = new DirectorySaveDataFileSystem(fileSystem); - - if (readOnly) - { - saveFileSystem = new ReadOnlyFileSystem(saveFileSystem); - } - - loadedFileSystem = new IFileSystem(saveFileSystem); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - public static ResultCode OpenNsp(ServiceCtx context, string pfsPath, out IFileSystem openedFileSystem) - { - openedFileSystem = null; - - try - { - LocalStorage storage = new LocalStorage(pfsPath, FileAccess.Read, FileMode.Open); - PartitionFileSystem nsp = new PartitionFileSystem(storage); - - ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet); - - openedFileSystem = new IFileSystem(nsp); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - public static ResultCode OpenNcaFs(ServiceCtx context, string ncaPath, LibHac.Fs.IStorage ncaStorage, out IFileSystem openedFileSystem) - { - openedFileSystem = null; - - try - { - Nca nca = new Nca(context.Device.System.KeySet, ncaStorage); - - if (!nca.SectionExists(NcaSectionType.Data)) - { - return ResultCode.PartitionNotFound; - } - - LibHac.Fs.IFileSystem fileSystem = nca.OpenFileSystem(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel); - - openedFileSystem = new IFileSystem(fileSystem); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - public static ResultCode OpenFileSystemFromInternalFile(ServiceCtx context, string fullPath, out IFileSystem openedFileSystem) - { - openedFileSystem = null; - - DirectoryInfo archivePath = new DirectoryInfo(fullPath).Parent; - - while (string.IsNullOrWhiteSpace(archivePath.Extension)) - { - archivePath = archivePath.Parent; - } - - if (archivePath.Extension == ".nsp" && File.Exists(archivePath.FullName)) - { - FileStream pfsFile = new FileStream( - archivePath.FullName.TrimEnd(Path.DirectorySeparatorChar), - FileMode.Open, - FileAccess.Read); - - try - { - PartitionFileSystem nsp = new PartitionFileSystem(pfsFile.AsStorage()); - - ImportTitleKeysFromNsp(nsp, context.Device.System.KeySet); - - string filename = fullPath.Replace(archivePath.FullName, string.Empty).TrimStart('\\'); - - if (nsp.FileExists(filename)) - { - return OpenNcaFs(context, fullPath, nsp.OpenFile(filename, OpenMode.Read).AsStorage(), out openedFileSystem); - } - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - } - - return ResultCode.PathDoesNotExist; - } - - public static void ImportTitleKeysFromNsp(LibHac.Fs.IFileSystem nsp, Keyset keySet) - { - foreach (DirectoryEntry ticketEntry in nsp.EnumerateEntries("*.tik")) - { - Ticket ticket = new Ticket(nsp.OpenFile(ticketEntry.FullPath, OpenMode.Read).AsStream()); - - if (!keySet.TitleKeys.ContainsKey(ticket.RightsId)) - { - keySet.TitleKeys.Add(ticket.RightsId, ticket.GetTitleKey(keySet)); - } - } - } - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/FileSystemType.cs b/Ryujinx.HLE/HOS/Services/FspSrv/FileSystemType.cs deleted file mode 100644 index 4b2d0ccd..00000000 --- a/Ryujinx.HLE/HOS/Services/FspSrv/FileSystemType.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Ryujinx.HLE.HOS.Services.FspSrv -{ - enum FileSystemType - { - Logo = 2, - ContentControl = 3, - ContentManual = 4, - ContentMeta = 5, - ContentData = 6, - ApplicationPackage = 7 - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/IDirectory.cs b/Ryujinx.HLE/HOS/Services/FspSrv/IDirectory.cs deleted file mode 100644 index 57d9142c..00000000 --- a/Ryujinx.HLE/HOS/Services/FspSrv/IDirectory.cs +++ /dev/null @@ -1,84 +0,0 @@ -using LibHac; -using System.Collections.Generic; -using System.Text; - -namespace Ryujinx.HLE.HOS.Services.FspSrv -{ - class IDirectory : IpcService - { - private const int DirectoryEntrySize = 0x310; - - private IEnumerator<LibHac.Fs.DirectoryEntry> _enumerator; - - private LibHac.Fs.IDirectory _baseDirectory; - - public IDirectory(LibHac.Fs.IDirectory directory) - { - _baseDirectory = directory; - _enumerator = directory.Read().GetEnumerator(); - } - - [Command(0)] - // Read() -> (u64 count, buffer<nn::fssrv::sf::IDirectoryEntry, 6, 0> entries) - public ResultCode Read(ServiceCtx context) - { - long bufferPosition = context.Request.ReceiveBuff[0].Position; - long bufferLen = context.Request.ReceiveBuff[0].Size; - - int maxReadCount = (int)(bufferLen / DirectoryEntrySize); - int readCount = 0; - - try - { - while (readCount < maxReadCount && _enumerator.MoveNext()) - { - long position = bufferPosition + readCount * DirectoryEntrySize; - - WriteDirectoryEntry(context, position, _enumerator.Current); - - readCount++; - } - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - context.ResponseData.Write((long)readCount); - - return ResultCode.Success; - } - - private void WriteDirectoryEntry(ServiceCtx context, long position, LibHac.Fs.DirectoryEntry entry) - { - for (int offset = 0; offset < 0x300; offset += 8) - { - context.Memory.WriteInt64(position + offset, 0); - } - - byte[] nameBuffer = Encoding.UTF8.GetBytes(entry.Name); - - context.Memory.WriteBytes(position, nameBuffer); - - context.Memory.WriteInt32(position + 0x300, (int)entry.Attributes); - context.Memory.WriteInt32(position + 0x304, (byte)entry.Type); - context.Memory.WriteInt64(position + 0x308, entry.Size); - } - - [Command(1)] - // GetEntryCount() -> u64 - public ResultCode GetEntryCount(ServiceCtx context) - { - try - { - context.ResponseData.Write((long)_baseDirectory.GetEntryCount()); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - } -} diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/IFile.cs b/Ryujinx.HLE/HOS/Services/FspSrv/IFile.cs deleted file mode 100644 index 7200611b..00000000 --- a/Ryujinx.HLE/HOS/Services/FspSrv/IFile.cs +++ /dev/null @@ -1,136 +0,0 @@ -using LibHac; -using LibHac.Fs; -using System; - -namespace Ryujinx.HLE.HOS.Services.FspSrv -{ - class IFile : IpcService, IDisposable - { - private LibHac.Fs.IFile _baseFile; - - public IFile(LibHac.Fs.IFile baseFile) - { - _baseFile = baseFile; - } - - [Command(0)] - // Read(u32 readOption, u64 offset, u64 size) -> (u64 out_size, buffer<u8, 0x46, 0> out_buf) - public ResultCode Read(ServiceCtx context) - { - long position = context.Request.ReceiveBuff[0].Position; - - ReadOption readOption = (ReadOption)context.RequestData.ReadInt32(); - context.RequestData.BaseStream.Position += 4; - - long offset = context.RequestData.ReadInt64(); - long size = context.RequestData.ReadInt64(); - - byte[] data = new byte[size]; - int readSize; - - try - { - readSize = _baseFile.Read(data, offset, readOption); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - context.Memory.WriteBytes(position, data); - - context.ResponseData.Write((long)readSize); - - return ResultCode.Success; - } - - [Command(1)] - // Write(u32 writeOption, u64 offset, u64 size, buffer<u8, 0x45, 0>) - public ResultCode Write(ServiceCtx context) - { - long position = context.Request.SendBuff[0].Position; - - WriteOption writeOption = (WriteOption)context.RequestData.ReadInt32(); - context.RequestData.BaseStream.Position += 4; - - long offset = context.RequestData.ReadInt64(); - long size = context.RequestData.ReadInt64(); - - byte[] data = context.Memory.ReadBytes(position, size); - - try - { - _baseFile.Write(data, offset, writeOption); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(2)] - // Flush() - public ResultCode Flush(ServiceCtx context) - { - try - { - _baseFile.Flush(); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(3)] - // SetSize(u64 size) - public ResultCode SetSize(ServiceCtx context) - { - try - { - long size = context.RequestData.ReadInt64(); - - _baseFile.SetSize(size); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(4)] - // GetSize() -> u64 fileSize - public ResultCode GetSize(ServiceCtx context) - { - try - { - context.ResponseData.Write(_baseFile.GetSize()); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - public void Dispose() - { - Dispose(true); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - _baseFile?.Dispose(); - } - } - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystem.cs b/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystem.cs deleted file mode 100644 index bcdc6fc3..00000000 --- a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystem.cs +++ /dev/null @@ -1,324 +0,0 @@ -using LibHac; -using LibHac.Fs; - -using static Ryujinx.HLE.Utilities.StringUtils; - -namespace Ryujinx.HLE.HOS.Services.FspSrv -{ - class IFileSystem : IpcService - { - private LibHac.Fs.IFileSystem _fileSystem; - - public IFileSystem(LibHac.Fs.IFileSystem provider) - { - _fileSystem = provider; - } - - [Command(0)] - // CreateFile(u32 createOption, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path) - public ResultCode CreateFile(ServiceCtx context) - { - string name = ReadUtf8String(context); - - CreateFileOptions createOption = (CreateFileOptions)context.RequestData.ReadInt32(); - context.RequestData.BaseStream.Position += 4; - - long size = context.RequestData.ReadInt64(); - - try - { - _fileSystem.CreateFile(name, size, createOption); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(1)] - // DeleteFile(buffer<bytes<0x301>, 0x19, 0x301> path) - public ResultCode DeleteFile(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - _fileSystem.DeleteFile(name); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(2)] - // CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path) - public ResultCode CreateDirectory(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - _fileSystem.CreateDirectory(name); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(3)] - // DeleteDirectory(buffer<bytes<0x301>, 0x19, 0x301> path) - public ResultCode DeleteDirectory(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - _fileSystem.DeleteDirectory(name); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(4)] - // DeleteDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path) - public ResultCode DeleteDirectoryRecursively(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - _fileSystem.DeleteDirectoryRecursively(name); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(5)] - // RenameFile(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath) - public ResultCode RenameFile(ServiceCtx context) - { - string oldName = ReadUtf8String(context, 0); - string newName = ReadUtf8String(context, 1); - - try - { - _fileSystem.RenameFile(oldName, newName); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(6)] - // RenameDirectory(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath) - public ResultCode RenameDirectory(ServiceCtx context) - { - string oldName = ReadUtf8String(context, 0); - string newName = ReadUtf8String(context, 1); - - try - { - _fileSystem.RenameDirectory(oldName, newName); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(7)] - // GetEntryType(buffer<bytes<0x301>, 0x19, 0x301> path) -> nn::fssrv::sf::DirectoryEntryType - public ResultCode GetEntryType(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - DirectoryEntryType entryType = _fileSystem.GetEntryType(name); - - if (entryType == DirectoryEntryType.Directory || entryType == DirectoryEntryType.File) - { - context.ResponseData.Write((int)entryType); - } - else - { - return ResultCode.PathDoesNotExist; - } - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(8)] - // 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(); - - string name = ReadUtf8String(context); - - try - { - LibHac.Fs.IFile file = _fileSystem.OpenFile(name, mode); - - IFile fileInterface = new IFile(file); - - MakeObject(context, fileInterface); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(9)] - // 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(); - - string name = ReadUtf8String(context); - - try - { - LibHac.Fs.IDirectory dir = _fileSystem.OpenDirectory(name, mode); - - IDirectory dirInterface = new IDirectory(dir); - - MakeObject(context, dirInterface); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(10)] - // Commit() - public ResultCode Commit(ServiceCtx context) - { - try - { - _fileSystem.Commit(); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(11)] - // GetFreeSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalFreeSpace - public ResultCode GetFreeSpaceSize(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - context.ResponseData.Write(_fileSystem.GetFreeSpaceSize(name)); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(12)] - // GetTotalSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalSize - public ResultCode GetTotalSpaceSize(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - context.ResponseData.Write(_fileSystem.GetTotalSpaceSize(name)); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(13)] - // CleanDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path) - public ResultCode CleanDirectoryRecursively(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - _fileSystem.CleanDirectoryRecursively(name); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - - [Command(14)] - // GetFileTimeStampRaw(buffer<bytes<0x301>, 0x19, 0x301> path) -> bytes<0x20> timestamp - public ResultCode GetFileTimeStampRaw(ServiceCtx context) - { - string name = ReadUtf8String(context); - - try - { - FileTimeStampRaw timestamp = _fileSystem.GetFileTimeStampRaw(name); - - context.ResponseData.Write(timestamp.Created); - context.ResponseData.Write(timestamp.Modified); - context.ResponseData.Write(timestamp.Accessed); - - byte[] data = new byte[8]; - - // is valid? - data[0] = 1; - - context.ResponseData.Write(data); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs b/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs deleted file mode 100644 index 43f5d647..00000000 --- a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs +++ /dev/null @@ -1,271 +0,0 @@ -using LibHac; -using LibHac.Fs; -using LibHac.Fs.NcaUtils; -using Ryujinx.Common.Logging; -using Ryujinx.HLE.FileSystem; -using System.IO; - -using static Ryujinx.HLE.FileSystem.VirtualFileSystem; -using static Ryujinx.HLE.Utilities.StringUtils; - -namespace Ryujinx.HLE.HOS.Services.FspSrv -{ - [Service("fsp-srv")] - class IFileSystemProxy : IpcService - { - public IFileSystemProxy(ServiceCtx context) { } - - [Command(1)] - // Initialize(u64, pid) - public ResultCode Initialize(ServiceCtx context) - { - return ResultCode.Success; - } - - [Command(8)] - // OpenFileSystemWithId(nn::fssrv::sf::FileSystemType filesystem_type, nn::ApplicationId tid, buffer<bytes<0x301>, 0x19, 0x301> path) - // -> object<nn::fssrv::sf::IFileSystem> contentFs - public ResultCode OpenFileSystemWithId(ServiceCtx context) - { - FileSystemType fileSystemType = (FileSystemType)context.RequestData.ReadInt32(); - long titleId = context.RequestData.ReadInt64(); - string switchPath = ReadUtf8String(context); - string fullPath = context.Device.FileSystem.SwitchPathToSystemPath(switchPath); - - if (!File.Exists(fullPath)) - { - if (fullPath.Contains(".")) - { - ResultCode result = FileSystemHelper.OpenFileSystemFromInternalFile(context, fullPath, out IFileSystem fileSystem); - - if (result == ResultCode.Success) - { - MakeObject(context, fileSystem); - } - - return result; - } - - return ResultCode.PathDoesNotExist; - } - - FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read); - string extension = Path.GetExtension(fullPath); - - if (extension == ".nca") - { - ResultCode result = FileSystemHelper.OpenNcaFs(context, fullPath, fileStream.AsStorage(), out IFileSystem fileSystem); - - if (result == ResultCode.Success) - { - MakeObject(context, fileSystem); - } - - return result; - } - else if (extension == ".nsp") - { - ResultCode result = FileSystemHelper.OpenNsp(context, fullPath, out IFileSystem fileSystem); - - if (result == ResultCode.Success) - { - MakeObject(context, fileSystem); - } - - return result; - } - - return ResultCode.InvalidInput; - } - - [Command(11)] - // OpenBisFileSystem(nn::fssrv::sf::Partition partitionID, buffer<bytes<0x301>, 0x19, 0x301>) -> object<nn::fssrv::sf::IFileSystem> Bis - public ResultCode OpenBisFileSystem(ServiceCtx context) - { - int bisPartitionId = context.RequestData.ReadInt32(); - string partitionString = ReadUtf8String(context); - string bisPartitionPath = string.Empty; - - switch (bisPartitionId) - { - case 29: - bisPartitionPath = SafeNandPath; - break; - case 30: - case 31: - bisPartitionPath = SystemNandPath; - break; - case 32: - bisPartitionPath = UserNandPath; - break; - default: - return ResultCode.InvalidInput; - } - - string fullPath = context.Device.FileSystem.GetFullPartitionPath(bisPartitionPath); - - LocalFileSystem fileSystem = new LocalFileSystem(fullPath); - - MakeObject(context, new IFileSystem(fileSystem)); - - return ResultCode.Success; - } - - [Command(18)] - // OpenSdCardFileSystem() -> object<nn::fssrv::sf::IFileSystem> - public ResultCode OpenSdCardFileSystem(ServiceCtx context) - { - string sdCardPath = context.Device.FileSystem.GetSdCardPath(); - - LocalFileSystem fileSystem = new LocalFileSystem(sdCardPath); - - MakeObject(context, new IFileSystem(fileSystem)); - - return ResultCode.Success; - } - - [Command(51)] - // OpenSaveDataFileSystem(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> saveDataFs - public ResultCode OpenSaveDataFileSystem(ServiceCtx context) - { - ResultCode result = FileSystemHelper.LoadSaveDataFileSystem(context, false, out IFileSystem fileSystem); - - if (result == ResultCode.Success) - { - MakeObject(context, fileSystem); - } - - return result; - } - - [Command(52)] - // OpenSaveDataFileSystemBySystemSaveDataId(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> systemSaveDataFs - public ResultCode OpenSaveDataFileSystemBySystemSaveDataId(ServiceCtx context) - { - ResultCode result = FileSystemHelper.LoadSaveDataFileSystem(context, false, out IFileSystem fileSystem); - - if (result == ResultCode.Success) - { - MakeObject(context, fileSystem); - } - - return result; - } - - [Command(53)] - // OpenReadOnlySaveDataFileSystem(u8 save_data_space_id, nn::fssrv::sf::SaveStruct save_struct) -> object<nn::fssrv::sf::IFileSystem> - public ResultCode OpenReadOnlySaveDataFileSystem(ServiceCtx context) - { - ResultCode result = FileSystemHelper.LoadSaveDataFileSystem(context, true, out IFileSystem fileSystem); - - if (result == ResultCode.Success) - { - MakeObject(context, fileSystem); - } - - return result; - } - - [Command(200)] - // OpenDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage> dataStorage - public ResultCode OpenDataStorageByCurrentProcess(ServiceCtx context) - { - MakeObject(context, new IStorage(context.Device.FileSystem.RomFs.AsStorage())); - - return 0; - } - - [Command(202)] - // OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage - public ResultCode OpenDataStorageByDataId(ServiceCtx context) - { - StorageId storageId = (StorageId)context.RequestData.ReadByte(); - byte[] padding = context.RequestData.ReadBytes(7); - long titleId = context.RequestData.ReadInt64(); - - ContentType contentType = ContentType.Data; - - StorageId installedStorage = - context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId); - - if (installedStorage == StorageId.None) - { - contentType = ContentType.PublicData; - - installedStorage = - context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId); - } - - if (installedStorage != StorageId.None) - { - string contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, contentType); - string installPath = context.Device.FileSystem.SwitchPathToSystemPath(contentPath); - - if (!string.IsNullOrWhiteSpace(installPath)) - { - string ncaPath = installPath; - - if (File.Exists(ncaPath)) - { - try - { - LibHac.Fs.IStorage ncaStorage = new LocalStorage(ncaPath, FileAccess.Read, FileMode.Open); - Nca nca = new Nca(context.Device.System.KeySet, ncaStorage); - LibHac.Fs.IStorage romfsStorage = nca.OpenStorage(NcaSectionType.Data, context.Device.System.FsIntegrityCheckLevel); - - MakeObject(context, new IStorage(romfsStorage)); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - else - { - throw new FileNotFoundException($"No Nca found in Path `{ncaPath}`."); - } - } - else - { - throw new DirectoryNotFoundException($"Path for title id {titleId:x16} on Storage {storageId} was not found in Path {installPath}."); - } - } - - throw new FileNotFoundException($"System archive with titleid {titleId:x16} was not found on Storage {storageId}. Found in {installedStorage}."); - } - - [Command(203)] - // OpenPatchDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage> - public ResultCode OpenPatchDataStorageByCurrentProcess(ServiceCtx context) - { - MakeObject(context, new IStorage(context.Device.FileSystem.RomFs.AsStorage())); - - return ResultCode.Success; - } - - [Command(1005)] - // GetGlobalAccessLogMode() -> u32 logMode - public ResultCode GetGlobalAccessLogMode(ServiceCtx context) - { - int mode = context.Device.System.GlobalAccessLogMode; - - context.ResponseData.Write(mode); - - return ResultCode.Success; - } - - [Command(1006)] - // OutputAccessLogToSdCard(buffer<bytes, 5> log_text) - public ResultCode OutputAccessLogToSdCard(ServiceCtx context) - { - string message = ReadUtf8StringSend(context); - - // FS ends each line with a newline. Remove it because Ryujinx logging adds its own newline - Logger.PrintAccessLog(LogClass.ServiceFs, message.TrimEnd('\n')); - - return ResultCode.Success; - } - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/IStorage.cs b/Ryujinx.HLE/HOS/Services/FspSrv/IStorage.cs deleted file mode 100644 index d13a12db..00000000 --- a/Ryujinx.HLE/HOS/Services/FspSrv/IStorage.cs +++ /dev/null @@ -1,65 +0,0 @@ -using LibHac; -using Ryujinx.HLE.HOS.Ipc; - -namespace Ryujinx.HLE.HOS.Services.FspSrv -{ - class IStorage : IpcService - { - private LibHac.Fs.IStorage _baseStorage; - - public IStorage(LibHac.Fs.IStorage baseStorage) - { - _baseStorage = baseStorage; - } - - [Command(0)] - // Read(u64 offset, u64 length) -> buffer<u8, 0x46, 0> buffer - public ResultCode Read(ServiceCtx context) - { - long offset = context.RequestData.ReadInt64(); - long size = context.RequestData.ReadInt64(); - - if (context.Request.ReceiveBuff.Count > 0) - { - IpcBuffDesc buffDesc = context.Request.ReceiveBuff[0]; - - // Use smaller length to avoid overflows. - if (size > buffDesc.Size) - { - size = buffDesc.Size; - } - - byte[] data = new byte[size]; - - try - { - _baseStorage.Read(data, offset); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - context.Memory.WriteBytes(buffDesc.Position, data); - } - - return ResultCode.Success; - } - - [Command(4)] - // GetSize() -> u64 size - public ResultCode GetSize(ServiceCtx context) - { - try - { - context.ResponseData.Write(_baseStorage.GetSize()); - } - catch (HorizonResultException ex) - { - return (ResultCode)ex.ResultValue.Value; - } - - return ResultCode.Success; - } - } -}
\ No newline at end of file diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/ResultCode.cs b/Ryujinx.HLE/HOS/Services/FspSrv/ResultCode.cs deleted file mode 100644 index b2be9293..00000000 --- a/Ryujinx.HLE/HOS/Services/FspSrv/ResultCode.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Ryujinx.HLE.HOS.Services.FspSrv -{ - enum ResultCode - { - ModuleId = 2, - ErrorCodeShift = 9, - - Success = 0, - - PathDoesNotExist = (1 << ErrorCodeShift) | ModuleId, - PathAlreadyExists = (2 << ErrorCodeShift) | ModuleId, - PathAlreadyInUse = (7 << ErrorCodeShift) | ModuleId, - PartitionNotFound = (1001 << ErrorCodeShift) | ModuleId, - InvalidInput = (6001 << ErrorCodeShift) | ModuleId - } -}
\ No newline at end of file |
