Implement many objects, improve logging. (#42)
* Implement many objects, improve logging. Change and rename folders of Services Add Logging of IpcMessage. Add "lm" Log Service. Parse Errors of SetTerminateResult Add Svc Calls. Add many object implementations. * Corrections Forgotten Debug Conf * Corrections 2 * Corrections 3 * Corrections 4
This commit is contained in:
9
Ryujinx.Core/OsHle/Services/FspSrv/FsErr.cs
Normal file
9
Ryujinx.Core/OsHle/Services/FspSrv/FsErr.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.FspSrv
|
||||
{
|
||||
static class FsErr
|
||||
{
|
||||
public const int PathDoesNotExist = 1;
|
||||
public const int PathAlreadyExists = 2;
|
||||
public const int PathAlreadyInUse = 7;
|
||||
}
|
||||
}
|
117
Ryujinx.Core/OsHle/Services/FspSrv/IDirectory.cs
Normal file
117
Ryujinx.Core/OsHle/Services/FspSrv/IDirectory.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.FspSrv
|
||||
{
|
||||
class IDirectory : IIpcService, IDisposable
|
||||
{
|
||||
private const int DirectoryEntrySize = 0x310;
|
||||
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private List<string> DirectoryEntries;
|
||||
|
||||
private int CurrentItemIndex;
|
||||
|
||||
public event EventHandler<EventArgs> Disposed;
|
||||
|
||||
public string HostPath { get; private set; }
|
||||
|
||||
public IDirectory(string HostPath, int Flags)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, Read },
|
||||
{ 1, GetEntryCount }
|
||||
};
|
||||
|
||||
this.HostPath = HostPath;
|
||||
|
||||
DirectoryEntries = new List<string>();
|
||||
|
||||
if ((Flags & 1) != 0)
|
||||
{
|
||||
DirectoryEntries.AddRange(Directory.GetDirectories(HostPath));
|
||||
}
|
||||
|
||||
if ((Flags & 2) != 0)
|
||||
{
|
||||
DirectoryEntries.AddRange(Directory.GetFiles(HostPath));
|
||||
}
|
||||
|
||||
CurrentItemIndex = 0;
|
||||
}
|
||||
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
long BufferPosition = Context.Request.ReceiveBuff[0].Position;
|
||||
long BufferLen = Context.Request.ReceiveBuff[0].Size;
|
||||
|
||||
int MaxReadCount = (int)(BufferLen / DirectoryEntrySize);
|
||||
|
||||
int Count = Math.Min(DirectoryEntries.Count - CurrentItemIndex, MaxReadCount);
|
||||
|
||||
for (int Index = 0; Index < Count; Index++)
|
||||
{
|
||||
long Position = BufferPosition + Index * DirectoryEntrySize;
|
||||
|
||||
WriteDirectoryEntry(Context, Position, DirectoryEntries[CurrentItemIndex++]);
|
||||
}
|
||||
|
||||
Context.ResponseData.Write((long)Count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void WriteDirectoryEntry(ServiceCtx Context, long Position, string FullPath)
|
||||
{
|
||||
for (int Offset = 0; Offset < 0x300; Offset += 8)
|
||||
{
|
||||
Context.Memory.WriteInt64(Position + Offset, 0);
|
||||
}
|
||||
|
||||
byte[] NameBuffer = Encoding.UTF8.GetBytes(Path.GetFileName(FullPath));
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, Position, NameBuffer);
|
||||
|
||||
int Type = 0;
|
||||
long Size = 0;
|
||||
|
||||
if (File.Exists(FullPath))
|
||||
{
|
||||
Type = 1;
|
||||
Size = new FileInfo(FullPath).Length;
|
||||
}
|
||||
|
||||
Context.Memory.WriteInt32(Position + 0x300, 0); //Padding?
|
||||
Context.Memory.WriteInt32(Position + 0x304, Type);
|
||||
Context.Memory.WriteInt64(Position + 0x308, Size);
|
||||
}
|
||||
|
||||
public long GetEntryCount(ServiceCtx Context)
|
||||
{
|
||||
Context.ResponseData.Write((long)DirectoryEntries.Count);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Disposed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
111
Ryujinx.Core/OsHle/Services/FspSrv/IFile.cs
Normal file
111
Ryujinx.Core/OsHle/Services/FspSrv/IFile.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.FspSrv
|
||||
{
|
||||
class IFile : IIpcService, IDisposable
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private Stream BaseStream;
|
||||
|
||||
public event EventHandler<EventArgs> Disposed;
|
||||
|
||||
public string HostPath { get; private set; }
|
||||
|
||||
public IFile(Stream BaseStream, string HostPath)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, Read },
|
||||
{ 1, Write },
|
||||
{ 2, Flush },
|
||||
{ 3, SetSize },
|
||||
{ 4, GetSize }
|
||||
};
|
||||
|
||||
this.BaseStream = BaseStream;
|
||||
this.HostPath = HostPath;
|
||||
}
|
||||
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.ReceiveBuff[0].Position;
|
||||
|
||||
long Zero = Context.RequestData.ReadInt64();
|
||||
long Offset = Context.RequestData.ReadInt64();
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
|
||||
byte[] Data = new byte[Size];
|
||||
|
||||
BaseStream.Seek(Offset, SeekOrigin.Begin);
|
||||
|
||||
int ReadSize = BaseStream.Read(Data, 0, (int)Size);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, Position, Data);
|
||||
|
||||
Context.ResponseData.Write((long)ReadSize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long Write(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.SendBuff[0].Position;
|
||||
|
||||
long Zero = Context.RequestData.ReadInt64();
|
||||
long Offset = Context.RequestData.ReadInt64();
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
|
||||
byte[] Data = AMemoryHelper.ReadBytes(Context.Memory, Position, (int)Size);
|
||||
|
||||
BaseStream.Seek(Offset, SeekOrigin.Begin);
|
||||
BaseStream.Write(Data, 0, (int)Size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long Flush(ServiceCtx Context)
|
||||
{
|
||||
BaseStream.Flush();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long SetSize(ServiceCtx Context)
|
||||
{
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
|
||||
BaseStream.SetLength(Size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetSize(ServiceCtx Context)
|
||||
{
|
||||
Context.ResponseData.Write(BaseStream.Length);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && BaseStream != null)
|
||||
{
|
||||
BaseStream.Dispose();
|
||||
|
||||
Disposed?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
383
Ryujinx.Core/OsHle/Services/FspSrv/IFileSystem.cs
Normal file
383
Ryujinx.Core/OsHle/Services/FspSrv/IFileSystem.cs
Normal file
@@ -0,0 +1,383 @@
|
||||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using static Ryujinx.Core.OsHle.IpcServices.ErrorCode;
|
||||
using static Ryujinx.Core.OsHle.IpcServices.ObjHelper;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.FspSrv
|
||||
{
|
||||
class IFileSystem : IIpcService
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private HashSet<string> OpenPaths;
|
||||
|
||||
private string Path;
|
||||
|
||||
public IFileSystem(string Path)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, CreateFile },
|
||||
{ 1, DeleteFile },
|
||||
{ 2, CreateDirectory },
|
||||
{ 3, DeleteDirectory },
|
||||
{ 4, DeleteDirectoryRecursively },
|
||||
{ 5, RenameFile },
|
||||
{ 6, RenameDirectory },
|
||||
{ 7, GetEntryType },
|
||||
{ 8, OpenFile },
|
||||
{ 9, OpenDirectory },
|
||||
{ 10, Commit },
|
||||
{ 11, GetFreeSpaceSize },
|
||||
{ 12, GetTotalSpaceSize },
|
||||
//{ 13, CleanDirectoryRecursively },
|
||||
//{ 14, GetFileTimeStampRaw }
|
||||
};
|
||||
|
||||
OpenPaths = new HashSet<string>();
|
||||
|
||||
this.Path = Path;
|
||||
}
|
||||
|
||||
public long CreateFile(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
long Mode = Context.RequestData.ReadInt64();
|
||||
int Size = Context.RequestData.ReadInt32();
|
||||
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (FileName == null)
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
if (File.Exists(FileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
||||
}
|
||||
|
||||
if (IsPathAlreadyInUse(FileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
||||
}
|
||||
|
||||
using (FileStream NewFile = File.Create(FileName))
|
||||
{
|
||||
NewFile.SetLength(Size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long DeleteFile(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (!File.Exists(FileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
if (IsPathAlreadyInUse(FileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
||||
}
|
||||
|
||||
File.Delete(FileName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long CreateDirectory(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string DirName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (DirName == null)
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
if (Directory.Exists(DirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
||||
}
|
||||
|
||||
if (IsPathAlreadyInUse(DirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(DirName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long DeleteDirectory(ServiceCtx Context)
|
||||
{
|
||||
return DeleteDirectory(Context, false);
|
||||
}
|
||||
|
||||
public long DeleteDirectoryRecursively(ServiceCtx Context)
|
||||
{
|
||||
return DeleteDirectory(Context, true);
|
||||
}
|
||||
|
||||
private long DeleteDirectory(ServiceCtx Context, bool Recursive)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string DirName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (!Directory.Exists(DirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
if (IsPathAlreadyInUse(DirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
||||
}
|
||||
|
||||
Directory.Delete(DirName, Recursive);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long RenameFile(ServiceCtx Context)
|
||||
{
|
||||
long OldPosition = Context.Request.PtrBuff[0].Position;
|
||||
long NewPosition = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string OldName = AMemoryHelper.ReadAsciiString(Context.Memory, OldPosition);
|
||||
string NewName = AMemoryHelper.ReadAsciiString(Context.Memory, NewPosition);
|
||||
|
||||
string OldFileName = Context.Ns.VFs.GetFullPath(Path, OldName);
|
||||
string NewFileName = Context.Ns.VFs.GetFullPath(Path, NewName);
|
||||
|
||||
if (!File.Exists(OldFileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
if (File.Exists(NewFileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
||||
}
|
||||
|
||||
if (IsPathAlreadyInUse(OldFileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
||||
}
|
||||
|
||||
File.Move(OldFileName, NewFileName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long RenameDirectory(ServiceCtx Context)
|
||||
{
|
||||
long OldPosition = Context.Request.PtrBuff[0].Position;
|
||||
long NewPosition = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string OldName = AMemoryHelper.ReadAsciiString(Context.Memory, OldPosition);
|
||||
string NewName = AMemoryHelper.ReadAsciiString(Context.Memory, NewPosition);
|
||||
|
||||
string OldDirName = Context.Ns.VFs.GetFullPath(Path, OldName);
|
||||
string NewDirName = Context.Ns.VFs.GetFullPath(Path, NewName);
|
||||
|
||||
if (!Directory.Exists(OldDirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
if (Directory.Exists(NewDirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyExists);
|
||||
}
|
||||
|
||||
if (IsPathAlreadyInUse(OldDirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
||||
}
|
||||
|
||||
Directory.Move(OldDirName, NewDirName);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetEntryType(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (File.Exists(FileName))
|
||||
{
|
||||
Context.ResponseData.Write(1);
|
||||
}
|
||||
else if (Directory.Exists(FileName))
|
||||
{
|
||||
Context.ResponseData.Write(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Context.ResponseData.Write(0);
|
||||
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long OpenFile(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
int FilterFlags = Context.RequestData.ReadInt32();
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string FileName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (!File.Exists(FileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
if (IsPathAlreadyInUse(FileName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
||||
}
|
||||
|
||||
FileStream Stream = new FileStream(FileName, FileMode.Open);
|
||||
|
||||
IFile FileInterface = new IFile(Stream, FileName);
|
||||
|
||||
FileInterface.Disposed += RemoveFileInUse;
|
||||
|
||||
lock (OpenPaths)
|
||||
{
|
||||
OpenPaths.Add(FileName);
|
||||
}
|
||||
|
||||
MakeObject(Context, FileInterface);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long OpenDirectory(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
int FilterFlags = Context.RequestData.ReadInt32();
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
string DirName = Context.Ns.VFs.GetFullPath(Path, Name);
|
||||
|
||||
if (!Directory.Exists(DirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathDoesNotExist);
|
||||
}
|
||||
|
||||
if (IsPathAlreadyInUse(DirName))
|
||||
{
|
||||
return MakeError(ErrorModule.Fs, FsErr.PathAlreadyInUse);
|
||||
}
|
||||
|
||||
IDirectory DirInterface = new IDirectory(DirName, FilterFlags);
|
||||
|
||||
DirInterface.Disposed += RemoveDirectoryInUse;
|
||||
|
||||
lock (OpenPaths)
|
||||
{
|
||||
OpenPaths.Add(DirName);
|
||||
}
|
||||
|
||||
MakeObject(Context, DirInterface);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long Commit(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetFreeSpaceSize(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
Context.ResponseData.Write(Context.Ns.VFs.GetDrive().AvailableFreeSpace);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetTotalSpaceSize(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.PtrBuff[0].Position;
|
||||
|
||||
string Name = AMemoryHelper.ReadAsciiString(Context.Memory, Position);
|
||||
|
||||
Context.ResponseData.Write(Context.Ns.VFs.GetDrive().TotalSize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private bool IsPathAlreadyInUse(string Path)
|
||||
{
|
||||
lock (OpenPaths)
|
||||
{
|
||||
return OpenPaths.Contains(Path);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveFileInUse(object sender, EventArgs e)
|
||||
{
|
||||
IFile FileInterface = (IFile)sender;
|
||||
|
||||
lock (OpenPaths)
|
||||
{
|
||||
FileInterface.Disposed -= RemoveFileInUse;
|
||||
|
||||
OpenPaths.Remove(FileInterface.HostPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveDirectoryInUse(object sender, EventArgs e)
|
||||
{
|
||||
IDirectory DirInterface = (IDirectory)sender;
|
||||
|
||||
lock (OpenPaths)
|
||||
{
|
||||
DirInterface.Disposed -= RemoveDirectoryInUse;
|
||||
|
||||
OpenPaths.Remove(DirInterface.HostPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
52
Ryujinx.Core/OsHle/Services/FspSrv/IStorage.cs
Normal file
52
Ryujinx.Core/OsHle/Services/FspSrv/IStorage.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.FspSrv
|
||||
{
|
||||
class IStorage : IIpcService
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
private Stream BaseStream;
|
||||
|
||||
public IStorage(Stream BaseStream)
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, Read }
|
||||
};
|
||||
|
||||
this.BaseStream = BaseStream;
|
||||
}
|
||||
|
||||
public long Read(ServiceCtx Context)
|
||||
{
|
||||
long Offset = Context.RequestData.ReadInt64();
|
||||
long Size = Context.RequestData.ReadInt64();
|
||||
|
||||
if (Context.Request.ReceiveBuff.Count > 0)
|
||||
{
|
||||
IpcBuffDesc BuffDesc = Context.Request.ReceiveBuff[0];
|
||||
|
||||
//Use smaller length to avoid overflows.
|
||||
if (Size > BuffDesc.Size)
|
||||
{
|
||||
Size = BuffDesc.Size;
|
||||
}
|
||||
|
||||
byte[] Data = new byte[Size];
|
||||
|
||||
BaseStream.Seek(Offset, SeekOrigin.Begin);
|
||||
BaseStream.Read(Data, 0, Data.Length);
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, BuffDesc.Position, Data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
67
Ryujinx.Core/OsHle/Services/FspSrv/ServiceFspSrv.cs
Normal file
67
Ryujinx.Core/OsHle/Services/FspSrv/ServiceFspSrv.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using static Ryujinx.Core.OsHle.IpcServices.ObjHelper;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.FspSrv
|
||||
{
|
||||
class ServiceFspSrv : IIpcService
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public ServiceFspSrv()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 1, Initialize },
|
||||
{ 18, MountSdCard },
|
||||
{ 51, MountSaveData },
|
||||
{ 200, OpenDataStorageByCurrentProcess },
|
||||
{ 203, OpenRomStorage },
|
||||
{ 1005, GetGlobalAccessLogMode }
|
||||
};
|
||||
}
|
||||
|
||||
public long Initialize(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long MountSdCard(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IFileSystem(Context.Ns.VFs.GetSdCardPath()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long MountSaveData(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IFileSystem(Context.Ns.VFs.GetGameSavesPath()));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long OpenDataStorageByCurrentProcess(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IStorage(Context.Ns.VFs.RomFs));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long OpenRomStorage(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IStorage(Context.Ns.VFs.RomFs));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetGlobalAccessLogMode(ServiceCtx Context)
|
||||
{
|
||||
Context.ResponseData.Write(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user