📄 utilapi.c
字号:
/****************************************************************************** File Name : utilapi.c Description : API test for 'utility' functions (fsck, defrag)******************************************************************************//* Includes ---------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <string.h>#include <assert.h>#include "wrapper.h" /* from ../utils. Uses ../../src */#include "apicomm.h"#include "stavfs.h"/* Private Types ----------------------------------------------------------- *//* Private Constants ------------------------------------------------------- */#define STD_DEV_NAME "GoodDevName" /* standard device name used in normal situations */ #define BOGUS_DEV_NAME "bogus" /* no device ever initialised with this name */ #define LONG_DEV_NAME "ThisIsALongWrongName" /* overlong bogus name to confirm no bad copying occurs before compare */ /* Private Variables ------------------------------------------------------- *//* Private Macros ---------------------------------------------------------- *//* Private Function Prototypes --------------------------------------------- */static TestResult_t Abort (int TestNo, TestVariant_t Variant);static TestResult_t FileSystemCheck (int TestNo, TestVariant_t Variant);static TestResult_t Defrag (int TestNo, TestVariant_t Variant);static void TryBadFSCK (char * DevName, STAVFS_FSCKMode_t Flags, char * Descr, TestResult_t * Result_p); /* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : UtilityAPI Description : Utility api test section function Parameters :******************************************************************************/BOOL UtilityAPI(parse_t * pars_p, char *result_sym_p){ char *Description = "Utility API tests"; TestCall_t TestList[] = { Abort, /* Test 001 */ FileSystemCheck, /* Test 002 */ Defrag, /* Test 003 */ }; GenericTest (pars_p, result_sym_p, Description, TestList, TABLE_LEN(TestList)-1, TEST_VARIANT_A); return (FALSE);}/******************************************************************************Function Name : Abort Description : API tests for STAVFS_Abort Parameters :******************************************************************************/static TestResult_t Abort(int TestNo, TestVariant_t Variant){ /* interface is not yet complete/stable */ return (TEST_NOT_WRITTEN);}/******************************************************************************Function Name : FileSystemCheck Description : API tests for STAVFS_FileSystemCheck Parameters :******************************************************************************/static TestResult_t FileSystemCheck(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 DiskHandle; TryBadFSCK (STD_DEV_NAME, 0, "with uninitialised device (and possibly uninitialised driver too)", &Result); /* give the remaining 'bad name' tests one valid name to compare against */ 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; InitParams.PartitionNumber = 3; /* work on partition 3 as out of main use and quickest to check */ OpenParams.Flags = 0; TermParams.Flags = 0; if (ST_NO_ERROR != STAVFS_Init (STD_DEV_NAME, &InitParams)) { STTBX_Print (("Error initialising unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; } else { TryBadFSCK (NULL, 0, "with NULL device name", &Result); TryBadFSCK (LONG_DEV_NAME, 0, "with overlong device name", &Result); TryBadFSCK (BOGUS_DEV_NAME, 0, "with device name that has never been initialised", &Result); /* device that is open ... */ if (ST_NO_ERROR != STAVFS_Open (STD_DEV_NAME, &OpenParams, &DiskHandle)) { STTBX_Print (("Error opening unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; } else { TryBadFSCK (BOGUS_DEV_NAME, 0, "with device that is open", &Result); /* go straight to Term ... */ } if (ST_NO_ERROR != STAVFS_Term (STD_DEV_NAME, &TermParams)) { STTBX_Print (("Error terminating unit %i partition %i\n", InitParams.UnitNumber, InitParams.PartitionNumber)); Result = TEST_FAILED; /* name should still end up invalid even if this fails, so go on with the final test regardless... */ } TryBadFSCK (STD_DEV_NAME, 0, "with device (identified by name) that has been terminated", &Result); } return (Result);}/******************************************************************************Function Name : TryBadFSCK Description : Helper for FileSystemCheck test: try a FileSystemCheck that should fail. Parameters : device name and Flags (for STAVFS_DeletePartition), description to complete error message, place to record test failure******************************************************************************/static void TryBadFSCK(char * DevName, STAVFS_FSCKMode_t Flags, char * Descr, TestResult_t * Result_p){ if (ST_NO_ERROR == STAVFS_FileSystemCheck (DevName, Flags)) { STTBX_Print(("STAVFS_FileSystemCheck should fail %s\n", Descr)); *Result_p = TEST_FAILED; }}/******************************************************************************Function Name : Defrag Description : API tests for STAVFS_FileSystemDefragmentation Parameters :******************************************************************************/static TestResult_t Defrag(int TestNo, TestVariant_t Variant){ /* interface is not yet complete/stable */ return (TEST_NOT_WRITTEN);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -