Ensure returned result codes are logged

This commit is contained in:
Alex Barney 2019-12-17 21:55:14 -06:00
parent 5d6dce7e1f
commit 47f2f4954a
13 changed files with 59 additions and 57 deletions

View File

@ -20,25 +20,22 @@ namespace LibHac.Common
public const int ERROR_DIRECTORY = unchecked((int)0x8007010B);
public const int ERROR_SPACES_NOT_ENOUGH_DRIVES = unchecked((int)0x80E7000B);
public static Result HResultToHorizonResult(int hResult)
public static Result HResultToHorizonResult(int hResult) => hResult switch
{
return hResult switch
{
ERROR_FILE_NOT_FOUND => ResultFs.PathNotFound,
ERROR_PATH_NOT_FOUND => ResultFs.PathNotFound,
ERROR_ACCESS_DENIED => ResultFs.TargetLocked,
ERROR_SHARING_VIOLATION => ResultFs.TargetLocked,
ERROR_HANDLE_EOF => ResultFs.ValueOutOfRange,
ERROR_HANDLE_DISK_FULL => ResultFs.InsufficientFreeSpace,
ERROR_FILE_EXISTS => ResultFs.PathAlreadyExists,
ERROR_DISK_FULL => ResultFs.InsufficientFreeSpace,
ERROR_INVALID_NAME => ResultFs.PathNotFound,
ERROR_DIR_NOT_EMPTY => ResultFs.DirectoryNotEmpty,
ERROR_ALREADY_EXISTS => ResultFs.PathAlreadyExists,
ERROR_DIRECTORY => ResultFs.PathNotFound,
ERROR_SPACES_NOT_ENOUGH_DRIVES => ResultFs.InsufficientFreeSpace,
_ => ResultFs.UnknownHostFileSystemError
};
}
ERROR_FILE_NOT_FOUND => ResultFs.PathNotFound,
ERROR_PATH_NOT_FOUND => ResultFs.PathNotFound,
ERROR_ACCESS_DENIED => ResultFs.TargetLocked,
ERROR_SHARING_VIOLATION => ResultFs.TargetLocked,
ERROR_HANDLE_EOF => ResultFs.ValueOutOfRange,
ERROR_HANDLE_DISK_FULL => ResultFs.InsufficientFreeSpace,
ERROR_FILE_EXISTS => ResultFs.PathAlreadyExists,
ERROR_DISK_FULL => ResultFs.InsufficientFreeSpace,
ERROR_INVALID_NAME => ResultFs.PathNotFound,
ERROR_DIR_NOT_EMPTY => ResultFs.DirectoryNotEmpty,
ERROR_ALREADY_EXISTS => ResultFs.PathAlreadyExists,
ERROR_DIRECTORY => ResultFs.PathNotFound,
ERROR_SPACES_NOT_ENOUGH_DRIVES => ResultFs.InsufficientFreeSpace,
_ => ResultFs.UnknownHostFileSystemError
};
}
}

View File

@ -151,7 +151,7 @@ namespace LibHac.Fs.Accessors
public Result GetCommonMountName(Span<byte> nameBuffer)
{
if (MountNameGenerator == null) return ResultFs.PreconditionViolation;
if (MountNameGenerator == null) return ResultFs.PreconditionViolation.Log();
return MountNameGenerator.GenerateCommonMountName(nameBuffer);
}

View File

