📄 crashtst.c
字号:
Result = OpenPartition(0, PARTITION_NUM, DEV_NAME, &DiskHandle); if (TEST_PASSED == Result) { /* Create a file to make the working file cross cluster blocks */ I64_SetValue (255 * DISK_SECTOR_SIZE * TestPartitionDefs[PARTITION_NUM].SizeOfCluster - BACKGROUND_NUM_CHUNKS * BACKGROUND_CHUNK_SIZE - WORKING_NUM_CHUNKS_PRESYNC * WORKING_CHUNK_SIZE, 0, FileSize); if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILLER_FILE_NAME, STAVFS_WRITE_MODE, FileSize, &FileHandle)) { STTBX_Print (("Error creating filler file\n")); Result = TEST_FAILED; /* but keep going for simplicity */ } else if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing filler file\n")); Result = TEST_FAILED; } /* Delete background file if present from an aborted previous run */ Error = STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, BACKGROUND_FILE_NAME); if ((Error != ST_NO_ERROR) && (Error != STAVFS_ERROR_NO_SUCH_FILE)) { STTBX_Print (("Unexpected error deleting background file\n")); Result = TEST_FAILED; } /* Create the file; let it auto-expand as we write data */ I64_SetValue (0, 0, FileSize); if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, BACKGROUND_FILE_NAME, STAVFS_WRITE_MODE, FileSize, &FileHandle)) { STTBX_Print (("Error creating background file\n")); Result = TEST_FAILED; } else { if (TEST_PASSED != WriteChunks (FileHandle, BACKGROUND_NUM_CHUNKS, BACKGROUND_CHUNK_SIZE, "Creating background file: ")) { Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing background file\n")); Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_GetFreeDiskSpace (DiskHandle, &BaseDiskSpace)) { STTBX_Print (("Error getting free disk space\n")); Result = TEST_FAILED; } if (Result != TEST_PASSED) { /* clean up file if something failed above */ if (ST_NO_ERROR != STAVFS_DeleteFile(DiskHandle, STAVFS_NULL_FILE_HANDLE, BACKGROUND_FILE_NAME)) { STTBX_Print (("Error deleting background file\n")); Result = TEST_FAILED; } } } if (TEST_PASSED != ClosePartition(DEV_NAME, DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ /* will leave file existing after test if we created it */ } } return (Result);}/******************************************************************************Function Name : DeleteBackgroundFile Description : Reopen partition one final time, with fsck, to delete the 'background' file Parameters :******************************************************************************/static TestResult_t DeleteBackgroundFile(void){ TestResult_t Result; STAVFS_Handle_t DiskHandle; Result = OpenPartition(0, PARTITION_NUM, DEV_NAME, &DiskHandle); if (TEST_PASSED == Result) { if (TEST_PASSED != ValidateFreeSpace (DiskHandle)) { Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_DeleteFile(DiskHandle, STAVFS_NULL_FILE_HANDLE, BACKGROUND_FILE_NAME)) { STTBX_Print (("Error deleting background file\n")); Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_DeleteFile(DiskHandle, STAVFS_NULL_FILE_HANDLE, FILLER_FILE_NAME)) { STTBX_Print (("Error deleting filler file\n")); Result = TEST_FAILED; } if (TEST_PASSED != ClosePartition(DEV_NAME, DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } } return (Result);}/******************************************************************************Function Name : CrashThreadProc Description : Thread procedure that runs the test sequence of operations which the simulated crash interrupts Parameters :******************************************************************************/static void CrashThreadProc(void * Param){ STAVFS_Handle_t DiskHandle; STAVFS_FileHandle_t FileHandle; STAVFS_InitParams_t InitParams; STAVFS_OpenParams_t OpenParams; STAVFS_TermParams_t TermParams; U64 FileSize; 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 = PARTITION_NUM; OpenParams.Flags = 0; TermParams.Flags = 0; /* Initialise variables reporting back to main thread */ CrashPoint = CP_INIT; /* Initialise and Open partition */ if (ST_NO_ERROR != STAVFS_Init (DEV_NAME, &InitParams)) { STTBX_Print (("CrashThreadProc: Error initialising partition\n")); CrashPoint = CP_ERROR; } else { CrashPoint = CP_OPEN; if (ST_NO_ERROR != STAVFS_Open (DEV_NAME, &OpenParams, &DiskHandle)) { STTBX_Print (("CrashThreadProc: Error opening partition\n")); CrashPoint = CP_ERROR; } if (CrashPoint != CP_ERROR) { CrashPoint = CP_CREATE_FILE; I64_SetValue (WORKING_ALLOC_SIZE, 0, FileSize); if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, WORKING_FILE_NAME, STAVFS_WRITE_MODE, FileSize, &FileHandle)) { STTBX_Print (("CrashThreadProc: Error creating file\n")); CrashPoint = CP_ERROR; } } if (CrashPoint != CP_ERROR) { CrashPoint = CP_WRITE_PRESYNC; if (TEST_PASSED != WriteChunks (FileHandle, WORKING_NUM_CHUNKS_PRESYNC, WORKING_CHUNK_SIZE, "CrashThreadProc pre-sync: ")) { CrashPoint = CP_ERROR; } } if (CrashPoint != CP_ERROR) { CrashPoint = CP_SYNC_FILE; if (ST_NO_ERROR != STAVFS_SyncFile (FileHandle)) { STTBX_Print (("CrashThreadProc: STAVFS_SyncFile failed\n")); CrashPoint = CP_ERROR; } } if (CrashPoint != CP_ERROR) { CrashPoint = CP_WRITE_POSTSYNC_FIRST; if (TEST_PASSED != WriteChunks (FileHandle, 1, WORKING_CHUNK_SIZE, "CrashThreadProc post-sync: ")) { CrashPoint = CP_ERROR; } } if (CrashPoint != CP_ERROR) { CrashPoint = CP_WRITE_POSTSYNC; if (TEST_PASSED != WriteChunks (FileHandle, WORKING_NUM_CHUNKS_POSTSYNC-1, WORKING_CHUNK_SIZE, "CrashThreadProc post-sync: ")) { CrashPoint = CP_ERROR; } } /* Terminating the driver is all we need to do in the event of an error, in case we don't crash before then. The main thread will handle deleting the file */ if (CrashPoint != CP_ERROR) { CrashPoint = CP_CLOSE_FILE; if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("CrashThreadProc: Error closing file\n")); CrashPoint = CP_ERROR; } } if (CrashPoint != CP_ERROR) { CrashPoint = CP_DELETE_FILE; if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, WORKING_FILE_NAME)) { STTBX_Print (("CrashThreadProc: Error deleting file\n")); CrashPoint = CP_ERROR; } } if (CrashPoint != CP_ERROR) { CrashPoint = CP_CLOSE; if (ST_NO_ERROR != STAVFS_Close (DiskHandle)) { STTBX_Print (("CrashThreadProc: Error closing partition\n")); CrashPoint = CP_ERROR; } } if (CrashPoint != CP_ERROR) { CrashPoint = CP_TERM; } if (ST_NO_ERROR != STAVFS_Term (DEV_NAME, &TermParams)) { STTBX_Print (("CrashThreadProc: Error terminating partition\n")); CrashPoint = CP_ERROR; } if (CrashPoint != CP_ERROR) { CrashPoint = CP_COMPLETE; } } }/******************************************************************************Function Name : CheckAfterCrash Description : Check state after crash and clean up working file Parameters :******************************************************************************/static TestResult_t CheckAfterCrash(int Iteration){ TestResult_t Result = TEST_PASSED; STAVFS_Handle_t DiskHandle; /* Open the partition carefully, checking the interaction with fsck */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -