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

📄 toplevel.c

📁 ST5518机顶盒系统文件系统源代码!绝对超值!
💻 C
📖 第 1 页 / 共 2 页
字号:
                /* hack to get Cluster size; we allocate files that are a multiple of this (infact 1), in                  order to avoid rounding-up problems when we compare the change in FreeDiskSpace reported */	        ClusterSize = ((stavfs_Device_t*)Handle)->ClusterSize;	        I64_SetValue (ClusterSize * DISK_SECTOR_SIZE, 0, FileSize);                for (i=0; i < CNT_FILES; ++i)                {                    if (ST_NO_ERROR != STAVFS_OpenFile (Handle, STAVFS_NULL_FILE_HANDLE, FNames[i],                                        STAVFS_WRITE_MODE, FileSize, &FHandles[i]))                    {                        STTBX_Print (("Error opening file #%i\n", i));                        Result = TEST_FAILED;                        break;                    }                    else if (ST_NO_ERROR != STAVFS_CloseFile (FHandles[i]))                    {                        STTBX_Print (("Error closing file #%i\n", i));                        Result = TEST_FAILED;                        break;                    }                }                /* -> i: count of files created */                /* delete second file (index 1) if it was sucessfully created */                                if (i >= 2 && ST_NO_ERROR != STAVFS_DeleteFile                    (Handle, STAVFS_NULL_FILE_HANDLE, FNames[1]))                {                    STTBX_Print (("Error deleting file #2\n"));                    Result = TEST_FAILED;                }                                /* if all three were sucessfully created, go and check the FreeDiskSpace */                                if (i == CNT_FILES)                {                    if (ST_NO_ERROR != STAVFS_GetFreeDiskSpace (Handle, &Size2))                    {                        STTBX_Print (("Error geting free space (2)\n"));                        Result = TEST_FAILED;                    }                    else                    {                        I64_Sub (Size1, Size2, Diff);                                                /* size to compare against - two files */	                I64_SetValue (2 * ClusterSize * DISK_SECTOR_SIZE, 0, FileSize);                        if (!I64_AreEqual (Diff, FileSize))                        {                            STTBX_Print (("Incorrect free space reported\n"));                            Result = TEST_FAILED;                        }                    }                                        /* Delete third file */                    if (ST_NO_ERROR != STAVFS_DeleteFile (Handle, STAVFS_NULL_FILE_HANDLE, FNames[2]))                    {                        STTBX_Print (("Error deleting file #3\n"));                        Result = TEST_FAILED;                    }                }                /* Delete first file (index 0) if it was created */                if (i >= 1 && ST_NO_ERROR != STAVFS_DeleteFile                        (Handle, STAVFS_NULL_FILE_HANDLE, FNames[0]))                {                    STTBX_Print (("Error deleting file #1\n"));                    Result = TEST_FAILED;                }            }        }        if (ST_NO_ERROR != STAVFS_Term ("Dev1", &TermParams))        {            STTBX_Print (("Termination failed\n"));            Result = TEST_FAILED;        }    }    return (Result);}/******************************************************************************Function Name : PartitionNumbers  Description : Checks the limits on partition numbers                Checks no name   Parameters :******************************************************************************/static TestResult_t PartitionNumbers (int TestNo, TestVariant_t Variant){    TestResult_t Result = TEST_PASSED;    STAVFS_InitParams_t InitParams;    STAVFS_OpenParams_t OpenParams;    STAVFS_TermParams_t TermParams;    strcpy (InitParams.EVTName, EVT_DEVICE_NAME);    strcpy (InitParams.ATAPIName, ATAPI_DEVICE_NAME);    InitParams.Flags = 0;    InitParams.MemoryPartition = system_partition;    InitParams.Protocol = 1;    InitParams.UnitNumber = 0;    OpenParams.Flags = 0;    TermParams.Flags = 0;    InitParams.PartitionNumber = 0XFFFF;    if (ST_NO_ERROR == STAVFS_Init ("bad1", &InitParams))    {        STTBX_Print (("Managed to initialise a bad partition number (-1)\n"));        Result = TEST_FAILED;    }    InitParams.PartitionNumber = 4;    if (ST_NO_ERROR == STAVFS_Init ("bad2", &InitParams))    {        STTBX_Print (("Managed to initialise a bad partition number (4)\n"));        Result = TEST_FAILED;    }    InitParams.PartitionNumber = 2;    if (ST_NO_ERROR == STAVFS_Init ("", &InitParams))    {        STTBX_Print (("Managed to initialise with no device name\n"));        Result = TEST_FAILED;    }    /* this should initialise succesfully */    if (ST_NO_ERROR != STAVFS_Init ("dev", &InitParams))    {        STTBX_Print (("Could not initialise partition\n"));        Result = TEST_FAILED;    }    /* test using the same partition number but new name */    if (ST_NO_ERROR == STAVFS_Init ("dev2", &InitParams))    {        STTBX_Print (("Managed to repeat-initialise a partition with a new name\n"));        Result = TEST_FAILED;    }    /* test using the same name but diff partition number */    InitParams.PartitionNumber = 1;    if (ST_NO_ERROR == STAVFS_Init ("dev", &InitParams))    {        STTBX_Print (("Managed to initialise a partition with used name\n"));        Result = TEST_FAILED;    }    if (ST_NO_ERROR != STAVFS_Term ("dev", &TermParams))    {	STTBX_Print (("Termination failed\n"));	Result = TEST_FAILED;    }    return (Result);}/******************************************************************************Function Name : Resetting  Description : Tests the partition resetting function (reseting the file table)   Parameters :******************************************************************************/static TestResult_t Resetting (int TestNo, TestVariant_t Variant){    TestResult_t Result = TEST_PASSED;    STAVFS_InitParams_t InitParams;    STAVFS_OpenParams_t OpenParams;    STAVFS_TermParams_t TermParams;    STAVFS_Handle_t Handle = 0;    strcpy (InitParams.EVTName, EVT_DEVICE_NAME);    strcpy (InitParams.ATAPIName, ATAPI_DEVICE_NAME);    InitParams.Flags = 0;    InitParams.MemoryPartition = system_partition;    InitParams.Protocol = 1;    InitParams.UnitNumber = 0;    OpenParams.Flags = 0;    TermParams.Flags = 0;    InitParams.PartitionNumber = 1;    /* device not initialised */    if(ST_NO_ERROR == STAVFS_ResetPartition (Handle))    {        STTBX_Print(("Bad handle accepted\n"));	Result = TEST_FAILED;    }     /* This should initialise succesfully */    if (ST_NO_ERROR != STAVFS_Init ("dev", &InitParams))    {        STTBX_Print (("Could not initialise partition\n"));        Result = TEST_FAILED;    }    if (ST_NO_ERROR != STAVFS_Open ("dev", &OpenParams, &Handle))    {         STTBX_Print (("Opening a volume on the device failed\n"));	 Result = TEST_FAILED;    }    else    {        STAVFS_FileHandle_t FHandle;        U64 FileSize;        U64 FreeSpace;        U64 OriginalFreeSpace;	if (ST_NO_ERROR != STAVFS_GetFreeDiskSpace (Handle, &OriginalFreeSpace))	{	     STTBX_Print (("Error geting free space\n"));	     Result = TEST_FAILED;	}        /* Create a file */	I64_SetValue (40, 0, FileSize);        if (ST_NO_ERROR != STAVFS_OpenFile (Handle, STAVFS_NULL_FILE_HANDLE, "testing",                STAVFS_WRITE_MODE, FileSize, &FHandle))        {            STTBX_Print (("Error opening file\n"));            Result = TEST_FAILED;        }	else	{	    /* file is open */	    if(ST_NO_ERROR == STAVFS_ResetPartition (Handle))	    {	        STTBX_Print(("Reset table with open files\n"));	        Result = TEST_FAILED;	    } 		    if (ST_NO_ERROR != STAVFS_CloseFile (FHandle))	    {	        STTBX_Print (("Error closing\n"));	        Result = TEST_FAILED;	    }	    /* Should reset */	    if(ST_NO_ERROR != STAVFS_ResetPartition (Handle))	    {	        STTBX_Print(("Unable to reset the partition\n"));	        Result = TEST_FAILED;	    }	    else	    {	        if (ST_NO_ERROR != STAVFS_GetFreeDiskSpace (Handle, &FreeSpace))	        {	             STTBX_Print (("Error geting free space\n"));	             Result = TEST_FAILED;	        }	        if (INT_I64_AreNotEqual(OriginalFreeSpace, FreeSpace))	        {	             STTBX_Print(("The amount of free space in the partition is unexpected (%X:%X) (%X:%X)\n",                                  FreeSpace,                                  OriginalFreeSpace));	             Result = TEST_FAILED;	        }	    }	}    }    if (ST_NO_ERROR != STAVFS_Term ("dev", &TermParams))    {	STTBX_Print (("Termination failed\n"));	Result = TEST_FAILED;    }    return (Result);}/******************************************************************************Function Name : Closing  Description : Tests closing and terminating a device   Parameters :******************************************************************************/static TestResult_t Closing (int TestNo, TestVariant_t Variant){    TestResult_t Result = TEST_PASSED;    STAVFS_InitParams_t InitParams;    STAVFS_OpenParams_t OpenParams;    STAVFS_TermParams_t TermParams;    STAVFS_Handle_t Handle = 0;    strcpy (InitParams.EVTName, EVT_DEVICE_NAME);    strcpy (InitParams.ATAPIName, ATAPI_DEVICE_NAME);    InitParams.Flags = 0;    InitParams.MemoryPartition = system_partition;    InitParams.Protocol = 1;    InitParams.UnitNumber = 0;    OpenParams.Flags = 0;    TermParams.Flags = 0;    InitParams.PartitionNumber = 2;    /* Uninitialised device */    if (ST_NO_ERROR == STAVFS_Term ("dev", &TermParams))    {	STTBX_Print (("Managed to terminate an unititialised device\n"));	Result = TEST_FAILED;    }    /* This should initialise succesfully */    if (ST_NO_ERROR != STAVFS_Init ("dev", &InitParams))    {        STTBX_Print (("Could not initialise partition\n"));        Result = TEST_FAILED;    }    /* Unopen device */    if(ST_NO_ERROR == STAVFS_Close (Handle))    {	STTBX_Print(("Managed to close an unopen device\n"));	Result = TEST_FAILED;    }        if (ST_NO_ERROR != STAVFS_Open ("dev", &OpenParams, &Handle))    {         STTBX_Print (("Opening a volume on the device failed\n"));	 Result = TEST_FAILED;    }    else    {            STAVFS_FileHandle_t FHandle;            U64 FileSize;            /* Create a file */	    I64_SetValue (40, 0, FileSize);            if (ST_NO_ERROR != STAVFS_OpenFile (Handle, STAVFS_NULL_FILE_HANDLE, "testing",                    STAVFS_WRITE_MODE, FileSize, &FHandle))            {                STTBX_Print (("Error opening file\n"));                Result = TEST_FAILED;            }	    else	    {		/* file is open - but should still successfully close */		if(ST_NO_ERROR != STAVFS_Close (Handle))		{		    STTBX_Print(("Device could not close with files still open\n"));		    Result = TEST_FAILED;		} 			    		/* Now reopen the device */		if (ST_NO_ERROR != STAVFS_Open ("dev", &OpenParams, &Handle))		{		    STTBX_Print (("Opening a volume on the device failed\n"));		    Result = TEST_FAILED;		}	    }	    if (ST_NO_ERROR != STAVFS_OpenFile (Handle, STAVFS_NULL_FILE_HANDLE, "testing",                    STAVFS_WRITE_MODE, FileSize, &FHandle))            {                STTBX_Print (("Error opening file\n"));                Result = TEST_FAILED;     		/* Clean up */		if (ST_NO_ERROR != STAVFS_Term ("dev", &TermParams))		{		    STTBX_Print (("Opening a volume on the device failed\n"));		    Result = TEST_FAILED;		}            }	    else	    {		/* Terminating device with open files should work OK */		if (ST_NO_ERROR != STAVFS_Term ("dev", &TermParams))		{		    STTBX_Print (("Opening a volume on the device failed\n"));		    Result = TEST_FAILED;		}		/* Terminating the same device twice */		if (ST_NO_ERROR == STAVFS_Term ("dev", &TermParams))		{		    STTBX_Print (("Managed to terminate the partition twice\n"));		    Result = TEST_FAILED;		}	    }            /* this will leave file "testing" on the partition */    }    return (Result);}

⌨️ 快捷键说明

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