2019-07-10 17:20:01 +00:00
|
|
|
using LibHac;
|
2019-06-01 00:31:10 +00:00
|
|
|
using LibHac.Fs;
|
2019-07-10 17:20:01 +00:00
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
using static Ryujinx.HLE.HOS.ErrorCode;
|
2018-11-18 19:37:41 +00:00
|
|
|
using static Ryujinx.HLE.Utilities.StringUtils;
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-08-16 23:47:36 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.FspSrv
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-03-19 18:58:46 +00:00
|
|
|
class IFileSystem : IpcService
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
private LibHac.Fs.IFileSystem _fileSystem;
|
2018-11-18 19:37:41 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
public IFileSystem(LibHac.Fs.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
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(0)]
|
2019-06-01 00:31:10 +00:00
|
|
|
// CreateFile(u32 createOption, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 11:16:24 +00:00
|
|
|
public long CreateFile(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-06-06 22:01:44 +00:00
|
|
|
CreateFileOptions createOption = (CreateFileOptions)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
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_fileSystem.CreateFile(name, size, createOption);
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(1)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// DeleteFile(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 11:16:24 +00:00
|
|
|
public long DeleteFile(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_fileSystem.DeleteFile(name);
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(2)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 11:16:24 +00:00
|
|
|
public long CreateDirectory(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-20 11:03:04 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_fileSystem.CreateDirectory(name);
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2018-02-21 21:56:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(3)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// DeleteDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 11:16:24 +00:00
|
|
|
public long DeleteDirectory(ServiceCtx context)
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2019-06-01 00:31:10 +00:00
|
|
|
string name = ReadUtf8String(context);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_fileSystem.DeleteDirectory(name);
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(4)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// DeleteDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 11:16:24 +00:00
|
|
|
public long DeleteDirectoryRecursively(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-20 11:03:04 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_fileSystem.DeleteDirectoryRecursively(name);
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2018-02-21 21:56:52 +00:00
|
|
|
|
|
|
|
return 0;
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(5)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// RenameFile(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
2018-12-06 11:16:24 +00:00
|
|
|
public long RenameFile(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string oldName = ReadUtf8String(context, 0);
|
|
|
|
string newName = ReadUtf8String(context, 1);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_fileSystem.RenameFile(oldName, newName);
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(6)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// RenameDirectory(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
2018-12-06 11:16:24 +00:00
|
|
|
public long RenameDirectory(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string oldName = ReadUtf8String(context, 0);
|
|
|
|
string newName = ReadUtf8String(context, 1);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_fileSystem.RenameDirectory(oldName, newName);
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(7)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// GetEntryType(buffer<bytes<0x301>, 0x19, 0x301> path) -> nn::fssrv::sf::DirectoryEntryType
|
2018-12-06 11:16:24 +00:00
|
|
|
public long GetEntryType(ServiceCtx context)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
DirectoryEntryType entryType = _fileSystem.GetEntryType(name);
|
2019-06-01 00:31:10 +00:00
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
if (entryType == DirectoryEntryType.Directory || entryType == DirectoryEntryType.File)
|
|
|
|
{
|
|
|
|
context.ResponseData.Write((int)entryType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
2018-02-21 21:56:52 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2018-02-21 21:56:52 +00:00
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(8)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// OpenFile(u32 mode, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IFile> file
|
2018-12-06 11:16:24 +00:00
|
|
|
public long OpenFile(ServiceCtx context)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2019-06-06 22:01:44 +00:00
|
|
|
OpenMode mode = (OpenMode)context.RequestData.ReadInt32();
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
LibHac.Fs.IFile file = _fileSystem.OpenFile(name, mode);
|
2018-02-24 00:59:38 +00:00
|
|
|
|
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
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2018-11-18 19:37:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
return 0;
|
2018-02-20 11:03:04 +00:00
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(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
|
2018-12-06 11:16:24 +00:00
|
|
|
public long OpenDirectory(ServiceCtx context)
|
2018-02-20 11:03:04 +00:00
|
|
|
{
|
2019-06-06 22:01:44 +00:00
|
|
|
OpenDirectoryMode mode = (OpenDirectoryMode)context.RequestData.ReadInt32();
|
2018-02-20 11:03:04 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-20 11:03:04 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
LibHac.Fs.IDirectory dir = _fileSystem.OpenDirectory(name, mode);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
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
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2018-11-18 19:37:41 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
return 0;
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(10)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// Commit()
|
2018-12-06 11:16:24 +00:00
|
|
|
public long Commit(ServiceCtx context)
|
2018-02-04 23:08:20 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_fileSystem.Commit();
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
|
|
|
return ex.ResultValue.Value;
|
|
|
|
}
|
2019-06-01 00:31:10 +00:00
|
|
|
|
2018-02-04 23:08:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(11)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// GetFreeSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalFreeSpace
|
2018-12-06 11:16:24 +00:00
|
|
|
public long GetFreeSpaceSize(ServiceCtx context)
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(_fileSystem.GetFreeSpaceSize(name));
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
|
|
|
return ex.ResultValue.Value;
|
|
|
|
}
|
2018-02-21 21:56:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(12)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// GetTotalSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalSize
|
2018-12-06 11:16:24 +00:00
|
|
|
public long GetTotalSpaceSize(ServiceCtx context)
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-21 21:56:52 +00:00
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
context.ResponseData.Write(_fileSystem.GetTotalSpaceSize(name));
|
|
|
|
}
|
|
|
|
catch (HorizonResultException ex)
|
|
|
|
{
|
|
|
|
return ex.ResultValue.Value;
|
|
|
|
}
|
2018-02-21 21:56:52 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(13)]
|
2018-11-18 19:37:41 +00:00
|
|
|
// CleanDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 11:16:24 +00:00
|
|
|
public long CleanDirectoryRecursively(ServiceCtx context)
|
2018-07-18 19:05:17 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
string name = ReadUtf8String(context);
|
2018-07-18 19:05:17 +00:00
|
|
|
|
2019-06-01 00:31:10 +00:00
|
|
|
try
|
2018-07-18 19:05:17 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
_fileSystem.CleanDirectoryRecursively(name);
|
2019-06-01 00:31:10 +00:00
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2019-06-01 00:31:10 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2018-07-18 19:05:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(14)]
|
2019-02-14 00:44:39 +00:00
|
|
|
// GetFileTimeStampRaw(buffer<bytes<0x301>, 0x19, 0x301> path) -> bytes<0x20> timestamp
|
|
|
|
public long GetFileTimeStampRaw(ServiceCtx context)
|
|
|
|
{
|
|
|
|
string name = ReadUtf8String(context);
|
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
try
|
2019-02-14 00:44:39 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
FileTimeStampRaw timestamp = _fileSystem.GetFileTimeStampRaw(name);
|
2019-02-14 00:44:39 +00:00
|
|
|
|
2019-06-01 00:31:10 +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
|
|
|
|
|
|
|
byte[] data = new byte[8];
|
|
|
|
|
|
|
|
// is valid?
|
|
|
|
data[0] = 1;
|
|
|
|
|
|
|
|
context.ResponseData.Write(data);
|
|
|
|
}
|
2019-07-10 17:20:01 +00:00
|
|
|
catch (HorizonResultException ex)
|
2018-02-21 21:56:52 +00:00
|
|
|
{
|
2019-07-10 17:20:01 +00:00
|
|
|
return ex.ResultValue.Value;
|
2018-02-21 21:56:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-10 17:20:01 +00:00
|
|
|
return 0;
|
2018-03-03 05:24:04 +00:00
|
|
|
}
|
2018-02-04 23:08:20 +00:00
|
|
|
}
|
|
|
|
}
|