⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cyclic.c

📁 ST5518机顶盒系统文件系统源代码!绝对超值!
💻 C
📖 第 1 页 / 共 2 页
字号:
                /* calculate actual number of bytes written in total, allowing for the fact that                  sizeof(StdData) may not divide exactly by 10, so we need to round down */                                  DataWritten = 10 * (sizeof(StdData) / 10);                /* compare the data */                                if (memcmp(StdData, Buffer, DataWritten))                {                    for (i = 0; (i < DataWritten); ++i)                    {                        if (StdData[i] != Buffer[i])                        {                            Result = TEST_FAILED;                            STTBX_Print(("Write-Read mismatch: first error is at byte offset %d within block\n", i));                            break;                        }                    }                }            }            /* In any case where we sucessfully opened the file, attempt to Close and Delete 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, "tstest"))            {                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 : BufferRead  Description : Test a read of a sector and a bit followed by a read within the second sector   Parameters :******************************************************************************/static TestResult_t BufferRead (int TestNo, TestVariant_t Variant){    TestResult_t Result;    STAVFS_Handle_t DiskHandle;    Result = OpenPartition(0, 1, "Dev1", &DiskHandle);    if (TEST_PASSED == Result)    {        STAVFS_FileHandle_t FileHandle;        U64 FileSize, ReadPos, WritePos;        U32 DataWritten, DataRead;        int i = 0;        /* Create a cyclic file big enough to cover the test */                I64_SetValue ((sizeof (StdData) * 2), 0, FileSize);        if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, "tstest",            STAVFS_CYCLIC_MODE | STAVFS_WRITE_MODE | STAVFS_READ_MODE, FileSize, &FileHandle))        {            STTBX_Print (("Error opening cyclic file\n"));            Result = TEST_FAILED;        }        else        {            /* Writes 760 bytes to the file in 10-byte chunks */            /* 512 on disk and 248 in buffer (until closed) */                        assert(760 < sizeof(StdData));            for (i = 0; i < 760; i = i + 10)            {                if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, StdData + i, 10, &DataWritten))                {                    STTBX_Print (("Error writing\n"));                    Result = TEST_FAILED;                    break;                }            }            if (TEST_PASSED == Result) /* ie okay so far */            {                STAVFS_GetFilePosition (FileHandle, FALSE, &ReadPos);                STAVFS_GetFilePosition (FileHandle, TRUE, &WritePos);                STTBX_Print (("read pos: %d, write pos: %d\n", ReadPos.LSW, WritePos.LSW));                /* read back in two parts. The first operation should read two sectors, leaving                  the second one in a buffer which the subsequent call reads entirely from */                                if (ST_NO_ERROR != STAVFS_ReadFile (FileHandle, Buffer, 730, &DataRead))                {                    STTBX_Print (("Error reading file (large chunk)\n"));                    Result = TEST_FAILED;                }                else if (ST_NO_ERROR != STAVFS_ReadFile (FileHandle, Buffer + 730, 30, &DataRead))                {                    STTBX_Print (("Error reading file (small chunk)\n"));                    Result = TEST_FAILED;                }            }            if (TEST_PASSED == Result) /* both write and read okay */            {                STAVFS_GetFilePosition (FileHandle, FALSE, &ReadPos);                STAVFS_GetFilePosition (FileHandle, TRUE, &WritePos);                STTBX_Print (("read pos: %d, write pos: %d\n", ReadPos.LSW, WritePos.LSW));                /* compare the data */                if (memcmp(StdData, Buffer, 760))                {                    for (i = 0; (i < 760); ++i)                    {                        if (StdData[i] != Buffer[i])                        {                            Result = TEST_FAILED;                            STTBX_Print(("Write-Read mismatch: first error is at byte offset %d within block\n", i));                            break;                        }                    }                }            }            /* In any case where we sucessfully opened the file, attempt to Close and Delete 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, "tstest"))            {                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 : WriteReadBuffer  Description : Test alternate reading and writing, both crossing sectors and within one buffer,                together with cycling back to the start of the physical file   Parameters :******************************************************************************/static TestResult_t WriteReadBuffer (int TestNo, TestVariant_t Variant){    TestResult_t Result;    STAVFS_Handle_t DiskHandle;    Result = OpenPartition(0, 1, "Dev1", &DiskHandle);    if (TEST_PASSED == Result)    {        STAVFS_FileHandle_t FileHandle;        U64 FileSize, ReadPos, WritePos;        U32 DataWritten, DataRead;        int i, j;                /* read/write blocks will be 20 bytes long, and we will iterate enough times          to cover just over four sectors: */                  U32 BytesPerIteration = 20;        U32 CntIterations = 1 + 4 * DISK_SECTOR_SIZE / BytesPerIteration;        /* Create a cyclic file with the smallest nonzero size possible (the cluster size in bytes).          With the Format test default of one sector per cluster, this will ensure we cycle the file          several times; and we will cycle at least once provided we have no more than 4 sectors          per cluster */        I64_SetValue (DISK_SECTOR_SIZE, 0, FileSize);        if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, "tstest",            STAVFS_CYCLIC_MODE | STAVFS_WRITE_MODE | STAVFS_READ_MODE, FileSize, &FileHandle))        {            STTBX_Print (("Error opening file\n"));            Result = TEST_FAILED;        }        else        {            /* alternately write and read blocks of data */                        for (i = 0; i < CntIterations; ++i)            {                if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, StdData, BytesPerIteration, &DataWritten))                {                    STTBX_Print (("Error writing file\n"));                    Result = TEST_FAILED;                }                else if (ST_NO_ERROR != STAVFS_ReadFile (FileHandle, Buffer, BytesPerIteration, &DataRead))                {                    STTBX_Print (("Error reading file\n"));                    Result = TEST_FAILED;                }                else if (memcmp(StdData, Buffer, BytesPerIteration))                {                    for (j = 0; j < BytesPerIteration; ++j)                    {                        if (StdData[j] != Buffer[j])                        {                            Result = TEST_FAILED;                            STTBX_Print(("Write-Read mismatch on iteration %d: first error is at byte offset %d within block\n", i, j));                            break;                        }                    }                }                if (Result == TEST_FAILED)                {                    STAVFS_GetFilePosition (FileHandle, FALSE, &ReadPos);                    STAVFS_GetFilePosition (FileHandle, TRUE, &WritePos);                    STTBX_Print (("read pos: %d, write pos: %d\n", ReadPos.LSW, WritePos.LSW));                    break;                }            }            /* In any case where we sucessfully opened the file, attempt to Close and Delete 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, "tstest"))            {                STTBX_Print (("Error deleting file\n"));                Result = TEST_FAILED;            }        }        if (TEST_PASSED != ClosePartition("Dev1", DiskHandle))        {            Result = TEST_FAILED; /* message already displayed */        }    }    return (Result);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -