2020-04-03 06:57:08 +02:00
|
|
|
|
using LibHac.Common;
|
|
|
|
|
using LibHac.Fs;
|
2020-06-10 07:55:59 +02:00
|
|
|
|
using LibHac.Fs.Fsa;
|
2020-04-03 06:57:08 +02:00
|
|
|
|
using LibHac.Fs.Shim;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
namespace LibHac.Tests.Fs.FileSystemClientTests.ShimTests;
|
|
|
|
|
|
|
|
|
|
public class Bis
|
2020-04-03 06:57:08 +02:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void MountBis_MountCalibrationPartition_OpensCorrectDirectory()
|
2020-04-03 06:57:08 +02:00
|
|
|
|
{
|
2021-11-14 20:08:57 +01:00
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(fs.MountBis("calib".ToU8Span(), BisPartitionId.CalibrationFile));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Create a file in the opened file system
|
|
|
|
|
Assert.Success(fs.CreateFile("calib:/file".ToU8Span(), 0));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Make sure the file exists on the root file system
|
|
|
|
|
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/cal/file".ToU8Span()));
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type);
|
|
|
|
|
}
|
2021-05-28 01:38:29 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void MountBis_MountSafePartition_OpensCorrectDirectory()
|
|
|
|
|
{
|
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(fs.MountBis("safe".ToU8Span(), BisPartitionId.SafeMode));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Create a file in the opened file system
|
|
|
|
|
Assert.Success(fs.CreateFile("safe:/file".ToU8Span(), 0));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Make sure the file exists on the root file system
|
|
|
|
|
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/safe/file".ToU8Span()));
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type);
|
|
|
|
|
}
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void MountBis_MountSystemPartition_OpensCorrectDirectory()
|
|
|
|
|
{
|
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(fs.MountBis("system".ToU8Span(), BisPartitionId.System));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Create a file in the opened file system
|
|
|
|
|
Assert.Success(fs.CreateFile("system:/file".ToU8Span(), 0));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Make sure the file exists on the root file system
|
|
|
|
|
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/system/file".ToU8Span()));
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type);
|
|
|
|
|
}
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void MountBis_MountUserPartition_OpensCorrectDirectory()
|
|
|
|
|
{
|
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(fs.MountBis("user".ToU8Span(), BisPartitionId.User));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Create a file in the opened file system
|
|
|
|
|
Assert.Success(fs.CreateFile("user:/file".ToU8Span(), 0));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Make sure the file exists on the root file system
|
|
|
|
|
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/user/file".ToU8Span()));
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type);
|
|
|
|
|
}
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void MountBis_WithRootPath_IgnoresRootPath()
|
|
|
|
|
{
|
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem rootFs);
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Success(fs.MountBis(BisPartitionId.User, "/sub".ToU8Span()));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Create a file in the opened file system
|
|
|
|
|
Assert.Success(fs.CreateFile("@User:/file".ToU8Span(), 0));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Make sure the file wasn't created in the sub path
|
|
|
|
|
Assert.Result(ResultFs.PathNotFound, rootFs.GetEntryType(out _, "/bis/user/sub/file".ToU8Span()));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
// Make sure the file was created in the main path
|
|
|
|
|
Assert.Success(rootFs.GetEntryType(out DirectoryEntryType type, "/bis/user/file".ToU8Span()));
|
|
|
|
|
Assert.Equal(DirectoryEntryType.File, type);
|
|
|
|
|
}
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
[Fact]
|
|
|
|
|
public void MountBis_InvalidPartition_ReturnsInvalidArgument()
|
|
|
|
|
{
|
|
|
|
|
FileSystemClient fs = FileSystemServerFactory.CreateClient(out IFileSystem _);
|
2020-04-03 06:57:08 +02:00
|
|
|
|
|
2021-11-14 20:08:57 +01:00
|
|
|
|
Assert.Result(ResultFs.InvalidArgument, fs.MountBis("boot1".ToU8Span(), BisPartitionId.BootPartition1Root));
|
2020-04-03 06:57:08 +02:00
|
|
|
|
}
|
2022-11-12 02:21:07 +01:00
|
|
|
|
}
|