2018-11-18 20:37:41 +01:00
|
|
|
using Ryujinx.HLE.FileSystem;
|
2018-08-17 01:47:36 +02:00
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-02-21 22:56:52 +01:00
|
|
|
using System;
|
2018-02-10 01:14:55 +01:00
|
|
|
using System.Collections.Generic;
|
2018-02-05 00:08:20 +01:00
|
|
|
using System.IO;
|
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
using static Ryujinx.HLE.HOS.ErrorCode;
|
2018-11-18 20:37:41 +01:00
|
|
|
using static Ryujinx.HLE.Utilities.StringUtils;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-08-17 01:47:36 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.FspSrv
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-03-19 19:58:46 +01:00
|
|
|
class IFileSystem : IpcService
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
private Dictionary<int, ServiceProcessRequest> _commands;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
|
2018-02-10 01:14:55 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private HashSet<string> _openPaths;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private string _path;
|
2018-02-10 01:14:55 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private IFileSystemProvider _provider;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public IFileSystem(string path, IFileSystemProvider provider)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_commands = new Dictionary<int, ServiceProcessRequest>
|
2018-02-10 01:14:55 +01:00
|
|
|
{
|
2018-04-24 20:57:39 +02:00
|
|
|
{ 0, CreateFile },
|
|
|
|
{ 1, DeleteFile },
|
|
|
|
{ 2, CreateDirectory },
|
|
|
|
{ 3, DeleteDirectory },
|
|
|
|
{ 4, DeleteDirectoryRecursively },
|
|
|
|
{ 5, RenameFile },
|
|
|
|
{ 6, RenameDirectory },
|
|
|
|
{ 7, GetEntryType },
|
|
|
|
{ 8, OpenFile },
|
|
|
|
{ 9, OpenDirectory },
|
2018-02-21 22:56:52 +01:00
|
|
|
{ 10, Commit },
|
|
|
|
{ 11, GetFreeSpaceSize },
|
|
|
|
{ 12, GetTotalSpaceSize },
|
2019-02-14 01:44:39 +01:00
|
|
|
{ 13, CleanDirectoryRecursively },
|
|
|
|
{ 14, GetFileTimeStampRaw }
|
2018-02-10 01:14:55 +01:00
|
|
|
};
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_openPaths = new HashSet<string>();
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_path = path;
|
|
|
|
_provider = provider;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// CreateFile(u32 mode, u64 size, buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 12:16:24 +01:00
|
|
|
public long CreateFile(ServiceCtx context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
long mode = context.RequestData.ReadInt64();
|
|
|
|
int size = context.RequestData.ReadInt32();
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string fileName = _provider.GetFullPath(name);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (fileName == null)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_provider.FileExists(fileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(fileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return _provider.CreateFile(fileName, size);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// DeleteFile(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 12:16:24 +01:00
|
|
|
public long DeleteFile(ServiceCtx context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string fileName = _provider.GetFullPath(name);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!_provider.FileExists(fileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(fileName))
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return _provider.DeleteFile(fileName);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// CreateDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 12:16:24 +01:00
|
|
|
public long CreateDirectory(ServiceCtx context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string dirName = _provider.GetFullPath(name);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (dirName == null)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_provider.DirectoryExists(dirName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
|
|
|
}
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(dirName))
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_provider.CreateDirectory(dirName);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// DeleteDirectory(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 12:16:24 +01:00
|
|
|
public long DeleteDirectory(ServiceCtx context)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
return DeleteDirectory(context, false);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// DeleteDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 12:16:24 +01:00
|
|
|
public long DeleteDirectoryRecursively(ServiceCtx context)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
return DeleteDirectory(context, true);
|
2018-02-21 22:56:52 +01:00
|
|
|
}
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private long DeleteDirectory(ServiceCtx context, bool recursive)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string dirName = _provider.GetFullPath(name);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!Directory.Exists(dirName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(dirName))
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_provider.DeleteDirectory(dirName, recursive);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
|
|
|
return 0;
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// RenameFile(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
2018-12-06 12:16:24 +01:00
|
|
|
public long RenameFile(ServiceCtx context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string oldName = ReadUtf8String(context, 0);
|
|
|
|
string newName = ReadUtf8String(context, 1);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string oldFileName = _provider.GetFullPath(oldName);
|
|
|
|
string newFileName = _provider.GetFullPath(newName);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_provider.FileExists(oldFileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_provider.FileExists(newFileName))
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(oldFileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return _provider.RenameFile(oldFileName, newFileName);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// RenameDirectory(buffer<bytes<0x301>, 0x19, 0x301> oldPath, buffer<bytes<0x301>, 0x19, 0x301> newPath)
|
2018-12-06 12:16:24 +01:00
|
|
|
public long RenameDirectory(ServiceCtx context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string oldName = ReadUtf8String(context, 0);
|
|
|
|
string newName = ReadUtf8String(context, 1);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string oldDirName = _provider.GetFullPath(oldName);
|
|
|
|
string newDirName = _provider.GetFullPath(newName);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!_provider.DirectoryExists(oldDirName))
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!_provider.DirectoryExists(newDirName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(oldDirName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return _provider.RenameDirectory(oldDirName, newDirName);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// GetEntryType(buffer<bytes<0x301>, 0x19, 0x301> path) -> nn::fssrv::sf::DirectoryEntryType
|
2018-12-06 12:16:24 +01:00
|
|
|
public long GetEntryType(ServiceCtx context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string fileName = _provider.GetFullPath(name);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_provider.FileExists(fileName))
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
context.ResponseData.Write(1);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (_provider.DirectoryExists(fileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
context.ResponseData.Write(0);
|
2018-02-21 22:56:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
context.ResponseData.Write(0);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenFile(u32 mode, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IFile> file
|
2018-12-06 12:16:24 +01:00
|
|
|
public long OpenFile(ServiceCtx context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
int filterFlags = context.RequestData.ReadInt32();
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string fileName = _provider.GetFullPath(name);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!_provider.FileExists(fileName))
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(fileName))
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
long error = _provider.OpenFile(fileName, out IFile fileInterface);
|
2018-02-24 01:59:38 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (error == 0)
|
2018-02-24 01:59:38 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
fileInterface.Disposed += RemoveFileInUse;
|
2018-02-24 01:59:38 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
lock (_openPaths)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_openPaths.Add(fileName);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
MakeObject(context, fileInterface);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return error;
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// OpenDirectory(u32 filter_flags, buffer<bytes<0x301>, 0x19, 0x301> path) -> object<nn::fssrv::sf::IDirectory> directory
|
2018-12-06 12:16:24 +01:00
|
|
|
public long OpenDirectory(ServiceCtx context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
int filterFlags = context.RequestData.ReadInt32();
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string dirName = _provider.GetFullPath(name);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!_provider.DirectoryExists(dirName))
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-02-21 22:56:52 +01:00
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
2018-02-20 12:03:04 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(dirName))
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
long error = _provider.OpenDirectory(dirName, filterFlags, out IDirectory dirInterface);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (error == 0)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
dirInterface.Disposed += RemoveDirectoryInUse;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
lock (_openPaths)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_openPaths.Add(dirName);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
MakeObject(context, dirInterface);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return error;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// Commit()
|
2018-12-06 12:16:24 +01:00
|
|
|
public long Commit(ServiceCtx context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// GetFreeSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalFreeSpace
|
2018-12-06 12:16:24 +01:00
|
|
|
public long GetFreeSpaceSize(ServiceCtx context)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
context.ResponseData.Write(_provider.GetFreeSpace(context));
|
2018-02-21 22:56:52 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// GetTotalSpaceSize(buffer<bytes<0x301>, 0x19, 0x301> path) -> u64 totalSize
|
2018-12-06 12:16:24 +01:00
|
|
|
public long GetTotalSpaceSize(ServiceCtx context)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
context.ResponseData.Write(_provider.GetFreeSpace(context));
|
2018-02-21 22:56:52 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// CleanDirectoryRecursively(buffer<bytes<0x301>, 0x19, 0x301> path)
|
2018-12-06 12:16:24 +01:00
|
|
|
public long CleanDirectoryRecursively(ServiceCtx context)
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
string name = ReadUtf8String(context);
|
2018-07-18 21:05:17 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
string dirName = _provider.GetFullPath(name);
|
2018-07-18 21:05:17 +02:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (!_provider.DirectoryExists(dirName))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (IsPathAlreadyInUse(dirName))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
foreach (DirectoryEntry entry in _provider.GetEntries(dirName))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (_provider.DirectoryExists(entry.Path))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_provider.DeleteDirectory(entry.Path, true);
|
2018-07-18 21:05:17 +02:00
|
|
|
}
|
2018-12-06 12:16:24 +01:00
|
|
|
else if (_provider.FileExists(entry.Path))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
_provider.DeleteFile(entry.Path);
|
2018-07-18 21:05:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-14 01:44:39 +01:00
|
|
|
// GetFileTimeStampRaw(buffer<bytes<0x301>, 0x19, 0x301> path) -> bytes<0x20> timestamp
|
|
|
|
public long GetFileTimeStampRaw(ServiceCtx context)
|
|
|
|
{
|
|
|
|
string name = ReadUtf8String(context);
|
|
|
|
|
|
|
|
string path = _provider.GetFullPath(name);
|
|
|
|
|
|
|
|
if (_provider.FileExists(path) || _provider.DirectoryExists(path))
|
|
|
|
{
|
|
|
|
FileTimestamp timestamp = _provider.GetFileTimeStampRaw(path);
|
|
|
|
|
|
|
|
context.ResponseData.Write(new DateTimeOffset(timestamp.CreationDateTime).ToUnixTimeSeconds());
|
|
|
|
context.ResponseData.Write(new DateTimeOffset(timestamp.ModifiedDateTime).ToUnixTimeSeconds());
|
|
|
|
context.ResponseData.Write(new DateTimeOffset(timestamp.LastAccessDateTime).ToUnixTimeSeconds());
|
|
|
|
|
|
|
|
byte[] data = new byte[8];
|
|
|
|
|
|
|
|
// is valid?
|
|
|
|
data[0] = 1;
|
|
|
|
|
|
|
|
context.ResponseData.Write(data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
private bool IsPathAlreadyInUse(string path)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
lock (_openPaths)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
return _openPaths.Contains(path);
|
2018-02-21 22:56:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RemoveFileInUse(object sender, EventArgs e)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
IFile fileInterface = (IFile)sender;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
lock (_openPaths)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
fileInterface.Disposed -= RemoveFileInUse;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_openPaths.Remove(fileInterface.HostPath);
|
2018-02-21 22:56:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RemoveDirectoryInUse(object sender, EventArgs e)
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
IDirectory dirInterface = (IDirectory)sender;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
lock (_openPaths)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
dirInterface.Disposed -= RemoveDirectoryInUse;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
_openPaths.Remove(dirInterface.DirectoryPath);
|
2018-03-03 06:24:04 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|