📄 partitio.c
字号:
/****************************************************************************** File Name : partitio.c Description : Unit test for the partition API calls.******************************************************************************//* Includes ---------------------------------------------------------------- */#include <stdlib.h>#include <stdio.h>#include <ctype.h>#include <string.h>#include "wrapper.h"#include "stavfs.h"#include "hal.h"/* Private Types ----------------------------------------------------------- *//* Private Constants ------------------------------------------------------- *//* Private Variables ------------------------------------------------------- *//* Private Macros ---------------------------------------------------------- *//* Private Function Prototypes --------------------------------------------- */static TestResult_t EmptyPartitionTable (int TestNo, TestVariant_t Variant);static ST_ErrorCode_t STAVFS_ClearDisk (ST_DeviceName_t EVTName, ST_DeviceName_t ATAPIName, U16 UnitNumber, U16 Protocol);/* Functions --------------------------------------------------------------- *//******************************************************************************Function Name : Partition Description : Partition test section function. Parameters :******************************************************************************/BOOL Partition (parse_t * pars_p, char *result_sym_p){ char *Description = "Unit Test for Development Support"; TestCall_t TestList[] = { EmptyPartitionTable, /* Test 001 */ }; GenericTest (pars_p, result_sym_p, Description, TestList, TABLE_LEN(TestList)-1, TEST_VARIANT_A); return (FALSE);}/******************************************************************************Function Name : EmptyPartitionTable Description : Creates an empty partition table. Parameters :******************************************************************************/static TestResult_t EmptyPartitionTable (int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; ST_DeviceName_t EVTName; ST_DeviceName_t ATAPIName; U16 UnitNumber = 0; U16 Protocol = 1; strcpy (EVTName, EVT_DEVICE_NAME); strcpy (ATAPIName, ATAPI_DEVICE_NAME); /* scramble the first few sectors */ if (ST_NO_ERROR != STAVFS_ClearDisk (EVTName, ATAPIName, UnitNumber, Protocol)) { STTBX_Print(("Could not clear the fist few sectors\n")); Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_CreateEmptyPartitionTable (EVTName, ATAPIName, UnitNumber, Protocol)) { STTBX_Print(("Could not create an empty partition table\n")); Result = TEST_FAILED; } return (Result);}/*******************************************************************Function Name : ClearDisk Description : Sets the first few sectors of the disk to FF so that the formating can be tested properly. Parameters : *******************************************************************/static ST_ErrorCode_t STAVFS_ClearDisk (ST_DeviceName_t EVTName, ST_DeviceName_t ATAPIName, U16 UnitNumber, U16 Protocol){ ST_ErrorCode_t Error = ST_NO_ERROR; stavfs_HAL_t Obj; Obj.Initialised = FALSE; Obj.Protocol = Protocol; Obj.UnitNumber = UnitNumber; strcpy (Obj.EVTName, EVTName); strcpy (Obj.ATAPIName, ATAPIName); if (ST_NO_ERROR != (Error = stavfs_HalInit (&Obj))) { STTBX_Print (("Error when opening a HAL device\n")); } else { char Buffer[DISK_SECTOR_SIZE]; U64 LBA64; int i; I64_SetValue (0, 0, LBA64); /* Set buffer to FF */ for (i = 0; i < DISK_SECTOR_SIZE; i++) { Buffer[i] = 0xFF; } /* Write the table back to the disk */ if (ST_NO_ERROR != (Error = stavfs_HalWrite (&Obj, &LBA64, 1, Buffer, FALSE))) { STTBX_Print (("Unable to write to the partition table\n")); Error = STAVFS_ERROR_UNWRITABLE_DISK; } I64_SetValue (1, 0, LBA64); if (ST_NO_ERROR != (Error = stavfs_HalWrite (&Obj, &LBA64, 1, Buffer, FALSE))) { STTBX_Print (("Unable to write to the partition table\n")); Error = STAVFS_ERROR_UNWRITABLE_DISK; } if (ST_NO_ERROR != (Error = stavfs_HalTerm (&Obj))) { STTBX_Print (("Failed to closed HAL device\n")); } } return (Error);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -