2019-07-10 13:20:01 -04:00
|
|
|
using LibHac;
|
2021-12-23 11:55:50 -05:00
|
|
|
using LibHac.Common;
|
2019-05-31 20:31:10 -04:00
|
|
|
using LibHac.Fs;
|
2021-12-23 11:55:50 -05:00
|
|
|
using Path = LibHac.FsSrv.Sf.Path;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2019-09-18 20:45:11 -04:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
class IFileSystem : DisposableIpcService
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2021-12-23 11:55:50 -05:00
|
|
|
private SharedRef<LibHac.FsSrv.Sf.IFileSystem> _fileSystem;
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
public IFileSystem(ref SharedRef<LibHac.FsSrv.Sf.IFileSystem> provider)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2021-12-23 11:55:50 -05:00
|
|
|
_fileSystem = SharedRef<LibHac.FsSrv.Sf.IFileSystem>.CreateMove(ref provider);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
public SharedRef<LibHac.FsSrv.Sf.IFileSystem> GetBaseFileSystem()
|
2020-03-25 04:14:35 -04:00
|
|
|
{
|
2021-12-23 11:55:50 -05:00
|
|
|
return SharedRef<LibHac.FsSrv.Sf.IFileSystem>.CreateCopy(in _fileSystem);
|
2020-03-25 04:14:35 -04:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(0)]
|
2019-05-31 20:31:10 -04:00
|
|
|
// CreateFile(u32 createOption, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode CreateFile(ServiceCtx context)
|
2018-02-20 06:03:04 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2021-08-12 17:56:24 -04:00
|
|
|
int createOption = context.RequestData.ReadInt32();
|
2019-05-31 20:31:10 -04:00
|
|
|
context.RequestData.BaseStream.Position += 4;
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2019-05-31 20:31:10 -04:00
|
|
|
long size = context.RequestData.ReadInt64();
|
2018-02-20 06:03:04 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.CreateFile(in name, size, createOption).Value;
|
2018-02-20 06:03:04 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(1)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// DeleteFile(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode DeleteFile(ServiceCtx context)
|
2018-02-20 06:03:04 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.DeleteFile(in name).Value;
|
2018-02-20 06:03:04 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(2)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode CreateDirectory(ServiceCtx context)
|
2018-02-20 06:03:04 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2018-02-20 06:03:04 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.CreateDirectory(in name).Value;
|
2018-02-21 16:56:52 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(3)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// DeleteDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode DeleteDirectory(ServiceCtx context)
|
2018-02-21 16:56:52 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2019-05-31 20:31:10 -04:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.DeleteDirectory(in name).Value;
|
2018-02-20 06:03:04 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(4)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// DeleteDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode DeleteDirectoryRecursively(ServiceCtx context)
|
2018-02-20 06:03:04 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2018-02-20 06:03:04 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.DeleteDirectoryRecursively(in name).Value;
|
2018-02-20 06:03:04 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(5)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// RenameFile(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode RenameFile(ServiceCtx context)
|
2018-02-20 06:03:04 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path currentName = ref FileSystemProxyHelper.GetSfPath(context, index: 0);
|
|
|
|
ref readonly Path newName = ref FileSystemProxyHelper.GetSfPath(context, index: 1);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.RenameFile(in currentName, in newName).Value;
|
2018-02-20 06:03:04 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(6)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// RenameDirectory(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode RenameDirectory(ServiceCtx context)
|
2018-02-20 06:03:04 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path currentName = ref FileSystemProxyHelper.GetSfPath(context, index: 0);
|
|
|
|
ref readonly Path newName = ref FileSystemProxyHelper.GetSfPath(context, index: 1);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.RenameDirectory(in currentName, in newName).Value;
|
2018-02-20 06:03:04 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(7)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// GetEntryType(buffer<bytes<0x301>, 0x19, 0x301> path) -> nn::fssrv::sf::DirectoryEntryType
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetEntryType(ServiceCtx context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
Result result = _fileSystem.Get.GetEntryType(out uint entryType, in name);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
context.ResponseData.Write((int)entryType);
|
|
|
|
|
|
|
|
return (ResultCode)result.Value;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(8)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenFile(u32 mode, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IFile> file
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenFile(ServiceCtx context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
uint mode = context.RequestData.ReadUInt32();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2021-12-23 11:55:50 -05:00
|
|
|
using var file = new SharedRef<LibHac.FsSrv.Sf.IFile>();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2023-03-01 21:42:27 -05:00
|
|
|
Result result = _fileSystem.Get.OpenFile(ref file.Ref, in name, mode);
|
2018-02-23 19:59:38 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
if (result.IsSuccess())
|
|
|
|
{
|
2023-03-01 21:42:27 -05:00
|
|
|
IFile fileInterface = new IFile(ref file.Ref);
|
2018-02-23 19:59:38 -05:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
MakeObject(context, fileInterface);
|
2019-05-31 20:31:10 -04:00
|
|
|
}
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
return (ResultCode)result.Value;
|
2018-02-20 06:03:04 -05:00
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(9)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// OpenDirectory(u32 filter_flags, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IDirectory> directory
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode OpenDirectory(ServiceCtx context)
|
2018-02-20 06:03:04 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
uint mode = context.RequestData.ReadUInt32();
|
2018-02-20 06:03:04 -05:00
|
|
|
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2021-12-23 11:55:50 -05:00
|
|
|
using var dir = new SharedRef<LibHac.FsSrv.Sf.IDirectory>();
|
2018-02-20 06:03:04 -05:00
|
|
|
|
2023-03-01 21:42:27 -05:00
|
|
|
Result result = _fileSystem.Get.OpenDirectory(ref dir.Ref, name, mode);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
if (result.IsSuccess())
|
|
|
|
{
|
2023-03-01 21:42:27 -05:00
|
|
|
IDirectory dirInterface = new IDirectory(ref dir.Ref);
|
2019-05-31 20:31:10 -04:00
|
|
|
|
2019-07-10 13:20:01 -04:00
|
|
|
MakeObject(context, dirInterface);
|
2019-05-31 20:31:10 -04:00
|
|
|
}
|
2018-11-18 14:37:41 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
return (ResultCode)result.Value;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(10)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// Commit()
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode Commit(ServiceCtx context)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.Commit().Value;
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(11)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// GetFreeSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalFreeSpace
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetFreeSpaceSize(ServiceCtx context)
|
2018-02-21 16:56:52 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
Result result = _fileSystem.Get.GetFreeSpaceSize(out long size, in name);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
context.ResponseData.Write(size);
|
|
|
|
|
|
|
|
return (ResultCode)result.Value;
|
2018-02-21 16:56:52 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(12)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// GetTotalSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalSize
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetTotalSpaceSize(ServiceCtx context)
|
2018-02-21 16:56:52 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
Result result = _fileSystem.Get.GetTotalSpaceSize(out long size, in name);
|
2019-10-17 02:17:44 -04:00
|
|
|
|
|
|
|
context.ResponseData.Write(size);
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
return (ResultCode)result.Value;
|
2018-02-21 16:56:52 -05:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(13)]
|
2018-11-18 14:37:41 -05:00
|
|
|
// CleanDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode CleanDirectoryRecursively(ServiceCtx context)
|
2018-07-18 15:05:17 -04:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2018-07-18 15:05:17 -04:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
return (ResultCode)_fileSystem.Get.CleanDirectoryRecursively(in name).Value;
|
2018-07-18 15:05:17 -04:00
|
|
|
}
|
|
|
|
|
2023-04-14 19:00:34 -04:00
|
|
|
[CommandCmif(14)]
|
2019-02-13 19:44:39 -05:00
|
|
|
// GetFileTimeStampRaw(buffer<bytes<0x301>, 0x19, 0x301> path) -> bytes<0x20> timestamp
|
2019-07-14 15:04:38 -04:00
|
|
|
public ResultCode GetFileTimeStampRaw(ServiceCtx context)
|
2019-02-13 19:44:39 -05:00
|
|
|
{
|
2021-08-12 17:56:24 -04:00
|
|
|
ref readonly Path name = ref FileSystemProxyHelper.GetSfPath(context);
|
2019-02-13 19:44:39 -05:00
|
|
|
|
2021-12-23 11:55:50 -05:00
|
|
|
Result result = _fileSystem.Get.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, in name);
|
2019-02-13 19:44:39 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
context.ResponseData.Write(timestamp.Created);
|
|
|
|
context.ResponseData.Write(timestamp.Modified);
|
|
|
|
context.ResponseData.Write(timestamp.Accessed);
|
2022-10-04 19:12:54 -04:00
|
|
|
context.ResponseData.Write(1L); // Is valid?
|
2018-02-21 16:56:52 -05:00
|
|
|
|
2019-10-17 02:17:44 -04:00
|
|
|
return (ResultCode)result.Value;
|
2018-03-03 00:24:04 -05:00
|
|
|
}
|
2021-08-12 17:56:24 -04:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
if (isDisposing)
|
|
|
|
{
|
2021-12-23 11:55:50 -05:00
|
|
|
_fileSystem.Destroy();
|
2021-08-12 17:56:24 -04:00
|
|
|
}
|
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|