mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Ensure UserDirectory and UserFileSystem are updated to 13.1.0
This commit is contained in:
parent
5670f2fd48
commit
ac378020dc
2 changed files with 44 additions and 32 deletions
|
@ -7,6 +7,10 @@ using static LibHac.Fs.Impl.AccessLogStrings;
|
||||||
|
|
||||||
namespace LibHac.Fs.Fsa;
|
namespace LibHac.Fs.Fsa;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains functions for interacting with opened directories.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public static class UserDirectory
|
public static class UserDirectory
|
||||||
{
|
{
|
||||||
|
@ -82,4 +86,4 @@ public static class UserDirectory
|
||||||
Get(handle).Dispose();
|
Get(handle).Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,11 +5,16 @@ using LibHac.Fs.Impl;
|
||||||
using LibHac.Fs.Shim;
|
using LibHac.Fs.Shim;
|
||||||
using LibHac.FsSrv.Sf;
|
using LibHac.FsSrv.Sf;
|
||||||
using LibHac.Os;
|
using LibHac.Os;
|
||||||
|
using LibHac.Util;
|
||||||
using static LibHac.Fs.Impl.AccessLogStrings;
|
using static LibHac.Fs.Impl.AccessLogStrings;
|
||||||
using IFileSystemSf = LibHac.FsSrv.Sf.IFileSystem;
|
using IFileSystemSf = LibHac.FsSrv.Sf.IFileSystem;
|
||||||
|
|
||||||
namespace LibHac.Fs.Fsa;
|
namespace LibHac.Fs.Fsa;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains functions for interacting with mounted file systems.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
|
||||||
[SkipLocalsInit]
|
[SkipLocalsInit]
|
||||||
public static class UserFileSystem
|
public static class UserFileSystem
|
||||||
{
|
{
|
||||||
|
@ -228,7 +233,7 @@ public static class UserFileSystem
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result RenameFile(this FileSystemClient fs, U8Span oldPath, U8Span newPath)
|
public static Result RenameFile(this FileSystemClient fs, U8Span currentPath, U8Span newPath)
|
||||||
{
|
{
|
||||||
Result rc;
|
Result rc;
|
||||||
U8Span currentSubPath, newSubPath;
|
U8Span currentSubPath, newSubPath;
|
||||||
|
@ -239,18 +244,18 @@ public static class UserFileSystem
|
||||||
if (fs.Impl.IsEnabledAccessLog())
|
if (fs.Impl.IsEnabledAccessLog())
|
||||||
{
|
{
|
||||||
Tick start = fs.Hos.Os.GetSystemTick();
|
Tick start = fs.Hos.Os.GetSystemTick();
|
||||||
rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, oldPath);
|
rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath);
|
||||||
Tick end = fs.Hos.Os.GetSystemTick();
|
Tick end = fs.Hos.Os.GetSystemTick();
|
||||||
|
|
||||||
var sb = new U8StringBuilder(logBuffer, true);
|
var sb = new U8StringBuilder(logBuffer, true);
|
||||||
sb.Append(LogPath).Append(oldPath).Append(LogNewPath).Append(newPath).Append((byte)'"');
|
sb.Append(LogPath).Append(currentPath).Append(LogNewPath).Append(newPath).Append((byte)'"');
|
||||||
logBuffer = sb.Buffer;
|
logBuffer = sb.Buffer;
|
||||||
|
|
||||||
fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer));
|
fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, oldPath);
|
rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath);
|
||||||
}
|
}
|
||||||
fs.Impl.AbortIfNeeded(rc);
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
@ -294,7 +299,7 @@ public static class UserFileSystem
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result RenameDirectory(this FileSystemClient fs, U8Span oldPath, U8Span newPath)
|
public static Result RenameDirectory(this FileSystemClient fs, U8Span currentPath, U8Span newPath)
|
||||||
{
|
{
|
||||||
Result rc;
|
Result rc;
|
||||||
U8Span currentSubPath, newSubPath;
|
U8Span currentSubPath, newSubPath;
|
||||||
|
@ -305,18 +310,18 @@ public static class UserFileSystem
|
||||||
if (fs.Impl.IsEnabledAccessLog())
|
if (fs.Impl.IsEnabledAccessLog())
|
||||||
{
|
{
|
||||||
Tick start = fs.Hos.Os.GetSystemTick();
|
Tick start = fs.Hos.Os.GetSystemTick();
|
||||||
rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, oldPath);
|
rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath);
|
||||||
Tick end = fs.Hos.Os.GetSystemTick();
|
Tick end = fs.Hos.Os.GetSystemTick();
|
||||||
|
|
||||||
var sb = new U8StringBuilder(logBuffer, true);
|
var sb = new U8StringBuilder(logBuffer, true);
|
||||||
sb.Append(LogPath).Append(oldPath).Append(LogNewPath).Append(newPath).Append((byte)'"');
|
sb.Append(LogPath).Append(currentPath).Append(LogNewPath).Append(newPath).Append((byte)'"');
|
||||||
logBuffer = sb.Buffer;
|
logBuffer = sb.Buffer;
|
||||||
|
|
||||||
fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer));
|
fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, oldPath);
|
rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath);
|
||||||
}
|
}
|
||||||
fs.Impl.AbortIfNeeded(rc);
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
@ -421,19 +426,18 @@ public static class UserFileSystem
|
||||||
FileSystemAccessor fileSystem;
|
FileSystemAccessor fileSystem;
|
||||||
Span<byte> logBuffer = stackalloc byte[0x300];
|
Span<byte> logBuffer = stackalloc byte[0x300];
|
||||||
|
|
||||||
|
static Result FindImpl(FileSystemClient fs, U8Span path, out FileSystemAccessor fileSystem, ref U8Span subPath)
|
||||||
|
{
|
||||||
|
if (fs.Impl.IsValidMountName(path))
|
||||||
|
return fs.Impl.Find(out fileSystem, path);
|
||||||
|
else
|
||||||
|
return fs.Impl.FindFileSystem(out fileSystem, out subPath, path);
|
||||||
|
}
|
||||||
|
|
||||||
if (fs.Impl.IsEnabledAccessLog())
|
if (fs.Impl.IsEnabledAccessLog())
|
||||||
{
|
{
|
||||||
Tick start = fs.Hos.Os.GetSystemTick();
|
Tick start = fs.Hos.Os.GetSystemTick();
|
||||||
if (fs.Impl.IsValidMountName(path))
|
rc = FindImpl(fs, path, out fileSystem, ref subPath);
|
||||||
{
|
|
||||||
rc = fs.Impl.Find(out fileSystem, path);
|
|
||||||
if (rc.IsFailure()) return rc;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path);
|
|
||||||
if (rc.IsFailure()) return rc;
|
|
||||||
}
|
|
||||||
Tick end = fs.Hos.Os.GetSystemTick();
|
Tick end = fs.Hos.Os.GetSystemTick();
|
||||||
|
|
||||||
var sb = new U8StringBuilder(logBuffer, true);
|
var sb = new U8StringBuilder(logBuffer, true);
|
||||||
|
@ -445,24 +449,25 @@ public static class UserFileSystem
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (fs.Impl.IsValidMountName(path))
|
rc = FindImpl(fs, path, out fileSystem, ref subPath);
|
||||||
{
|
|
||||||
rc = fs.Impl.Find(out fileSystem, path);
|
|
||||||
if (rc.IsFailure()) return rc;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path);
|
|
||||||
if (rc.IsFailure()) return rc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fs.Impl.AbortIfNeeded(rc);
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
static Result GetImpl(out long freeSpace, FileSystemAccessor fileSystem, U8Span subPath)
|
||||||
|
{
|
||||||
|
UnsafeHelpers.SkipParamInit(out freeSpace);
|
||||||
|
|
||||||
|
if (subPath.IsEmpty() && StringUtils.Compare(subPath, new[] { (byte)'/' }) != 0)
|
||||||
|
return ResultFs.InvalidMountName.Log();
|
||||||
|
|
||||||
|
return fileSystem.GetFreeSpaceSize(out freeSpace, new U8Span(new[] { (byte)'/' }));
|
||||||
|
}
|
||||||
|
|
||||||
if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog())
|
if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog())
|
||||||
{
|
{
|
||||||
Tick start = fs.Hos.Os.GetSystemTick();
|
Tick start = fs.Hos.Os.GetSystemTick();
|
||||||
rc = fileSystem.GetFreeSpaceSize(out freeSpace, subPath);
|
rc = GetImpl(out freeSpace, fileSystem, subPath);
|
||||||
Tick end = fs.Hos.Os.GetSystemTick();
|
Tick end = fs.Hos.Os.GetSystemTick();
|
||||||
|
|
||||||
var sb = new U8StringBuilder(logBuffer, true);
|
var sb = new U8StringBuilder(logBuffer, true);
|
||||||
|
@ -474,7 +479,7 @@ public static class UserFileSystem
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = fileSystem.GetFreeSpaceSize(out freeSpace, subPath);
|
rc = GetImpl(out freeSpace, fileSystem, subPath);
|
||||||
}
|
}
|
||||||
fs.Impl.AbortIfNeeded(rc);
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -635,6 +640,9 @@ public static class UserFileSystem
|
||||||
if (mountNames.Length > 10)
|
if (mountNames.Length > 10)
|
||||||
return ResultFs.InvalidCommitNameCount.Log();
|
return ResultFs.InvalidCommitNameCount.Log();
|
||||||
|
|
||||||
|
if (mountNames.Length < 10)
|
||||||
|
return ResultFs.InvalidCommitNameCount.Log();
|
||||||
|
|
||||||
if (mountNames.Length == 0)
|
if (mountNames.Length == 0)
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
|
|
||||||
|
@ -744,4 +752,4 @@ public static class UserFileSystem
|
||||||
{
|
{
|
||||||
return CommitImpl(fs, mountName);
|
return CommitImpl(fs, mountName);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue