2019-07-10 10:20:01 -07:00
|
|
|
using LibHac;
|
2021-07-13 07:48:54 -07:00
|
|
|
using LibHac.Common;
|
2019-05-31 17:31:10 -07:00
|
|
|
using LibHac.Fs;
|
2021-07-13 07:48:54 -07:00
|
|
|
using LibHac.Fs.Fsa;
|
|
|
|
using static Ryujinx.HLE.Utilities.StringUtils;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2019-09-18 17:45:11 -07:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Fs.FileSystemProxy
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
class IFileSystem : IpcService
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
private LibHac.Fs.Fsa.IFileSystem _fileSystem;
|
2018-11-18 11:37:41 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
public IFileSystem(LibHac.Fs.Fsa.IFileSystem provider)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2019-07-10 10:20:01 -07:00
|
|
|
_fileSystem = provider;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
public LibHac.Fs.Fsa.IFileSystem GetBaseFileSystem()
|
2020-03-25 01:14:35 -07:00
|
|
|
{
|
|
|
|
return _fileSystem;
|
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(0)]
|
2019-05-31 17:31:10 -07:00
|
|
|
// CreateFile(u32 createOption, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode CreateFile(ServiceCtx context)
|
2018-02-20 03:03:04 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
CreateFileOptions createOption = (CreateFileOptions)context.RequestData.ReadInt32();
|
2019-05-31 17:31:10 -07:00
|
|
|
context.RequestData.BaseStream.Position += 4;
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2019-05-31 17:31:10 -07:00
|
|
|
long size = context.RequestData.ReadInt64();
|
2018-02-20 03:03:04 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.CreateFile(name, size, createOption).Value;
|
2018-02-20 03:03:04 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(1)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// DeleteFile(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode DeleteFile(ServiceCtx context)
|
2018-02-20 03:03:04 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.DeleteFile(name).Value;
|
2018-02-20 03:03:04 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(2)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode CreateDirectory(ServiceCtx context)
|
2018-02-20 03:03:04 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-20 03:03:04 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.CreateDirectory(name).Value;
|
2018-02-21 13:56:52 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(3)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// DeleteDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode DeleteDirectory(ServiceCtx context)
|
2018-02-21 13:56:52 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2019-05-31 17:31:10 -07:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.DeleteDirectory(name).Value;
|
2018-02-20 03:03:04 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(4)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// DeleteDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode DeleteDirectoryRecursively(ServiceCtx context)
|
2018-02-20 03:03:04 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-20 03:03:04 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.DeleteDirectoryRecursively(name).Value;
|
2018-02-20 03:03:04 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(5)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// RenameFile(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode RenameFile(ServiceCtx context)
|
2018-02-20 03:03:04 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span oldName = ReadUtf8Span(context, 0);
|
|
|
|
U8Span newName = ReadUtf8Span(context, 1);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.RenameFile(oldName, newName).Value;
|
2018-02-20 03:03:04 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(6)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// RenameDirectory(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode RenameDirectory(ServiceCtx context)
|
2018-02-20 03:03:04 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span oldName = ReadUtf8Span(context, 0);
|
|
|
|
U8Span newName = ReadUtf8Span(context, 1);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.RenameDirectory(oldName, newName).Value;
|
2018-02-20 03:03:04 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(7)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// GetEntryType(buffer<bytes<0x301>, 0x19, 0x301> path) -> nn::fssrv::sf::DirectoryEntryType
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode GetEntryType(ServiceCtx context)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
Result result = _fileSystem.GetEntryType(out DirectoryEntryType entryType, name);
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
context.ResponseData.Write((int)entryType);
|
|
|
|
|
|
|
|
return (ResultCode)result.Value;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(8)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// OpenFile(u32 mode, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IFile> file
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode OpenFile(ServiceCtx context)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
OpenMode mode = (OpenMode)context.RequestData.ReadInt32();
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
Result result = _fileSystem.OpenFile(out LibHac.Fs.Fsa.IFile file, name, mode);
|
2018-02-23 16:59:38 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
if (result.IsSuccess())
|
|
|
|
{
|
2019-07-10 10:20:01 -07:00
|
|
|
IFile fileInterface = new IFile(file);
|
2018-02-23 16:59:38 -08:00
|
|
|
|
2019-07-10 10:20:01 -07:00
|
|
|
MakeObject(context, fileInterface);
|
2019-05-31 17:31:10 -07:00
|
|
|
}
|
2018-11-18 11:37:41 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
return (ResultCode)result.Value;
|
2018-02-20 03:03:04 -08:00
|
|
|
}
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(9)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// OpenDirectory(u32 filter_flags, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IDirectory> directory
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode OpenDirectory(ServiceCtx context)
|
2018-02-20 03:03:04 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
OpenDirectoryMode mode = (OpenDirectoryMode)context.RequestData.ReadInt32();
|
2018-02-20 03:03:04 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-20 03:03:04 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
Result result = _fileSystem.OpenDirectory(out LibHac.Fs.Fsa.IDirectory dir, name, mode);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
if (result.IsSuccess())
|
|
|
|
{
|
2019-07-10 10:20:01 -07:00
|
|
|
IDirectory dirInterface = new IDirectory(dir);
|
2019-05-31 17:31:10 -07:00
|
|
|
|
2019-07-10 10:20:01 -07:00
|
|
|
MakeObject(context, dirInterface);
|
2019-05-31 17:31:10 -07:00
|
|
|
}
|
2018-11-18 11:37:41 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
return (ResultCode)result.Value;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(10)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// Commit()
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode Commit(ServiceCtx context)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.Commit().Value;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(11)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// GetFreeSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalFreeSpace
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode GetFreeSpaceSize(ServiceCtx context)
|
2018-02-21 13:56:52 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
Result result = _fileSystem.GetFreeSpaceSize(out long size, name);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
context.ResponseData.Write(size);
|
|
|
|
|
|
|
|
return (ResultCode)result.Value;
|
2018-02-21 13:56:52 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(12)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// GetTotalSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalSize
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode GetTotalSpaceSize(ServiceCtx context)
|
2018-02-21 13:56:52 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
Result result = _fileSystem.GetTotalSpaceSize(out long size, name);
|
2019-10-16 23:17:44 -07:00
|
|
|
|
|
|
|
context.ResponseData.Write(size);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
return (ResultCode)result.Value;
|
2018-02-21 13:56:52 -08:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(13)]
|
2018-11-18 11:37:41 -08:00
|
|
|
// CleanDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode CleanDirectoryRecursively(ServiceCtx context)
|
2018-07-18 12:05:17 -07:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2018-07-18 12:05:17 -07:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
return (ResultCode)_fileSystem.CleanDirectoryRecursively(name).Value;
|
2018-07-18 12:05:17 -07:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
[CommandHipc(14)]
|
2019-02-13 16:44:39 -08:00
|
|
|
// GetFileTimeStampRaw(buffer<bytes<0x301>, 0x19, 0x301> path) -> bytes<0x20> timestamp
|
2019-07-14 12:04:38 -07:00
|
|
|
public ResultCode GetFileTimeStampRaw(ServiceCtx context)
|
2019-02-13 16:44:39 -08:00
|
|
|
{
|
2021-07-13 07:48:54 -07:00
|
|
|
U8Span name = ReadUtf8Span(context);
|
2019-02-13 16:44:39 -08:00
|
|
|
|
2021-07-13 07:48:54 -07:00
|
|
|
Result result = _fileSystem.GetFileTimeStampRaw(out FileTimeStampRaw timestamp, name);
|
2019-02-13 16:44:39 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
context.ResponseData.Write(timestamp.Created);
|
|
|
|
context.ResponseData.Write(timestamp.Modified);
|
|
|
|
context.ResponseData.Write(timestamp.Accessed);
|
2019-02-13 16:44:39 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
byte[] data = new byte[8];
|
2019-02-13 16:44:39 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
// is valid?
|
|
|
|
data[0] = 1;
|
2019-02-13 16:44:39 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
context.ResponseData.Write(data);
|
2018-02-21 13:56:52 -08:00
|
|
|
|
2019-10-16 23:17:44 -07:00
|
|
|
return (ResultCode)result.Value;
|
2018-03-02 21:24:04 -08:00
|
|
|
}
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
}
|