📄 crashtst.c
字号:
/* cluster chain did not deallocate properly, crash left orphaned clusters, or delete encroached on background file */ STTBX_Print (("Deleting the file does not restore all disk space\n" "\toriginal: 0x%8x now: 0x%8x\n", I64_GetLower(BaseDiskSpace), I64_GetLower(FreeDiskSpace))); Result = TEST_FAILED; } return (Result);}/******************************************************************************Function Name : ValidateFreeSpace Description : Create a file filling all disk space that should be free. This confirms that the LCATs have the right number of free clusters marked, no corrupt chains, etc (GetFreeDiskSpace, by contrast, looks at the MCAT). Since this is a bit costly, you can disable it by defining SKIP_FILL_FREE_SPACE, and at any rate we only do it on the final pass of the test Parameters :******************************************************************************/static TestResult_t ValidateFreeSpace(STAVFS_Handle_t DiskHandle){ TestResult_t Result = TEST_PASSED; STAVFS_FileHandle_t FileHandle; U64 FileSize; STTBX_Print (("\nValidating LCATs...\n")); if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, "ValidateFreeSpace", STAVFS_WRITE_MODE, BaseDiskSpace, &FileHandle)) { STTBX_Print (("Error creating a file to fill the free space,\n" " so the LCATs have been corrupted\n")); Result = TEST_FAILED; } else { if (ST_NO_ERROR != STAVFS_CloseFile(FileHandle)) { STTBX_Print (("Error closing file that fills the free space\n")); Result = TEST_FAILED; } /* check we can't allocate any more - that the LCATs haven't marked as free any space that isn't or joined cluster chains */ I64_SetValue(1, 0, FileSize); /* get minimum nonzero allocation */ TryBadFileOpen (DiskHandle, "AllocTooMuch", STAVFS_WRITE_MODE, FileSize, "creating a file when the disk has been filled\n", &Result); if (ST_NO_ERROR != STAVFS_DeleteFile(DiskHandle, STAVFS_NULL_FILE_HANDLE, "ValidateFreeSpace")) { STTBX_Print (("Error deleting file that fills the free space\n")); Result = TEST_FAILED; } } /* CheckBackgroundFile could be called to confirm that file hasn't been crossed into mistakenly */ return (Result);}/******************************************************************************Function Name : TryBadFileOpen Description : Adapted from fileapi.c to help ValidateFreeDiskSpace: attempt a file open that should fail, but if it does succeed close and delete the file Parameters : Partition handle, OpenParams (both for STAVFS_Open), description to complete error message, place to record test failure******************************************************************************/static void TryBadFileOpen(STAVFS_Handle_t DiskHandle, char * PathName, STAVFS_OpenMode_t OpenMode, U64 Size, char * Descr, TestResult_t * Result_p){ STAVFS_FileHandle_t FileHandle; if (ST_NO_ERROR == STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, PathName, OpenMode, Size, &FileHandle)) { STTBX_Print (("STAVFS_OpenFile should fail %s\n", Descr)); if (Result_p != NULL) { *Result_p = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Failed closing that handle\n")); } if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, PathName)) { STTBX_Print (("Failed deleting that file\n")); } } }/******************************************************************************Function Name : DescribeCrashPoint Description : Output a line describing the current crash point Parameters :******************************************************************************/static void DescribeCrashPoint(void){ char * ActionDescr_p; switch (CrashPoint) { case CP_INIT: ActionDescr_p = "initialising partition"; break; case CP_OPEN: ActionDescr_p = "opening partition"; break; case CP_CREATE_FILE: ActionDescr_p = "creating file"; break; case CP_WRITE_PRESYNC: ActionDescr_p = "writing to file before sync"; break; case CP_SYNC_FILE: ActionDescr_p = "synchronising file"; break; case CP_WRITE_POSTSYNC_FIRST: case CP_WRITE_POSTSYNC: ActionDescr_p = "writing to file after sync"; break; case CP_CLOSE_FILE: ActionDescr_p = "closing file"; break; case CP_DELETE_FILE: ActionDescr_p = "deleting file"; break; case CP_CLOSE: ActionDescr_p = "closing partition"; break; case CP_TERM: ActionDescr_p = "terminating partition"; break; case CP_COMPLETE: ActionDescr_p = "<completed without crashing>"; break; case CP_ERROR: ActionDescr_p = "<error occured during test sequence>"; break; default: ActionDescr_p = "<BAD CrashPoint VALUE>"; } STTBX_Print (("Crash occured whilst %s\n", ActionDescr_p));}/******************************************************************************Function Name : WriteChunks Description : Write a given number of chunks from StdData Parameters : file handle, number of chunks, chunk size, prefix for messages******************************************************************************/static TestResult_t WriteChunks(STAVFS_FileHandle_t FileHandle, U32 NumChunks, U32 ChunkSize, char * Prefix_p){ TestResult_t Result = TEST_PASSED; U32 BytesWritten; assert (ChunkSize <= sizeof(StdData)); if (Prefix_p == NULL) Prefix_p = ""; while(NumChunks--) { if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, StdData, ChunkSize, &BytesWritten)) { STTBX_Print (("%sError writing file", Prefix_p)); Result = TEST_FAILED; break; /* give up */ } } return (Result);}/******************************************************************************Function Name : ReadChunks Description : Read a given number of chunks, that should each match StdData Parameters : file handle, chunk size, prefix for messages, number of chunks found before EOF (out)******************************************************************************/static TestResult_t ReadChunks(STAVFS_FileHandle_t FileHandle, U32 ChunkSize, char * Prefix_p, U32 * NumChunks_p, BOOL BadLastSector){ TestResult_t Result = TEST_PASSED; ST_ErrorCode_t Error = ST_NO_ERROR; U32 BytesRead; assert (ChunkSize <= sizeof(Buffer)); assert (ChunkSize <= sizeof(StdData)); if (Prefix_p == NULL) { Prefix_p = ""; } *NumChunks_p = 0; while ((Result == TEST_PASSED) && (Error != STAVFS_ERROR_EOF)) { /* Allow no error or EOF on chunk boundary */ Error = STAVFS_ReadFile (FileHandle, Buffer, ChunkSize, &BytesRead); if (Error != ST_NO_ERROR) { if ((Error != STAVFS_ERROR_EOF) || (BytesRead != 0)) { STTBX_Print (("%sError reading file after %i bytes\n", Prefix_p, *NumChunks_p * ChunkSize + BytesRead)); Result = TEST_FAILED; } } else { if (memcmp (Buffer, StdData, ChunkSize)) { int i; if (BadLastSector) { /* * Assume this is our bad last sector * If it is not the following reads will * wrong because we will have changed the * ChunkSize */ ChunkSize -= ChunkSize % DISK_SECTOR_SIZE; } for (i = 0; (i < ChunkSize); ++i) { if (Buffer[i] != StdData[i]) { STTBX_Print (("%sData read is incorrect after %i bytes\n", Prefix_p, *NumChunks_p * ChunkSize + i)); Result = TEST_FAILED; break; } } } (*NumChunks_p)++; } } return (Result);}/******************************************************************************Function Name : ScanFile Description : Try to open the indicated file, and if sucessful scan it for valid chunks of the indicated size Parameters :******************************************************************************/static TestResult_t ScanFile(STAVFS_Handle_t DiskHandle, char * FileName, U32 ChunkSize, char * Prefix_p, S32 * NumChunks_p, BOOL BadLastSector){ TestResult_t Result = TEST_PASSED; ST_ErrorCode_t Error; STAVFS_FileHandle_t FileHandle; U64 FileSize; I64_SetValue (0, 0, FileSize); Error = STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FileName, STAVFS_READ_MODE, FileSize, &FileHandle); if (Error != ST_NO_ERROR) { if (Error == STAVFS_ERROR_NO_SUCH_FILE) { *NumChunks_p = DOESNT_EXIST; } else { STTBX_Print (("%sError opening file\n", Prefix_p)); *NumChunks_p = 0; Result = TEST_FAILED; } } else { if (TEST_PASSED != ReadChunks (FileHandle, ChunkSize, Prefix_p, (U32 *) NumChunks_p, BadLastSector)) { Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("%sError closing file\n", Prefix_p)); Result = TEST_FAILED; } } return (Result);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -