2018-11-18 20:37:41 +01:00
|
|
|
using LibHac;
|
2019-06-01 02:31:10 +02:00
|
|
|
using LibHac.Fs;
|
|
|
|
using LibHac.Fs.NcaUtils;
|
2019-06-16 03:31:18 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-09-09 00:04:26 +02:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
2018-11-18 20:37:41 +01:00
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using static Ryujinx.HLE.FileSystem.VirtualFileSystem;
|
|
|
|
using static Ryujinx.HLE.Utilities.StringUtils;
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.FspSrv
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2019-07-10 17:59:54 +02:00
|
|
|
[Service("fsp-srv")]
|
2018-04-06 06:01:52 +02:00
|
|
|
class IFileSystemProxy : IpcService
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2019-07-12 03:13:43 +02:00
|
|
|
public IFileSystemProxy(ServiceCtx context) { }
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(1)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// Initialize(u64, pid)
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode Initialize(ServiceCtx context)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(8)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenFileSystemWithId(nn::fssrv::sf::FileSystemType filesystem_type, nn::ApplicationId tid, buffer<bytes<0x301>, 0x19, 0x301> path)
|
|
|
|
// -> object<nn::fssrv::sf::IFileSystem> contentFs
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OpenFileSystemWithId(ServiceCtx context)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
FileSystemType fileSystemType = (FileSystemType)context.RequestData.ReadInt32();
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
|
|
|
string switchPath = ReadUtf8String(context);
|
|
|
|
string fullPath = context.Device.FileSystem.SwitchPathToSystemPath(switchPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!File.Exists(fullPath))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (fullPath.Contains("."))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2019-09-08 23:33:40 +02:00
|
|
|
ResultCode result = FileSystemHelper.OpenFileSystemFromInternalFile(context, fullPath, out IFileSystem fileSystem);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
MakeObject(context, fileSystem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.PathDoesNotExist;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
|
|
|
|
string extension = Path.GetExtension(fullPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (extension == ".nca")
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2019-09-08 23:33:40 +02:00
|
|
|
ResultCode result = FileSystemHelper.OpenNcaFs(context, fullPath, fileStream.AsStorage(), out IFileSystem fileSystem);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
MakeObject(context, fileSystem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (extension == ".nsp")
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2019-09-08 23:33:40 +02:00
|
|
|
ResultCode result = FileSystemHelper.OpenNsp(context, fullPath, out IFileSystem fileSystem);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
MakeObject(context, fileSystem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.InvalidInput;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(11)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenBisFileSystem(nn::fssrv::sf::Partition partitionID, buffer<bytes<0x301>, 0x19, 0x301>) -> object<nn::fssrv::sf::IFileSystem> Bis
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OpenBisFileSystem(ServiceCtx context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2019-06-01 02:31:10 +02:00
|
|
|
int bisPartitionId = context.RequestData.ReadInt32();
|
|
|
|
string partitionString = ReadUtf8String(context);
|
|
|
|
string bisPartitionPath = string.Empty;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
switch (bisPartitionId)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
|
|
|
case 29:
|
2019-06-01 02:31:10 +02:00
|
|
|
bisPartitionPath = SafeNandPath;
|
2018-11-18 20:37:41 +01:00
|
|
|
break;
|
|
|
|
case 30:
|
|
|
|
case 31:
|
2019-06-01 02:31:10 +02:00
|
|
|
bisPartitionPath = SystemNandPath;
|
2018-11-18 20:37:41 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2019-06-01 02:31:10 +02:00
|
|
|
bisPartitionPath = UserNandPath;
|
2018-11-18 20:37:41 +01:00
|
|
|
break;
|
|
|
|
default:
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.InvalidInput;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2019-06-01 02:31:10 +02:00
|
|
|
string fullPath = context.Device.FileSystem.GetFullPartitionPath(bisPartitionPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2019-06-01 02:31:10 +02:00
|
|
|
LocalFileSystem fileSystem = new LocalFileSystem(fullPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2019-06-01 02:31:10 +02:00
|
|
|
MakeObject(context, new IFileSystem(fileSystem));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(18)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenSdCardFileSystem() -> object<nn::fssrv::sf::IFileSystem>
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OpenSdCardFileSystem(ServiceCtx context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string sdCardPath = context.Device.FileSystem.GetSdCardPath();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2019-06-01 02:31:10 +02:00
|
|
|
LocalFileSystem fileSystem = new LocalFileSystem(sdCardPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2019-06-01 02:31:10 +02:00
|
|
|
MakeObject(context, new IFileSystem(fileSystem));
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(51)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenSaveDataFileSystem(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> saveDataFs
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OpenSaveDataFileSystem(ServiceCtx context)
|
2018-06-03 00:46:09 +02:00
|
|
|
{
|
2019-09-08 23:33:40 +02:00
|
|
|
ResultCode result = FileSystemHelper.LoadSaveDataFileSystem(context, false, out IFileSystem fileSystem);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
MakeObject(context, fileSystem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2018-06-03 00:46:09 +02:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(52)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenSaveDataFileSystemBySystemSaveDataId(u8 save_data_space_id, nn::fssrv::sf::SaveStruct saveStruct) -> object<nn::fssrv::sf::IFileSystem> systemSaveDataFs
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OpenSaveDataFileSystemBySystemSaveDataId(ServiceCtx context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2019-09-08 23:33:40 +02:00
|
|
|
ResultCode result = FileSystemHelper.LoadSaveDataFileSystem(context, false, out IFileSystem fileSystem);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
MakeObject(context, fileSystem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2019-09-02 18:38:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[Command(53)]
|
|
|
|
// OpenReadOnlySaveDataFileSystem(u8 save_data_space_id, nn::fssrv::sf::SaveStruct save_struct) -> object<nn::fssrv::sf::IFileSystem>
|
|
|
|
public ResultCode OpenReadOnlySaveDataFileSystem(ServiceCtx context)
|
|
|
|
{
|
2019-09-08 23:33:40 +02:00
|
|
|
ResultCode result = FileSystemHelper.LoadSaveDataFileSystem(context, true, out IFileSystem fileSystem);
|
|
|
|
|
|
|
|
if (result == ResultCode.Success)
|
|
|
|
{
|
|
|
|
MakeObject(context, fileSystem);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(200)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage> dataStorage
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OpenDataStorageByCurrentProcess(ServiceCtx context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2019-06-01 02:31:10 +02:00
|
|
|
MakeObject(context, new IStorage(context.Device.FileSystem.RomFs.AsStorage()));
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(202)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenDataStorageByDataId(u8 storageId, nn::ApplicationId tid) -> object<nn::fssrv::sf::IStorage> dataStorage
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OpenDataStorageByDataId(ServiceCtx context)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
StorageId storageId = (StorageId)context.RequestData.ReadByte();
|
|
|
|
byte[] padding = context.RequestData.ReadBytes(7);
|
|
|
|
long titleId = context.RequestData.ReadInt64();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-30 14:36:35 +01:00
|
|
|
ContentType contentType = ContentType.Data;
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
StorageId installedStorage =
|
2018-12-30 14:36:35 +01:00
|
|
|
context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (installedStorage == StorageId.None)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2019-06-01 02:31:10 +02:00
|
|
|
contentType = ContentType.PublicData;
|
2018-12-30 14:36:35 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
installedStorage =
|
2018-12-30 14:36:35 +01:00
|
|
|
context.Device.System.ContentManager.GetInstalledStorage(titleId, contentType, storageId);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (installedStorage != StorageId.None)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-30 14:36:35 +01:00
|
|
|
string contentPath = context.Device.System.ContentManager.GetInstalledContentPath(titleId, storageId, contentType);
|
2018-12-06 12:16:24 +01:00
|
|
|
string installPath = context.Device.FileSystem.SwitchPathToSystemPath(contentPath);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!string.IsNullOrWhiteSpace(installPath))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string ncaPath = installPath;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (File.Exists(ncaPath))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2019-07-10 19:20:01 +02:00
|
|
|
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)
|
|
|
|
{
|
2019-07-14 21:04:38 +02:00
|
|
|
return (ResultCode)ex.ResultValue.Value;
|
2019-07-10 19:20:01 +02:00
|
|
|
}
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
throw new FileNotFoundException($"No Nca found in Path `{ncaPath}`.");
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
throw new DirectoryNotFoundException($"Path for title id {titleId:x16} on Storage {storageId} was not found in Path {installPath}.");
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
throw new FileNotFoundException($"System archive with titleid {titleId:x16} was not found on Storage {storageId}. Found in {installedStorage}.");
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(203)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenPatchDataStorageByCurrentProcess() -> object<nn::fssrv::sf::IStorage>
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OpenPatchDataStorageByCurrentProcess(ServiceCtx context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2019-06-01 02:31:10 +02:00
|
|
|
MakeObject(context, new IStorage(context.Device.FileSystem.RomFs.AsStorage()));
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(1005)]
|
2018-11-18 20:37:41 +01:00
|
|
|
// GetGlobalAccessLogMode() -> u32 logMode
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode GetGlobalAccessLogMode(ServiceCtx context)
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
2019-06-16 03:31:18 +02:00
|
|
|
int mode = context.Device.System.GlobalAccessLogMode;
|
|
|
|
|
|
|
|
context.ResponseData.Write(mode);
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2019-06-16 03:31:18 +02:00
|
|
|
}
|
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(1006)]
|
2019-06-16 03:31:18 +02:00
|
|
|
// OutputAccessLogToSdCard(buffer<bytes, 5> log_text)
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode OutputAccessLogToSdCard(ServiceCtx context)
|
2019-06-16 03:31:18 +02:00
|
|
|
{
|
|
|
|
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'));
|
2018-02-25 05:34:16 +01:00
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2018-04-06 06:01:52 +02:00
|
|
|
}
|
2018-02-25 05:34:16 +01:00
|
|
|
}
|
|
|
|
}
|