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-05 01:52:39 +01:00
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-10 01:14:55 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private HashSet<string> OpenPaths;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private string Path;
|
2018-02-10 01:14:55 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private IFileSystemProvider Provider;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public IFileSystem(string Path, IFileSystemProvider Provider)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
m_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 },
|
2018-12-05 01:52:39 +01:00
|
|
|
{ 13, CleanDirectoryRecursively },
|
2018-02-21 22:56:52 +01:00
|
|
|
//{ 14, GetFileTimeStampRaw }
|
2018-02-10 01:14:55 +01:00
|
|
|
};
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
OpenPaths = new HashSet<string>();
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
this.Path = Path;
|
|
|
|
this.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-05 01:52:39 +01:00
|
|
|
public long CreateFile(ServiceCtx Context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
long Mode = Context.RequestData.ReadInt64();
|
|
|
|
int Size = Context.RequestData.ReadInt32();
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string FileName = Provider.GetFullPath(Name);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (FileName == null)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Provider.FileExists(FileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsPathAlreadyInUse(FileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long DeleteFile(ServiceCtx Context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string FileName = Provider.GetFullPath(Name);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (!Provider.FileExists(FileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long CreateDirectory(ServiceCtx Context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string DirName = Provider.GetFullPath(Name);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long DeleteDirectory(ServiceCtx Context)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long DeleteDirectoryRecursively(ServiceCtx Context)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return DeleteDirectory(Context, true);
|
2018-02-21 22:56:52 +01:00
|
|
|
}
|
2018-11-18 20:37:41 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private long DeleteDirectory(ServiceCtx Context, bool Recursive)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string DirName = Provider.GetFullPath(Name);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (!Directory.Exists(DirName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long RenameFile(ServiceCtx Context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string OldName = ReadUtf8String(Context, 0);
|
|
|
|
string NewName = ReadUtf8String(Context, 1);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string OldFileName = Provider.GetFullPath(OldName);
|
|
|
|
string NewFileName = Provider.GetFullPath(NewName);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Provider.FileExists(OldFileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
if (IsPathAlreadyInUse(OldFileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long RenameDirectory(ServiceCtx Context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string OldName = ReadUtf8String(Context, 0);
|
|
|
|
string NewName = ReadUtf8String(Context, 1);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string OldDirName = Provider.GetFullPath(OldName);
|
|
|
|
string NewDirName = Provider.GetFullPath(NewName);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
if (!Provider.DirectoryExists(NewDirName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsPathAlreadyInUse(OldDirName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long GetEntryType(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string FileName = Provider.GetFullPath(Name);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Provider.FileExists(FileName))
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Context.ResponseData.Write(1);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
2018-12-05 01:52:39 +01:00
|
|
|
else if (Provider.DirectoryExists(FileName))
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Context.ResponseData.Write(0);
|
2018-02-21 22:56:52 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long OpenFile(ServiceCtx Context)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
int FilterFlags = Context.RequestData.ReadInt32();
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string FileName = Provider.GetFullPath(Name);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
long Error = Provider.OpenFile(FileName, out IFile FileInterface);
|
2018-02-24 01:59:38 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Error == 0)
|
2018-02-24 01:59:38 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
FileInterface.Disposed += RemoveFileInUse;
|
2018-02-24 01:59:38 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
lock (OpenPaths)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
OpenPaths.Add(FileName);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, FileInterface);
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long OpenDirectory(ServiceCtx Context)
|
2018-02-20 12:03:04 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
int FilterFlags = Context.RequestData.ReadInt32();
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string DirName = Provider.GetFullPath(Name);
|
2018-02-20 12:03:04 +01:00
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
long Error = Provider.OpenDirectory(DirName, FilterFlags, out IDirectory DirInterface);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Error == 0)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
DirInterface.Disposed += RemoveDirectoryInUse;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
lock (OpenPaths)
|
2018-11-18 20:37:41 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
OpenPaths.Add(DirName);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
MakeObject(Context, DirInterface);
|
2018-11-18 20:37:41 +01:00
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
return Error;
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-11-18 20:37:41 +01:00
|
|
|
// Commit()
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long GetFreeSpaceSize(ServiceCtx Context)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long GetTotalSpaceSize(ServiceCtx Context)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +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-05 01:52:39 +01:00
|
|
|
public long CleanDirectoryRecursively(ServiceCtx Context)
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
string Name = ReadUtf8String(Context);
|
2018-07-18 21:05:17 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
string DirName = Provider.GetFullPath(Name);
|
2018-07-18 21:05:17 +02:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (!Provider.DirectoryExists(DirName))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
if (IsPathAlreadyInUse(DirName))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
|
|
|
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
foreach (DirectoryEntry Entry in Provider.GetEntries(DirName))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
if (Provider.DirectoryExists(Entry.Path))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Provider.DeleteDirectory(Entry.Path, true);
|
2018-07-18 21:05:17 +02:00
|
|
|
}
|
2018-12-05 01:52:39 +01:00
|
|
|
else if (Provider.FileExists(Entry.Path))
|
2018-07-18 21:05:17 +02:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
Provider.DeleteFile(Entry.Path);
|
2018-07-18 21:05:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
private bool IsPathAlreadyInUse(string Path)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
lock (OpenPaths)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
return OpenPaths.Contains(Path);
|
2018-02-21 22:56:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RemoveFileInUse(object sender, EventArgs e)
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
IFile FileInterface = (IFile)sender;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
lock (OpenPaths)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
FileInterface.Disposed -= RemoveFileInUse;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
OpenPaths.Remove(FileInterface.HostPath);
|
2018-02-21 22:56:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void RemoveDirectoryInUse(object sender, EventArgs e)
|
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
IDirectory DirInterface = (IDirectory)sender;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
lock (OpenPaths)
|
2018-02-21 22:56:52 +01:00
|
|
|
{
|
2018-12-05 01:52:39 +01:00
|
|
|
DirInterface.Disposed -= RemoveDirectoryInUse;
|
2018-02-21 22:56:52 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
OpenPaths.Remove(DirInterface.DirectoryPath);
|
2018-03-03 06:24:04 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|