📄 position.c
字号:
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 : InitialPos Description : Check initialisation of file positions on create/open Parameters :******************************************************************************/static TestResult_t InitialPos(int TestNo, TestVariant_t Variant){ TestResult_t Result; STAVFS_Handle_t DiskHandle; STAVFS_OpenMode_t OpenMode = STAVFS_WRITE_MODE | STAVFS_READ_MODE; switch (Variant) { case TEST_VARIANT_A: /* regular files; no special settings */ break; case TEST_VARIANT_B: /* cyclic files */ OpenMode |= STAVFS_CYCLIC_MODE; break; default: return TEST_NOT_WRITTEN; } Result = OpenPartition(0, 1, "Dev1", &DiskHandle); /* 1 sector per cluster */ if (TEST_PASSED == Result) { STAVFS_FileHandle_t FileHandle; U64 FileSize; U32 ExpectedWritePos; U32 DataRead, DataWritten; int i; I64_SetValue (500, 0, FileSize); /* < 1 sector */ if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, OpenMode, FileSize, &FileHandle)) { STTBX_Print (("Error opening file (1)\n")); Result = TEST_FAILED; } else { /* Initial read and write pos should be 0 */ if (TEST_PASSED != CheckPos(FileHandle, 0, 0, "New empty file: ")) { Result = TEST_FAILED; /* message already displayed */ } /* write and read a bit */ for (i = 0; i < 4; ++i) { if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, StdData, 100, &DataWritten)) { STTBX_Print (("Error writing file (1)\n")); Result = TEST_FAILED; break; } } if (Result == TEST_PASSED && ST_NO_ERROR != STAVFS_ReadFile (FileHandle, Buffer, 200, &DataRead)) { STTBX_Print (("Error reading file (1)\n")); Result = TEST_FAILED; } /* close, and reopen if no errors so far */ if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing file (1)\n")); Result = TEST_FAILED; } if (Result == TEST_PASSED && ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, OpenMode, FileSize, &FileHandle)) { STTBX_Print (("Error opening file (2)\n")); Result = TEST_FAILED; } if (Result == TEST_PASSED) { ExpectedWritePos = (OpenMode & STAVFS_CYCLIC_MODE) ? 0 : 400; if (TEST_PASSED != CheckPos(FileHandle, 0, ExpectedWritePos, "Reopened after writing 400 bytes: ")) { Result = TEST_FAILED; /* message already displayed */ } /* The rest of the test is currently for non-cyclic files only */ if ((OpenMode & STAVFS_CYCLIC_MODE) == 0) { Result = InitialPosNonCyclic(DiskHandle, FileHandle); /* will close the file */ } else if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing file (2)\n")); Result = TEST_FAILED; } } /* delete file in all cases where we sucessfully created it */ 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("Dev1", DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } } return (Result);}/******************************************************************************Function Name : InitialPosNonCyclic Description : Inner part of InitialPos test, currently applied to only non-cyclic files because of the resetting they exhibit on close Parameters : file handle******************************************************************************/static TestResult_t InitialPosNonCyclic(STAVFS_Handle_t DiskHandle, STAVFS_FileHandle_t FileHandle){ TestResult_t Result = TEST_PASSED; U32 DataWritten; U64 FileSize; /* shouldn't matter as we're reopening */ I64_SetValue (0, 0, FileSize); /* write a further 100 bytes, to land exactly on the original allocation */ if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, StdData, 100, &DataWritten)) { STTBX_Print (("Error writing file (2)\n")); Result = TEST_FAILED; } else if (TEST_PASSED != CheckPos(FileHandle, 0, 500, "Extended file to 500 bytes: ")) { Result = TEST_FAILED; /* message already displayed */ } /* close file, and reopen if no errors so far */ if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing file (2)\n")); Result = TEST_FAILED; } if (Result == TEST_PASSED && ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, STAVFS_READ_MODE | STAVFS_WRITE_MODE, FileSize, &FileHandle)) { STTBX_Print (("Error opening file (3)\n")); Result = TEST_FAILED; } if (Result == TEST_PASSED) { if (TEST_PASSED != CheckPos(FileHandle, 0, 500, "Reopened after writing 500 bytes: ")) { Result = TEST_FAILED; /* message already displayed */ } /* write a final 100 bytes, taking us over the allocation, sector, and cluster boundary */ if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, StdData, 100, &DataWritten)) { STTBX_Print (("Error writing file (3)\n")); Result = TEST_FAILED; } else if (TEST_PASSED != CheckPos(FileHandle, 0, 600, "Extended file to 600 bytes: ")) { Result = TEST_FAILED; /* message already displayed */ } /* close file, and reopen if no errors so far */ if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing file (3)\n")); Result = TEST_FAILED; } if (Result == TEST_PASSED && ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, STAVFS_READ_MODE | STAVFS_WRITE_MODE, FileSize, &FileHandle)) { STTBX_Print (("Error opening file (4)\n")); Result = TEST_FAILED; } if (Result == TEST_PASSED) { if (TEST_PASSED != CheckPos(FileHandle, 0, 600, "Reopened after writing 600 bytes: ")) { Result = TEST_FAILED; /* message already displayed */ } if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle)) { STTBX_Print (("Error closing file (4)\n")); Result = TEST_FAILED; } } } /* InitialPos will perform the deletion */ return (Result);}/******************************************************************************Function Name : Boundaries Description : Check following if we land directly on sector/cluster/allocation boundaries Parameters :******************************************************************************/static TestResult_t Boundaries(int TestNo, TestVariant_t Variant){ TestResult_t Result; STAVFS_Handle_t DiskHandle; STAVFS_OpenMode_t OpenMode = STAVFS_WRITE_MODE | STAVFS_READ_MODE; switch (Variant) { case TEST_VARIANT_A: /* regular files; no special settings */ break; case TEST_VARIANT_B: /* cyclic files; just to check they do the same thing when not wrapping */ OpenMode |= STAVFS_CYCLIC_MODE; break; default: return TEST_NOT_WRITTEN; } Result = OpenPartition(0, 2, "Dev2", &DiskHandle); /* 2 sectors per cluster */ if (TEST_PASSED == Result) { STAVFS_FileHandle_t FileHandle; U64 FileSize; U32 ReadPos = 0, WritePos = 0; I64_SetValue (4 * DISK_SECTOR_SIZE, 0, FileSize); 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 { /* land write pos on sector and then cluster boundary */ if (ST_NO_ERROR != WriteChunks (FileHandle, 2, DISK_SECTOR_SIZE, ReadPos, &WritePos, NULL)) { Result = TEST_FAILED; /* message already displayed */ } /* now do the same for read pos */ else if (ST_NO_ERROR != ReadChunks (FileHandle, 2, DISK_SECTOR_SIZE, &ReadPos, WritePos, NULL)) { Result = TEST_FAILED; /* message already displayed */ } /* now a whole sector at once, which will also take us to the allocation boundary */ else if (ST_NO_ERROR != WriteChunks (FileHandle, 1, 2 * DISK_SECTOR_SIZE, ReadPos, &WritePos, NULL)) { Result = TEST_FAILED; /* message already displayed */ } else if (ST_NO_ERROR != ReadChunks (FileHandle, 1, 2 *DISK_SECTOR_SIZE, &ReadPos, WritePos, 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);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -