diff --git a/src/LibHac/Fs/Fsa/MountUtility.cs b/src/LibHac/Fs/Fsa/MountUtility.cs index b7a144ea..0749c2a2 100644 --- a/src/LibHac/Fs/Fsa/MountUtility.cs +++ b/src/LibHac/Fs/Fsa/MountUtility.cs @@ -292,7 +292,7 @@ public static class MountUtility if (mountNameLength + commonPathLength > commonPathBuffer.Length) return ResultFs.TooLongPath.Log(); - StringUtils.Copy(commonPathBuffer.Slice(commonPathLength), subPath); + StringUtils.Copy(commonPathBuffer.Slice(mountNameLength), subPath); return Result.Success; } } \ No newline at end of file diff --git a/tests/LibHac.Tests/Fs/FsaTests/MountUtilityTests.cs b/tests/LibHac.Tests/Fs/FsaTests/MountUtilityTests.cs index 371e3236..301b0eaa 100644 --- a/tests/LibHac.Tests/Fs/FsaTests/MountUtilityTests.cs +++ b/tests/LibHac.Tests/Fs/FsaTests/MountUtilityTests.cs @@ -1,8 +1,11 @@ -using LibHac.Common; +using System; +using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; using LibHac.Fs.Shim; using LibHac.Tests.Fs.FileSystemClientTests; +using LibHac.Tools.Fs; +using LibHac.Util; using Xunit; namespace LibHac.Tests.Fs.FsaTests; @@ -32,4 +35,43 @@ public class MountUtilityTests Assert.Success(fs.MountSdCard(mountName.ToU8Span())); Assert.Result(ResultFs.InvalidMountName, fs.GetEntryType(out _, path.ToU8Span())); } + + private class TestCommonMountNameGenerator : ICommonMountNameGenerator + { + public void Dispose() { } + + public Result GenerateCommonMountName(Span nameBuffer) + { + ReadOnlySpan mountName = "@Test"u8; + + // Add 2 for the mount name separator and null terminator + int requiredNameBufferSize = StringUtils.GetLength(mountName, PathTool.MountNameLengthMax) + 2; + + Assert.True(nameBuffer.Length >= requiredNameBufferSize); + + var sb = new U8StringBuilder(nameBuffer); + sb.Append(mountName).Append(StringTraits.DriveSeparator); + + Assert.Equal(sb.Length, requiredNameBufferSize - 1); + + return Result.Success; + } + } + + [Fact] + public void ConvertToFsCommonPath_MountedWithCommonPath_ReturnsCommonPath() + { + FileSystemClient fs = FileSystemServerFactory.CreateClient(true); + + using var fileSystem = new UniqueRef(new InMemoryFileSystem()); + using var mountNameGenerator = new UniqueRef(new TestCommonMountNameGenerator()); + Assert.Success(fs.Register("mount"u8, ref fileSystem.Ref, ref mountNameGenerator.Ref)); + + byte[] outputPath = new byte[100]; + Assert.Success(fs.ConvertToFsCommonPath(new U8SpanMutable(outputPath), "mount:/entry1/entry2"u8)); + + string expected = "@Test:/entry1/entry2"; + string actual = StringUtils.Utf8ZToString(outputPath); + Assert.Equal(expected, actual); + } } \ No newline at end of file