📄 suppapi.c
字号:
I64_SetValue(TestPartitionDefs[2].Position - TEST_PARTITION_PADDING, 0, Position); TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with size running into partition 2\n" " You may need to reformat partitions 2 and 3", &Result); I64_SetValue(2 * TestPartitionDefs[2].Size, 0, Size); TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with size running completely over partition 2\n" " You may need to reformat partitions 2 and 3", &Result); I64_SetValue(TestPartitionDefs[2].Position + 1, 0, Position); I64_SetValue(TestPartitionDefs[2].Size / 2, 0, Size); TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with new partition completely inside the region covered by partition 2\n" " You may need to reformat partitions 2 and 3", &Result); I64_SetValue(TestPartitionDefs[3].Position, 0, Position); I64_SetValue(TestPartitionDefs[3].Size, 0, Size); /* position/size beyond disk capacity */ I64_SetValue(0xFFFFFFFF, 0, Position); TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with first sector past the end of the disk." " You may need to reformat partition 3.", &Result); I64_SetValue(TestPartitionDefs[3].Position, 0, Position); I64_SetValue(0xFFFFFFFF, 0, Size); TryGoodFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with size going beyond the end of the disk." " You may need to reformat partition 3.", &Result); I64_SetValue(TestPartitionDefs[3].Size, 0, Size); /* reformatting an open partition */ if (ST_NO_ERROR != STAVFS_Open (STD_DEV_NAME, &OpenParams, &DiskHandle)) { STTBX_Print (("Error opening unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; } else { TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with partition that is open", &Result); /* no need to reformat because we gave the right values */ /* go straight to Term ... */ } if (ST_NO_ERROR != STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("Error terminating unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; /* name should still end up invalid even if this fails, so go on with the final test regardless... */ } TryBadFormatPartition (STD_DEV_NAME, Size, Position, SizeOfCluster, "with device (identified by name) that has been terminated", &Result); /* no need to reformat because we gave the right values */ } return (Result);}/******************************************************************************Function Name : TryBadFormatPartition Description : Helper for FormatPartition test: try a FormatPartition that should fail. Since in most cases it is hard to know what it will have done if it does succeed, recovery is left to the caller Parameters : device name, sector count, position, cluster size (for STAVFS_FormatPartition), description to complete error message, place to record test failure******************************************************************************/static void TryBadFormatPartition(char * DevName, U64 SpaceInSectors, U64 Position, U16 SizeOfCluster, char * Descr, TestResult_t * Result_p){ if (ST_NO_ERROR == STAVFS_FormatPartition (DevName, SpaceInSectors, Position, SizeOfCluster)) { STTBX_Print(("STAVFS_FormatPartition should fail %s\n", Descr)); *Result_p = TEST_FAILED; }}/******************************************************************************Function Name : TryGoodFormatPartition Description : Helper for FormatPartition test: try a FormatPartition that should pass. Since in most cases it is hard to know what it will have done if it does fail, recovery is left to the caller Parameters : device name, sector count, position, cluster size (for STAVFS_FormatPartition), description to complete error message, place to record test failure******************************************************************************/static void TryGoodFormatPartition(char * DevName, U64 SpaceInSectors, U64 Position, U16 SizeOfCluster, char * Descr, TestResult_t * Result_p){ if (ST_NO_ERROR != STAVFS_FormatPartition (DevName, SpaceInSectors, Position, SizeOfCluster)) { STTBX_Print(("STAVFS_FormatPartition should pass %s\n", Descr)); *Result_p = TEST_FAILED; }}/******************************************************************************Function Name : DeletePartition Description : API tests for STAVFS_DeletePartition Parameters :******************************************************************************/static TestResult_t DeletePartition(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; STAVFS_InitParams_t InitParams; STAVFS_OpenParams_t OpenParams; STAVFS_TermParams_t TermParams; STAVFS_Handle_t DiskHandle; TryBadDeletePartition (STD_DEV_NAME, "with uninitialised device (and possibly uninitialised driver too)", &Result); /* give the remaining 'bad name' tests one valid name to compare against */ strcpy (InitParams.EVTName, EVT_DEVICE_NAME); strcpy (InitParams.ATAPIName, ATAPI_DEVICE_NAME); InitParams.Flags = 0; InitParams.MemoryPartition = system_partition; InitParams.Protocol = 1; InitParams.UnitNumber = 0; InitParams.PartitionNumber = 3; /* work on partition 3 as out of main use and quickest to format */ OpenParams.Flags = 0; TermParams.Flags = 0; if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams)) { STTBX_Print (("Error initialising unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; } else { TryBadDeletePartition (NULL, "with NULL device name", &Result); TryBadDeletePartition (LONG_DEV_NAME, "with overlong device name", &Result); TryBadDeletePartition (BOGUS_DEV_NAME, "with device name that has never been initialised", &Result); /* deleting a partition that is open ... */ if (ST_NO_ERROR != STAVFS_Open (STD_DEV_NAME, &OpenParams, &DiskHandle)) { STTBX_Print (("Error opening unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; } else { if (ST_NO_ERROR == STAVFS_DeletePartition (STD_DEV_NAME)) { U64 Size, Position; STTBX_Print(("STAVFS_DeletePartition should fail" " with partition that is open\nAttempting to reformat...\n")); Result = TEST_FAILED; /* Put the partition back again. Position, size, and sectors per cluster must match those produced by ../unittest/toplevel.c Format */ if (ST_NO_ERROR != STAVFS_Close (DiskHandle)) { STTBX_Print (("Error closing unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; /* but should still end up closed, so carry on trying to reformat ... */ } I64_SetValue(TestPartitionDefs[3].Size, 0, Size); I64_SetValue(TestPartitionDefs[3].Position, 0, Position); if (ST_NO_ERROR != STAVFS_FormatPartition (STD_DEV_NAME, Size, Position, TestPartitionDefs[3].SizeOfCluster)) { STTBX_Print (("Error reformatting unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; } } } if (ST_NO_ERROR != STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("Error terminating unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; /* name should still end up invalid even if this fails, so go on with the final test regardless... */ } TryBadDeletePartition (STD_DEV_NAME, "with device (identified by name) that has been terminated", &Result); } return (Result);}/******************************************************************************Function Name : TryBadDeletePartition Description : Helper for DeletePartition test: try a DeletePartition that should fail. Since in most cases it is hard to know what it will have done if it does succeed, recovery is left to the caller Parameters : device name (for STAVFS_DeletePartition), description to complete error message, place to record test failure******************************************************************************/static void TryBadDeletePartition(char * DevName, char * Descr, TestResult_t * Result_p){ if (ST_NO_ERROR == STAVFS_DeletePartition (DevName)) { STTBX_Print(("STAVFS_DeletePartition should fail %s\n", Descr)); *Result_p = TEST_FAILED; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -