Fix AesXtsFileSystem

This commit is contained in:
Alex Barney 2020-02-12 02:18:22 -07:00
parent ea8cc33003
commit 4ff12ec21b
4 changed files with 18 additions and 5 deletions

View File

@ -107,13 +107,15 @@ namespace LibHac.FsSystem
Result rc = BaseFile.Write(0, Header.ToBytes(false)); Result rc = BaseFile.Write(0, Header.ToBytes(false));
if (rc.IsFailure()) return rc; if (rc.IsFailure()) return rc;
return BaseStorage.SetSize(size); return BaseStorage.SetSize(Util.AlignUp(size, 0x10));
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing) if (disposing)
{ {
BaseStorage.Flush();
BaseStorage.Dispose();
BaseFile?.Dispose(); BaseFile?.Dispose();
} }
} }

View File

@ -148,7 +148,7 @@ namespace LibHac.FsSystem
private void RenameDirectoryImpl(string srcDir, string dstDir, bool doRollback) private void RenameDirectoryImpl(string srcDir, string dstDir, bool doRollback)
{ {
foreach (DirectoryEntryEx entry in this.EnumerateEntries(srcDir, "*")) foreach (DirectoryEntryEx entry in this.EnumerateEntries(dstDir, "*"))
{ {
string subSrcPath = $"{srcDir}/{entry.Name}"; string subSrcPath = $"{srcDir}/{entry.Name}";
string subDstPath = $"{dstDir}/{entry.Name}"; string subDstPath = $"{dstDir}/{entry.Name}";
@ -185,7 +185,8 @@ namespace LibHac.FsSystem
AesXtsFileHeader header = ReadXtsHeader(oldPath, oldPath); AesXtsFileHeader header = ReadXtsHeader(oldPath, oldPath);
BaseFileSystem.RenameFile(oldPath, newPath); Result rc = BaseFileSystem.RenameFile(oldPath, newPath);
if (rc.IsFailure()) return rc;
try try
{ {

View File

@ -109,13 +109,20 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
fs.CreateFile("/file", 100, CreateFileOptions.None); fs.CreateFile("/file", 100, CreateFileOptions.None);
// The contents of a created file are undefined, so zero the file
fs.OpenFile(out IFile file, "/file", OpenMode.Write);
using (file)
{
file.Write(0, new byte[100], WriteOption.None);
}
var bufferExpected = new byte[200]; var bufferExpected = new byte[200];
bufferExpected.AsSpan(10).Fill(0xCC); bufferExpected.AsSpan(10).Fill(0xCC);
var buffer = new byte[200]; var buffer = new byte[200];
buffer.AsSpan().Fill(0xCC); buffer.AsSpan().Fill(0xCC);
fs.OpenFile(out IFile file, "/file", OpenMode.Read); fs.OpenFile(out file, "/file", OpenMode.Read);
using (file) using (file)
{ {
Assert.True(file.Read(out _, 90, buffer, ReadOption.None).IsSuccess()); Assert.True(file.Read(out _, 90, buffer, ReadOption.None).IsSuccess());

View File

@ -147,7 +147,10 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
fs.OpenFile(out IFile file, "/file", OpenMode.All); fs.OpenFile(out IFile file, "/file", OpenMode.All);
using (file) using (file)
{ {
file.Write(15, writeBuffer, WriteOption.None).IsSuccess(); Assert.True(file.Write(15, writeBuffer, WriteOption.None).IsSuccess());
// Unwritten portions of new files are undefined, so write to the other portions
file.Write(0, new byte[15], WriteOption.None);
} }
var readBuffer = new byte[25]; var readBuffer = new byte[25];