strat: revise fs unsupported operation results, add overflow utils

This commit is contained in:
Michael Scire 2022-03-13 01:32:34 -08:00 committed by SciresM
parent ba4e7c5866
commit 11e4bed199
31 changed files with 265 additions and 142 deletions

View file

@ -346,56 +346,92 @@ namespace ams::fs {
R_DEFINE_ERROR_RESULT(WriteNotPermitted, 6203);
R_DEFINE_ERROR_RANGE(UnsupportedOperation, 6300, 6399);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInSubStorageA, 6302);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInSubStorageB, 6303);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInMemoryStorageA, 6304);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInMemoryStorageB, 6305);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInFileStorageA, 6306);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInFileStorageB, 6307);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInSwitchStorageA, 6308);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInStorageServiceObjectAdapterA, 6309);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInAesCtrCounterExtendedStorageA, 6310);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInAesCtrCounterExtendedStorageB, 6311);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInAesCtrCounterExtendedStorageC, 6312);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInAesCtrStorageExternalA, 6313);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInAesCtrStorageExternalB, 6314);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInAesCtrStorageA, 6315);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInHierarchicalIntegrityVerificationStorageA, 6316);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInHierarchicalIntegrityVerificationStorageB, 6317);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInIntegrityVerificationStorageA, 6318);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInIntegrityVerificationStorageB, 6319);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInIntegrityVerificationStorageC, 6320);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInBlockCacheBufferedStorageA, 6321);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInBlockCacheBufferedStorageB, 6322);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInBlockCacheBufferedStorageC, 6323);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInIndirectStorageA, 6324);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInIndirectStorageB, 6325);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInIndirectStorageC, 6326);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInZeroStorageA, 6327);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInZeroStorageB, 6328);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInHierarchicalSha256StorageA, 6329);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInReadOnlyBlockCacheStorageA, 6330);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInReadOnlyBlockCacheStorageB, 6331);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInIntegrityRomFsStorageA , 6332);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInFileServiceObjectAdapterA, 6362);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInRomFsFileSystemA, 6364);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInRomFsFileSystemB, 6365);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInRomFsFileSystemC, 6366);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInRomFsFileA, 6367);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInRomFsFileB, 6368);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInReadOnlyFileSystemTemplateA, 6369);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInReadOnlyFileSystemTemplateB, 6370);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInReadOnlyFileSystemTemplateC, 6371);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInReadOnlyFileA, 6372);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInReadOnlyFileB, 6373);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInPartitionFileSystemA, 6374);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInPartitionFileSystemB, 6375);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInPartitionFileA, 6376);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInPartitionFileB, 6377);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInLocalFileA, 6378);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInDirectorySaveDataFileSystemA, 6384);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInCompressedStorageA, 6387);
R_DEFINE_ERROR_RESULT(UnsupportedOperationInCompressedStorageB, 6388);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForNotResizableSubStorage, 6302);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForResizableSubStorage, 6303);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForMemoryStorage, 6304);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForMemoryStorage, 6305);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForFileStorage, 6306);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForFileHandleStorage, 6307);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForSwitchStorage, 6308);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForStorageServiceObjectAdapter, 6309);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForAesCtrCounterExtendedStorage, 6310);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForAesCtrCounterExtendedStorage, 6311);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForAesCtrCounterExtendedStorage, 6312);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForAesCtrStorageExternal, 6313);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForAesCtrStorageExternal, 6314);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForAesCtrStorage, 6315);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForHierarchicalIntegrityVerificationStorage, 6316);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForHierarchicalIntegrityVerificationStorage, 6317);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForIntegrityVerificationStorage, 6318);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForNonSaveDataIntegrityVerificationStorage, 6319);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForIntegrityVerificationStorage, 6320);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForBlockCacheBufferedStorage, 6321);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForNonSaveDataBlockCacheBufferedStorage, 6322);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForBlockCacheBufferedStorage, 6323);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForIndirectStorage, 6324);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForIndirectStorage, 6325);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForIndirectStorage, 6326);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForZeroStorage, 6327);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForZeroStorage, 6328);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForHierarchicalSha256Storage, 6329);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForReadOnlyBlockCacheStorage, 6330);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForReadOnlyBlockCacheStorage, 6331);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForIntegrityRomFsStorage, 6332);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForDuplexStorage, 6333);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForDuplexStorage, 6334);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForHierarchicalDuplexStorage, 6335);
R_DEFINE_ERROR_RESULT(UnsupportedGetSizeForRemapStorage, 6336);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForRemapStorage, 6337);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForRemapStorage, 6338);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForIntegritySaveDataStorage, 6339);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForIntegritySaveDataStorage, 6340);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForJournalIntegritySaveDataStorage, 6341);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForJournalIntegritySaveDataStorage, 6342);
R_DEFINE_ERROR_RESULT(UnsupportedGetSizeForJournalStorage, 6343);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForJournalStorage, 6344);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForJournalStorage, 6345);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForUnionStorage, 6346);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForAllocationTableStorage, 6347);
R_DEFINE_ERROR_RESULT(UnsupportedReadForWriteOnlyGameCardStorage, 6348);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForWriteOnlyGameCardStorage, 6349);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForReadOnlyGameCardStorage, 6350);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForReadOnlyGameCardStorage, 6351);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForReadOnlyGameCardStorage, 6352);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForSdmmcStorage, 6353);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForSdmmcStorage, 6354);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForFatFile, 6355);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForStorageFile, 6356);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForInternalStorageConcatenationFile, 6357);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForInternalStorageConcatenationFile, 6358);
R_DEFINE_ERROR_RESULT(UnsupportedQueryEntryForConcatenationFileSystem, 6359);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForConcatenationFile, 6360);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForZeroBitmapFile, 6361);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForFileServiceObjectAdapter, 6362);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForAesXtsFile, 6363);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForRomFsFileSystem, 6364);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForRomFsFileSystem, 6365);
R_DEFINE_ERROR_RESULT(UnsupportedGetTotalSpaceSizeForRomFsFileSystem, 6366);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForRomFsFile, 6367);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForRomFsFile, 6368);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForReadOnlyFileSystem, 6369);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForReadOnlyFileSystem, 6370);
R_DEFINE_ERROR_RESULT(UnsupportedGetTotalSpaceSizeForReadOnlyFileSystem, 6371);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForReadOnlyFile, 6372);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForReadOnlyFile, 6373);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForPartitionFileSystem, 6374);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForPartitionFileSystem, 6375);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForPartitionFile, 6376);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForPartitionFile, 6377);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForTmFileSystemFile, 6378);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForSaveDataInternalStorageFileSystem, 6379);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForApplicationTemporaryFileSystem, 6382);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForSaveDataFileSystem, 6383);
R_DEFINE_ERROR_RESULT(UnsupportedCommitProvisionallyForDirectorySaveDataFileSystem, 6384);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForZeroBitmapHashStorageFile, 6385);
R_DEFINE_ERROR_RESULT(UnsupportedSetSizeForZeroBitmapHashStorageFile, 6386);
R_DEFINE_ERROR_RESULT(UnsupportedWriteForCompressedStorage, 6387);
R_DEFINE_ERROR_RESULT(UnsupportedOperateRangeForCompressedStorage, 6388);
R_DEFINE_ERROR_RANGE(PermissionDenied, 6400, 6449);
R_DEFINE_ERROR_RESULT(PermissionDeniedForCreateHostFileSystem, 6403);

View file

@ -69,4 +69,91 @@ namespace ams::util {
return ::ams::util::impl::IsIntValueRepresentableImpl<To, From>(v);
}
template<std::integral T>
constexpr ALWAYS_INLINE bool CanAddWithoutOverflow(T x, T y) {
if constexpr (std::unsigned_integral<T>) {
return x <= std::numeric_limits<T>::max() - y;
} else {
if (y >= 0) {
return x <= std::numeric_limits<T>::max() - y;
} else {
return x >= std::numeric_limits<T>::min() - y;
}
}
}
template<std::integral T>
constexpr ALWAYS_INLINE bool CanSubtractWithoutOverflow(T x, T y) {
if constexpr (std::unsigned_integral<T>) {
return x >= std::numeric_limits<T>::min() + y;
} else {
if (y >= 0) {
return x >= std::numeric_limits<T>::min() + y;
} else {
return x <= std::numeric_limits<T>::max() + y;
}
}
}
template<std::integral T>
constexpr ALWAYS_INLINE bool CanMultiplyWithoutOverflow(T x, T y) {
if (x == 0 || y == 0) {
return true;
}
if constexpr (std::unsigned_integral<T>) {
return y <= std::numeric_limits<T>::max() / x;
} else {
if (x > 0) {
if (y > 0) {
return y <= std::numeric_limits<T>::max() / x;
} else /*if (y < 0) */ {
return y >= std::numeric_limits<T>::min() / x;
}
} else /* if (x < 0) */ {
if (y > 0) {
return x >= std::numeric_limits<T>::min() / y;
} else /*if (y < 0) */ {
return y >= std::numeric_limits<T>::max() / x;
}
}
}
}
template<std::integral T>
constexpr inline bool TryAddWithoutOverflow(T *out, T x, T y) {
AMS_ASSERT(out != nullptr);
if (CanAddWithoutOverflow(x, y)) {
*out = x + y;
return true;
} else {
return false;
}
}
template<std::integral T>
constexpr inline bool TrySubtractWithoutOverflow(T *out, T x, T y) {
AMS_ASSERT(out != nullptr);
if (CanSubtractWithoutOverflow(x, y)) {
*out = x - y;
return true;
} else {
return false;
}
}
template<std::integral T>
constexpr inline bool TryMultiplyWithoutOverflow(T *out, T x, T y) {
AMS_ASSERT(out != nullptr);
if (CanMultiplyWithoutOverflow(x, y)) {
*out = x * y;
return true;
} else {
return false;
}
}
}