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

📄 fileapi.c

📁 ST5518机顶盒系统文件系统源代码!绝对超值!
💻 C
📖 第 1 页 / 共 4 页
字号:
                if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle))                {                    STTBX_Print (("Error closing file (2)\n"));                    Result = TEST_FAILED;                }            }            /* delete the file (not actually necessary whilst it's STD_FILE_NAME) */            if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, STD_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 : GetFilePosition  Description : API tests for STAVFS_GetFilePosition   Parameters :******************************************************************************/static TestResult_t GetFilePosition(int TestNo, TestVariant_t Variant){    TestResult_t        Result = TEST_PASSED;    STAVFS_Handle_t     DiskHandle;    STAVFS_FileHandle_t FileHandle;    U64 FileSize;    S64 Pos;        I64_SetValue (STD_FILE_SIZE, 0, FileSize);        /* Bad file handles (stale one attempted after we've closed a file) */    if (ST_NO_ERROR == STAVFS_GetFilePosition (STAVFS_NULL_FILE_HANDLE, TRUE, &Pos))    {        STTBX_Print (("STAVFS_GetFilePosition should fail for STAVFS_NULL_FILE_HANDLE\n"));        Result = TEST_FAILED;    }    /* provided PushMaxHandles has not been run, file handle 20 will never have been used.      Either way, it shouldn't be in use at the moment */    if (ST_NO_ERROR == STAVFS_GetFilePosition ((void *) 20, TRUE, &Pos))    {        STTBX_Print (("STAVFS_GetFilePosition should fail with a file handle that has"                      " never been opened (inside the range used)\n"));        Result = TEST_FAILED;    }    if (ST_NO_ERROR == STAVFS_GetFilePosition ((void *) 5678, TRUE, &Pos))    {        STTBX_Print (("STAVFS_GetFilePosition should fail with out-of-range file handle\n"));        Result = TEST_FAILED;    }    /* get an open device and file so bad handle tests have something the driver must reject */        if (TEST_PASSED != OpenPartition (0, 0, "Dev0", &DiskHandle))    {        Result = TEST_FAILED; /* message already displayed */    }    else    {        if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, STD_FILE_NAME,                                            STAVFS_WRITE_MODE, FileSize, &FileHandle))        {            STTBX_Print (("Error opening file\n"));            Result = TEST_FAILED;        }        else        {            /* attempt to read-seek on this handle (not opened for read) */            if (ST_NO_ERROR == STAVFS_GetFilePosition (FileHandle, FALSE, &Pos))            {                STTBX_Print (("STAVFS_GetFilePosition should fail getting read position"                              " in a file not opened for read\n"));                Result = TEST_FAILED;            }            /* ... 2 for BOOL WritePosition ... */                        /* NULL destination */                        if (ST_NO_ERROR == STAVFS_GetFilePosition (FileHandle, TRUE, NULL))            {                STTBX_Print (("STAVFS_GetFilePosition should fail"                              " when asked to write the file position to NULL\n"));                Result = TEST_FAILED;            }                        /* close the file we opened, and confirm we can't then get a position */            if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle))            {                STTBX_Print (("Error closing file\n"));                Result = TEST_FAILED;            }            if (ST_NO_ERROR == STAVFS_GetFilePosition (FileHandle, TRUE, &Pos))            {                STTBX_Print (("STAVFS_GetFilePosition should fail for a closed file handle\n"));                Result = TEST_FAILED;            }            /* reopen for read only and confirm we can't then get a write position */            if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, STD_FILE_NAME,                                                STAVFS_READ_MODE, FileSize, &FileHandle))            {                STTBX_Print (("Error reopening file\n"));                Result = TEST_FAILED;            }            else            {                if (ST_NO_ERROR == STAVFS_GetFilePosition (FileHandle, TRUE, &Pos))                {                    STTBX_Print (("STAVFS_GetFilePosition should fail getting write position"                                  " in a file not opened for write\n"));                    Result = TEST_FAILED;                }                if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle))                {                    STTBX_Print (("Error closing file (2)\n"));                    Result = TEST_FAILED;                }            }            /* delete the file (not actually necessary whilst it's STD_FILE_NAME) */            if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, STD_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 : DeleteFile  Description : API tests for STAVFS_DeleteFile   Parameters :******************************************************************************/static TestResult_t DeleteFile(int TestNo, TestVariant_t Variant){    TestResult_t        Result = TEST_PASSED;    STAVFS_Handle_t     DiskHandle;    STAVFS_FileHandle_t FileHandle;    STAVFS_OpenParams_t OpenParams; /* for reopen near end */    STAVFS_TermParams_t TermParams; /* for Term near end */        U64 FileSize;        OpenParams.Flags = 0;    TermParams.Flags = 0;    I64_SetValue (STD_FILE_SIZE, 0, FileSize);    /* Bad device handles (stale ones attempted after we've closed/terminated a device) */        /* Provided only API tests have been run since startup, handle 2 has never been opened */          TryBadDelete ((void *) 2, STAVFS_NULL_FILE_HANDLE, STD_FILE_NAME,        "with a device handle that has never been opened (inside the range used)\n", &Result);        TryBadDelete ((void *) 10000, STAVFS_NULL_FILE_HANDLE, STD_FILE_NAME,        "with out-of-range device handle\n", &Result);        /* remaining tests need an open partition */    if (TEST_PASSED != OpenPartition (0, 0, "Dev0", &DiskHandle))    {        Result = TEST_FAILED; /* message already displayed */    }    else    {        /* create the file we will then ask to be deleted, but carry on if this fails          - the deletes will just have two reasons to fail instead of one. The same          policy applies if a bad delete should actually happen, though several cases          create their own files and so are isolated */                  if (TEST_PASSED != MakeStdFile(DiskHandle))        {            Result = TEST_FAILED; /* message already displayed */        }        /* Bad CurrentDirectory argument */                /* a file handle that has probably been used */        TryBadDelete (DiskHandle, (void *) 0, STD_FILE_NAME,            "with CurrentDirectory ((void*) 0) (inside file table range)\n", &Result);        /* a file handle that won't have been used unless the Push tests have been run */        TryBadDelete (DiskHandle, (void *) 20, STD_FILE_NAME,            "with CurrentDirectory ((void*) 20) (inside file table range)\n", &Result);                TryBadDelete (DiskHandle, (void *) 10000, STD_FILE_NAME,            "with CurrentDirectory ((void*) 10000) (outside file table range)\n", &Result);            /* try a valid file handle - that isn't a directory or the file itself. Also          try deleting a file that is open */        if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, "OtherFile",                                            STAVFS_WRITE_MODE, FileSize, &FileHandle))        {            STTBX_Print (("Error opening file\n"));            Result = TEST_FAILED;        }        else        {            TryBadDelete (DiskHandle, FileHandle, STD_FILE_NAME,                "with a non-directory open file handle specified for CurrentDirectory", &Result);            TryBadDelete (DiskHandle, STAVFS_NULL_FILE_HANDLE, "OtherFile",                "with a file that is open", &Result);            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, "OtherFile"))            {                STTBX_Print (("Error deleting file\n"));                Result = TEST_FAILED;            }        }        /* NULL and truncated/extended filename */                TryBadDelete (DiskHandle, STAVFS_NULL_FILE_HANDLE, NULL,            "with NULL PathName\n", &Result);                    DelCmpEnd (DiskHandle, &Result);                        /* close and terminate partition, with "device that was open but is now closed/terminated"          tests postponed earlier */                  if (ST_NO_ERROR != STAVFS_Close (DiskHandle))        {            STTBX_Print (("Failed to close partition\n"));            Result = TEST_FAILED;        }        TryBadDelete (DiskHandle, STAVFS_NULL_FILE_HANDLE, STD_FILE_NAME,            "with a device handle that was open but is now closed\n", &Result);        /* try to reopen before terminate in order to make          "was open but now terminated" test a bit more strict */        if (ST_NO_ERROR != STAVFS_Open ("Dev0", &OpenParams, &DiskHandle))        {            STTBX_Print (("Failed to reopen partition\n"));            Result = TEST_FAILED;        }        if (TEST_PASSED != STAVFS_Term ("Dev0", &TermParams))        {            STTBX_Print (("Failed to terminate partition\n"));            Result = TEST_FAILED;        }        TryBadDelete (DiskHandle, STAVFS_NULL_FILE_HANDLE, STD_FILE_NAME,            "with a device handle that was open but is now terminated\n", &Result);    }    return (Result);}/******************************************************************************Function Name : MakeStdFile  Description : Creates (and closes) an empty regular file with allocation STD_FILE_SIZE                and name STD_FILE_NAME, ready for deletion attempts   Parameters : partition handle******************************************************************************/static TestResult_t MakeStdFile(STAVFS_Handle_t DiskHandle){    TestResult_t            Result = TEST_PASSED;    STAVFS_FileHandle_t     FileHandle;        U64 FileSize;    I64_SetValue (STD_FILE_SIZE, 0, FileSize);        if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, STD_FILE_NAME,                                        STAVFS_WRITE_MODE, FileSize, &FileHandle))    {        STTBX_Print (("Error opening file\n"));        Result = TEST_FAILED;    }    else if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle))    {        STTBX_Print (("Error closing file\n"));        Result = TEST_FAILED;    }    return (Result);}/******************************************************************************Function Name : TryBadDelete  Description : Helper for DeleteFile: attempt the indicated bad deletion   Parameters : Partition handle, CurrentDirectory handle, path name (all for STAVFS_Delete),                description to complete error message, place to record test failure******************************************************************************/static void TryBadDelete(STAVFS_Handle_t DiskHandle, STAVFS_FileHandle_t Dir,                         char * PathName, char * Descr, TestResult_t * Result_p){    /* This very simple function helps to shorten FileDelete, make a clearer distinction      between positive and negative logic, and provide a place where you could always      try to create the file first, etc */    if (ST_NO_ERROR == STAVFS_DeleteFile (DiskHandle, Dir, PathName))    {        STTBX_Print (("STAVFS_DeleteFile should fail %s\n", Descr));        *Result_p = TEST_FAILED;    }}/******************************************************************************Function Name : DelCmpLimit  Description : Part of DeleteFile test: check that a file having a full length name                is not deleted by truncated or extended forms of that name.                THIS TEST DEPENDS ON US KNOWING THE CORRECT MAX CHAR LIMIT FOR A FILENAME   Parameters : partition handle, place to record test failure******************************************************************************/static void DelCmpEnd(STAVFS_Handle_t DiskHandle, TestResult_t * Result_p){    STAVFS_FileHandle_t FileHandle;    U64 FileSize;    I64_SetValue (STD_FILE_SIZE, 0, FileSize);    if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, LONG_FILE_NAME,                                        STAVFS_WRITE_MODE, FileSize, &FileHandle))    {        STTBX_Print (("Error opening file with full-length name\n"));        *Result_p = TEST_FAILED;    }    else if (ST_NO_ERROR != STAVFS_CloseFile (FileHandle))    {        STTBX_Print (("Error closing file\n"));        *Result_p = TEST_FAILED;    }    else    {        TryBadDelete (DiskHandle, FileHandle, TRUNC_LONG_FILE_NAME,            "with a truncated form of a full-length file name", Result_p);            /* blind strncmp would give this */        TryBadDelete (DiskHandle, FileHandle, EXT_LONG_FILE_NAME,            "with an extended form of a full-length file name", Result_p);            /* strncmp with wrong size would give this */        if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle,                STAVFS_NULL_FILE_HANDLE, LONG_FILE_NAME))        {            STTBX_Print (("Error deleting file with full-length name\n"));            *Result_p = TEST_FAILED;        }    }    }/******************************************************************************Function Name : GetFreeDiskSpace  Description : API tests for STAVFS_GetFreeDiskSpace   Parameters :******************************************************************************/static TestResult_t GetFreeDiskSpace(int TestNo, TestVariant_t Variant){    TestResult_t        Result = TEST_PASSED;    STAVFS_Handle_t     DiskHandle;    U64 Size;

⌨️ 快捷键说明

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