@ -16,7 +16,7 @@ namespace LibHac.Fs.Accessors
if (Table.ContainsKey(mountName))
{
return ResultFs.MountNameAlreadyExists;
return ResultFs.MountNameAlreadyExists.Log();
}
Table.Add(mountName, fileSystem);
@ -31,7 +31,7 @@ namespace LibHac.Fs.Accessors
{
if (!Table.TryGetValue(name, out fileSystem))
{
return ResultFs.MountNameNotFound;
return ResultFs.MountNameNotFound.Log();
}
return Result.Success;
@ -44,7 +44,7 @@ namespace LibHac.Fs.Accessors
{
if (!Table.TryGetValue(name, out FileSystemAccessor fsAccessor))
{
return ResultFs.MountNameNotFound;
return ResultFs.MountNameNotFound.Log();
}
Table.Remove(name);

View File

@ -22,8 +22,8 @@ namespace LibHac.FsService.Creators
{
fileSystem = default;
if (!IsValidPartitionId(partitionId)) return ResultFs.InvalidArgument;
if (rootPath == null) return ResultFs.NullArgument;
if (!IsValidPartitionId(partitionId)) return ResultFs.InvalidArgument.Log();
if (rootPath == null) return ResultFs.NullArgument.Log();
if (Config.TryGetFileSystem(out fileSystem, partitionId))
{
@ -32,7 +32,7 @@ namespace LibHac.FsService.Creators
if (Config.RootFileSystem == null)
{
return ResultFs.PreconditionViolation;
return ResultFs.PreconditionViolation.Log();
}
string partitionPath = GetPartitionPath(partitionId);
@ -54,7 +54,7 @@ namespace LibHac.FsService.Creators
public Result CreateFatFileSystem(out IFileSystem fileSystem, BisPartitionId partitionId)
{
fileSystem = default;
return ResultFs.NotImplemented;
return ResultFs.NotImplemented.Log();
}
public Result SetBisRootForHost(BisPartitionId partitionId, string rootPath)

View File

@ -14,8 +14,8 @@ namespace LibHac.FsService.Creators
public Result SetFileSystem(IFileSystem fileSystem, BisPartitionId partitionId)
{
if (fileSystem == null) return ResultFs.NullArgument;
if (!IsValidPartitionId(partitionId)) return ResultFs.InvalidArgument;
if (fileSystem == null) return ResultFs.NullArgument.Log();
if (!IsValidPartitionId(partitionId)) return ResultFs.InvalidArgument.Log();
PartitionFileSystems[GetArrayIndex(partitionId)] = fileSystem;
@ -24,8 +24,8 @@ namespace LibHac.FsService.Creators
public Result SetPath(string path, BisPartitionId partitionId)
{
if (path == null) return ResultFs.NullArgument;
if (!IsValidPartitionId(partitionId)) return ResultFs.InvalidArgument;
if (path == null) return ResultFs.NullArgument.Log();
if (!IsValidPartitionId(partitionId)) return ResultFs.InvalidArgument.Log();
PartitionPaths[GetArrayIndex(partitionId)] = path;

View File

@ -20,7 +20,7 @@ namespace LibHac.FsService.Creators
if (keyId < EncryptedFsKeyId.Save || keyId > EncryptedFsKeyId.CustomStorage)
{
return ResultFs.InvalidArgument;
return ResultFs.InvalidArgument.Log();
}
// todo: "proper" key generation instead of a lazy hack

View File

@ -32,7 +32,7 @@ namespace LibHac.FsService.Creators
Result rc = sourceFileSystem.GetEntryType(out DirectoryEntryType entryType, saveDataPath);
if (rc.IsFailure())
{
return rc == ResultFs.PathNotFound ? ResultFs.TargetNotFound : rc;
return rc == ResultFs.PathNotFound ? ResultFs.TargetNotFound.LogConverted(rc) : rc;
}
switch (entryType)

View File

@ -514,7 +514,12 @@ namespace LibHac.FsService
}
}
return ResultFs.TargetNotFound;
if (saveFsResult == ResultFs.PathNotFound)
{
return ResultFs.TargetNotFound.LogConverted(saveFsResult);
}
return saveFsResult;
}
private Result OpenSaveDataFileSystem3(out IFileSystem fileSystem, SaveDataSpaceId spaceId,
@ -873,7 +878,7 @@ namespace LibHac.FsService
{
if (saveDataSize < 0 || saveDataJournalSize < 0)
{
return ResultFs.InvalidSize;
return ResultFs.InvalidSize.Log();
}
SaveDataSize = saveDataSize;
@ -887,7 +892,7 @@ namespace LibHac.FsService
if (StringUtils.GetLength(path.Str, FsPath.MaxLength + 1) > FsPath.MaxLength)
{
return ResultFs.TooLongPath;
return ResultFs.TooLongPath.Log();
}
StringUtils.Copy(SaveDataRootPath.Str, path.Str);
@ -971,7 +976,7 @@ namespace LibHac.FsService
public Result SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed)
{
// todo: use struct instead of byte span
if (seed.Length != 0x10) return ResultFs.InvalidSize;
if (seed.Length != 0x10) return ResultFs.InvalidSize.Log();
// Missing permission check

View File

@ -85,7 +85,7 @@ namespace LibHac.FsService
isEncrypted = true;
break;
default:
rc = ResultFs.InvalidArgument;
rc = ResultFs.InvalidArgument.Log();
break;
}

View File

@ -27,7 +27,7 @@ namespace LibHac.FsSystem
U8StringBuilder builder = new U8StringBuilder(fsPath.Str).Append(path);
return builder.Overflowed ? ResultFs.TooLongPath : Result.Success;
return builder.Overflowed ? ResultFs.TooLongPath.Log() : Result.Success;
}
public static implicit operator U8Span(FsPath value) => new U8Span(value.Str);

View File

@ -156,12 +156,12 @@ namespace LibHac.FsSystem
{
if (typeof(T) == typeof(StandardEntry))
{
return ResultFs.InvalidPartitionFileSystemMagic;
return ResultFs.InvalidPartitionFileSystemMagic.Log();
}
if (typeof(T) == typeof(HashedEntry))
{
return ResultFs.InvalidHashedPartitionFileSystemMagic;
return ResultFs.InvalidHashedPartitionFileSystemMagic.Log();
}
throw new NotSupportedException();

View File

@ -147,98 +147,98 @@ namespace LibHac.FsSystem.Save
{
Result result = SaveDataFileSystemCore.CreateDirectory(path);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result CreateFileImpl(string path, long size, CreateFileOptions options)
{
Result result = SaveDataFileSystemCore.CreateFile(path, size, options);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result DeleteDirectoryImpl(string path)
{
Result result = SaveDataFileSystemCore.DeleteDirectory(path);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result DeleteDirectoryRecursivelyImpl(string path)
{
Result result = SaveDataFileSystemCore.DeleteDirectoryRecursively(path);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result CleanDirectoryRecursivelyImpl(string path)
{
Result result = SaveDataFileSystemCore.CleanDirectoryRecursively(path);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result DeleteFileImpl(string path)
{
Result result = SaveDataFileSystemCore.DeleteFile(path);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result OpenDirectoryImpl(out IDirectory directory, string path, OpenDirectoryMode mode)
{
Result result = SaveDataFileSystemCore.OpenDirectory(out directory, path, mode);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result OpenFileImpl(out IFile file, string path, OpenMode mode)
{
Result result = SaveDataFileSystemCore.OpenFile(out file, path, mode);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result RenameDirectoryImpl(string oldPath, string newPath)
{
Result result = SaveDataFileSystemCore.RenameDirectory(oldPath, newPath);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result RenameFileImpl(string oldPath, string newPath)
{
Result result = SaveDataFileSystemCore.RenameFile(oldPath, newPath);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path)
{
Result result = SaveDataFileSystemCore.GetEntryType(out entryType, path);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, string path)
{
Result result = SaveDataFileSystemCore.GetFreeSpaceSize(out freeSpace, path);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, string path)
{
Result result = SaveDataFileSystemCore.GetTotalSpaceSize(out totalSpace, path);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
protected override Result CommitImpl()
{
Result result = Commit(Keyset);
return SaveResults.ConvertToExternalResult(result);
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
}
public Result Commit(Keyset keyset)
@ -259,7 +259,7 @@ namespace LibHac.FsSystem.Save
headerStream.Position = 0x108;
headerStream.Write(hash, 0, hash.Length);
if (keyset == null || keyset.SaveMacKey.IsEmpty()) return ResultFs.PreconditionViolation;
if (keyset == null || keyset.SaveMacKey.IsEmpty()) return ResultFs.PreconditionViolation.Log();
var cmacData = new byte[0x200];
var cmac = new byte[0x10];

View File

@ -87,7 +87,7 @@ namespace LibHac.FsSystem.Save
{
if (description > 4721 && description < 4729)
{
return new Result(ResultFs.ModuleFs, (description - 260));
return new Result(ResultFs.ModuleFs, description - 260);
}
return result;