📄 position.c
字号:
/* remaining bytes should have been left alone, and thus still zero */ for (i = 1; (i < SeekReadChunkSize) && (Result == TEST_PASSED); ++i) { if (Buffer[i] != 0) { STTBX_Print (("Bogus bytes returned by STAVFS_ReadFile past EOF\n")); Result = TEST_FAILED; /* will drop out of loop condition */ } } } if (Result == TEST_PASSED) { /* check EOF seeks still work with wrapping */ I64_SetValue (DataSize, 0, Pos); if (ST_NO_ERROR != STAVFS_SeekFile (FileHandle, Pos, STAVFS_START, FALSE)) { STTBX_Print (("Unable to read-seek to EOF after wrapping\n")); Result = TEST_FAILED; } else if (ST_NO_ERROR != STAVFS_SeekFile (FileHandle, Pos, STAVFS_START, TRUE)) { STTBX_Print (("Unable to write-seek to EOF after wrapping\n")); Result = TEST_FAILED; } /* confirm that various out-of-range seeks fail */ else if (TEST_PASSED != ProbePositions (FileHandle, FALSE, BadSeeks, TABLE_LEN(BadSeeks), NULL)) { Result = TEST_FAILED; /* message already displayed */ } } /* close and delete file in all cases where we sucessfully created it */ if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing file\n")); Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME)) { STTBX_Print (("Error deleting file\n")); Result = TEST_FAILED; } } if (TEST_PASSED != ClosePartition("Dev2", DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } } return (Result);}/******************************************************************************Function Name : CyclicStability Description : Confirm that reads/writes following a seek in a wrapped/extended apply to the correct locations, and that STAVFS_CURRENT/END work Parameters :******************************************************************************/static TestResult_t CyclicStability(int TestNo, TestVariant_t Variant){ TestResult_t Result; STAVFS_Handle_t DiskHandle; STAVFS_OpenMode_t OpenMode = STAVFS_WRITE_MODE | STAVFS_READ_MODE; STAVFS_TypePosition_t SeekMode; /* CURRENT or END-based, from TestNo */ S64 Off800To400, Off600To750, Off800To750; switch (TestNo) { case 8: /* Test 009 to the outside world */ SeekMode = STAVFS_CURRENT; I64_SetValue (-400, -1, Off800To400); /* 800 -> 400 */ I64_SetValue ( 150, 0, Off600To750); /* 600 -> 750 */ I64_SetValue (- 50, -1, Off800To750); /* 800 -> 750 */ break; case 9: /* Test 010 to the outside world */ SeekMode = STAVFS_END; /* EOF is at position 800 in all cases, so the offset to supply is simply 800-DestinationPos */ I64_SetValue (400, 0, Off800To400); I64_SetValue ( 50, 0, Off600To750); I64_SetValue ( 50, 0, Off800To750); break; default: return TEST_NOT_WRITTEN; } switch (Variant) { case TEST_VARIANT_A: /* regular files */ break; case TEST_VARIANT_B: /* cyclic files */ OpenMode |= STAVFS_CYCLIC_MODE; break; default: return TEST_NOT_WRITTEN; } Result = OpenPartition(0, 0, "Dev0", &DiskHandle); /* 1 sector per cluster */ if (TEST_PASSED == Result) { STAVFS_FileHandle_t FileHandle; U64 FileSize; U32 DataWritten, DataRead; int i; I64_SetValue (1000, 0, FileSize); /* will get 1024, ie 2 clusters */ if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, OpenMode, FileSize, &FileHandle)) { STTBX_Print (("Error opening file\n")); Result = TEST_FAILED; } else { for (i = 0; i < 10; ++i) { /* write 800 bytes */ if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, StdData, 800, &DataWritten)) { STTBX_Print (("Error writing file, iteration #%i\n", i)); Result = TEST_FAILED; break; } /* write-seek back and replace 400->599 in that block */ if (ST_NO_ERROR != STAVFS_SeekFile (FileHandle, Off800To400, SeekMode, TRUE)) { STTBX_Print (("Unable to write-seek backwards, iteration #%i\n", i)); Result = TEST_FAILED; break; } if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, StdData, 200, &DataWritten)) { STTBX_Print (("Error rewriting file, iteration #%i\n", i)); Result = TEST_FAILED; break; } /* write-seek to offset 750 from where we originally started. The above write got us to 600 */ if (ST_NO_ERROR != STAVFS_SeekFile (FileHandle, Off600To750, SeekMode, TRUE)) { STTBX_Print (("Unable to write-seek forwards, iteration #%i\n", i)); Result = TEST_FAILED; break; } /* read 800 bytes, and confirm they (and hence the positionnings) are correct */ if (ST_NO_ERROR != STAVFS_ReadFile (FileHandle, Buffer, 800, &DataRead)) { STTBX_Print (("Error reading file, iteration #%i\n", i)); Result = TEST_FAILED; break; } if (memcmp (Buffer, StdData, 400)) { STTBX_Print (("Write-read mismatch, iteration #%i, before rewritten block\n", i)); Result = TEST_FAILED; break; } if (memcmp (Buffer + 400, StdData, 200)) { STTBX_Print (("Write-read mismatch, iteration #%i, in rewritten block\n", i)); Result = TEST_FAILED; break; } if (memcmp (Buffer + 600, StdData + 600, 200)) { STTBX_Print (("Write-read mismatch, iteration #%i, after rewritten block\n", i)); Result = TEST_FAILED; break; } /* and, finally, read-seek to 750 so that both start the next iteration in the same place */ if (ST_NO_ERROR != STAVFS_SeekFile (FileHandle, Off800To750, SeekMode, FALSE)) { STTBX_Print (("Unable to read-seek backwards, iteration #%i\n", i)); Result = TEST_FAILED; break; } } /* close and delete file in all cases where we sucessfully created it */ if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing file\n")); Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME)) { STTBX_Print (("Error deleting file\n")); Result = TEST_FAILED; } } if (TEST_PASSED != ClosePartition("Dev0", DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } } return (Result);}/******************************************************************************Function Name : CheckPos Description : Check that read and write positions have the indicated values, displaying a diagnostic message and returning TEST_FAILED if not. Caller can optionally provide a prefix for any messages, which should generally end ": " to lead into ours. Otherwise, provide an empty string or NULL Parameters : file handle, correct read and write positions, prefix for messages******************************************************************************/static TestResult_t CheckPos(STAVFS_FileHandle_t FileHandle, U32 ReadPos, U32 WritePos, char * Prefix_p){ TestResult_t Result = TEST_PASSED; U64 Pos; if (Prefix_p == NULL) Prefix_p = ""; else if (ST_NO_ERROR != STAVFS_GetFilePosition (FileHandle, FALSE, &Pos)) { STTBX_Print (("%sError getting current read position\n", Prefix_p)); Result = TEST_FAILED; } else if (!I64_CompU32(Pos, ReadPos)) { STTBX_Print (("%sIncorrect read position %u reported (should be %u)\n", Prefix_p, I64_GetU32(Pos), ReadPos)); Result = TEST_FAILED; } else if (ST_NO_ERROR != STAVFS_GetFilePosition (FileHandle, TRUE, &Pos)) { STTBX_Print (("%sError getting current write position\n", Prefix_p)); Result = TEST_FAILED; } else if (!I64_CompU32(Pos, WritePos)) { STTBX_Print (("%sIncorrect write position %u reported (should be %u)\n", Prefix_p, I64_GetU32(Pos), WritePos)); Result = TEST_FAILED; } return (Result);}/******************************************************************************Function Name : WriteChunks Description : Write a given number of chunks, checking GetFilePosition after each Parameters : file handle, number of chunks, chunk size, correct read position, pointer to correct write position (which we will update), prefix for messages******************************************************************************/static TestResult_t WriteChunks(STAVFS_FileHandle_t FileHandle, U32 NumChunks, U32 ChunkSize, U32 ReadPos, U32 * WritePos_p, 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 from position %u\n", Prefix_p, *WritePos_p)); Result = TEST_FAILED; break; } else { *WritePos_p += ChunkSize; if (TEST_PASSED != CheckPos(FileHandle, ReadPos, *WritePos_p, Prefix_p)) { Result = TEST_FAILED; /* message already displayed */ break; } } } return (Result);}/******************************************************************************Function Name : ReadChunks Description : Read a given number of chunks, checking GetFilePosition after each Parameters : file handle, number of chunks, chunk size, pointer to correct read position (which we will update), correct write position, prefix for messages******************************************************************************/static TestResult_t ReadChunks(STAVFS_FileHandle_t FileHandle, U32 NumChunks, U32 ChunkSize, U3
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -