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