diff --git a/fsw/cfe-core/src/es/cfe_es_start.c b/fsw/cfe-core/src/es/cfe_es_start.c index 2a883ef13..560fc259d 100644 --- a/fsw/cfe-core/src/es/cfe_es_start.c +++ b/fsw/cfe-core/src/es/cfe_es_start.c @@ -494,11 +494,11 @@ void CFE_ES_SetupResetVariables(uint32 StartType, uint32 StartSubtype, uint32 Bo */ void CFE_ES_InitializeFileSystems(uint32 StartType) { - int32 RetStatus; - cpuaddr RamDiskMemoryAddress; - uint32 RamDiskMemorySize; - int32 BlocksFree; - int32 PercentFree; + int32 RetStatus; + cpuaddr RamDiskMemoryAddress; + uint32 RamDiskMemorySize; + int32 PercentFree; + OS_statvfs_t StatBuf; /* ** Get the memory area for the RAM disk @@ -601,25 +601,13 @@ void CFE_ES_InitializeFileSystems(uint32 StartType) /* ** See how many blocks are free in the RAM disk */ - BlocksFree = OS_fsBlocksFree(CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING); - if ( BlocksFree >= 0 ) + RetStatus = OS_FileSysStatVolume(CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING, &StatBuf); + if ( RetStatus == OS_SUCCESS && StatBuf.total_blocks > 0 ) { - /* - ** Need a sanity check for the desktop systems. - ** Because the desktop ports map the volatile disk to the host - ** hard disk, it will report more free blocks than the defined number - ** of sectors ( blocks ). Therefore it must be truncated. - */ - if ( BlocksFree > CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS ) - { - BlocksFree = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS - 1; - } - /* ** Determine if the disk is too full */ - BlocksFree = BlocksFree * 100; - PercentFree = BlocksFree / CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS; + PercentFree = (StatBuf.blocks_free * 100) / StatBuf.total_blocks; CFE_ES_WriteToSysLog("Volatile Disk has %d Percent free space.\n",(int)PercentFree); if ( PercentFree < CFE_PLATFORM_ES_RAM_DISK_PERCENT_RESERVED ) @@ -721,7 +709,7 @@ void CFE_ES_InitializeFileSystems(uint32 StartType) else /* could not determine free blocks */ { /* Log error message -- note that BlocksFree returns the error code in this case */ - CFE_ES_WriteToSysLog("ES Startup: Error Determining Blocks Free on Volume. EC = 0x%08X\n",(unsigned int)BlocksFree); + CFE_ES_WriteToSysLog("ES Startup: Error Determining Blocks Free on Volume. EC = 0x%08X\n",(unsigned int)RetStatus); /* ** Delay to allow the message to be read @@ -983,4 +971,3 @@ int32 CFE_ES_MainTaskSyncDelay(uint32 AppStateId, uint32 TimeOutMilliseconds) return Status; } - diff --git a/fsw/cfe-core/unit-test/es_UT.c b/fsw/cfe-core/unit-test/es_UT.c index 2190e3851..bff84dc8b 100644 --- a/fsw/cfe-core/unit-test/es_UT.c +++ b/fsw/cfe-core/unit-test/es_UT.c @@ -711,6 +711,7 @@ void TestStartupErrorPaths(void) ES_UT_SetAppStateHook_t StateHook; uint32 PanicStatus; uint32 ResetType; + OS_statvfs_t StatBuf; CFE_ES_TaskRecord_t *TaskRecPtr; CFE_ES_AppRecord_t *AppRecPtr; @@ -886,6 +887,11 @@ void TestStartupErrorPaths(void) "CFE_ES_InitializeFileSystems", "Power on reset; error creating volatile (RAM) volume"); + /* prepare the StatBuf to reflect a RAM disk that is 99% full */ + StatBuf.block_size = 1024; + StatBuf.total_blocks = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS; + StatBuf.blocks_free = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS / 100; + /* Test initialization of the file systems specifying a processor reset * following a failure to reformat the RAM volume */ @@ -893,6 +899,7 @@ void TestStartupErrorPaths(void) UT_SetDefaultReturnValue(UT_KEY(OS_initfs), OS_ERROR); UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR); UT_SetDefaultReturnValue(UT_KEY(OS_mkfs), OS_ERROR); + UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false); CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) && @@ -909,6 +916,7 @@ void TestStartupErrorPaths(void) */ ES_ResetUnitTest(); UT_SetDefaultReturnValue(UT_KEY(CFE_PSP_GetVolatileDiskMem), CFE_PSP_ERROR); + UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false); CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) && @@ -916,24 +924,12 @@ void TestStartupErrorPaths(void) "CFE_ES_InitializeFileSystems", "Processor reset; cannot get memory for volatile disk"); - /* Test initialization of the file systems where the number of free blocks - * reported is greater than the number of RAM disk sectors - */ - ES_ResetUnitTest(); - UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR); - UT_SetDeferredRetcode(UT_KEY(OS_fsBlocksFree), 1, CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS + 1); - CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR); - UT_Report(__FILE__, __LINE__, - UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_MOUNT_VOLATILE]) && - UT_GetStubCount(UT_KEY(OS_printf)) == 2, - "CFE_ES_InitializeFileSystems", - "Processor reset; truncate free block count"); - /* Test initialization of the file systems specifying a processor reset * following a failure to remove the RAM volume */ ES_ResetUnitTest(); UT_SetDefaultReturnValue(UT_KEY(OS_rmfs), OS_ERROR); + UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false); CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) && @@ -947,6 +943,7 @@ void TestStartupErrorPaths(void) */ ES_ResetUnitTest(); UT_SetDeferredRetcode(UT_KEY(OS_unmount), 1, -1); + UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false); CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) && @@ -968,6 +965,7 @@ void TestStartupErrorPaths(void) */ ES_ResetUnitTest(); UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR); + UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false); CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) && @@ -981,7 +979,7 @@ void TestStartupErrorPaths(void) * number of blocks that are free on the volume */ ES_ResetUnitTest(); - UT_SetDeferredRetcode(UT_KEY(OS_fsBlocksFree), 1, -1); + UT_SetDeferredRetcode(UT_KEY(OS_FileSysStatVolume), 1, -1); CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_DETERMINE_BLOCKS]) && @@ -1106,6 +1104,7 @@ void TestStartupErrorPaths(void) ES_ResetUnitTest(); UT_SetDefaultReturnValue(UT_KEY(OS_initfs), OS_ERROR); UT_SetDefaultReturnValue(UT_KEY(OS_mount), OS_ERROR); + UT_SetDataBuffer(UT_KEY(OS_FileSysStatVolume), &StatBuf, sizeof(StatBuf), false); CFE_ES_InitializeFileSystems(CFE_PSP_RST_TYPE_PROCESSOR); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_INSUFF_FREE_SPACE]) &&