int32 UT_os_teardown_fs() { OS_unmount(g_mntName); OS_rmfs(g_devName); return (OS_FS_SUCCESS); }
/* ** Name: CFE_ES_InitializeFileSystems ** ** Purpose: This function initializes the file systems used in the cFE core. ** */ void CFE_ES_InitializeFileSystems(uint32 start_type) { int32 RetStatus; uint32 *RamDiskMemoryAddress; uint32 RamDiskMemorySize; int32 BlocksFree; int32 PercentFree; /* ** Get the memory area for the RAM disk */ RetStatus = CFE_PSP_GetVolatileDiskMem(&(RamDiskMemoryAddress), &(RamDiskMemorySize)); if ( RetStatus != OS_FS_SUCCESS ) { CFE_ES_WriteToSysLog("ES Startup: Cannot Get Memory for Volatile Disk. EC = 0x%08X\n",RetStatus); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } /* ** Next, either format, or just initialize the RAM disk depending on ** the reset type */ if ( start_type == CFE_ES_POWERON_RESET ) { RetStatus = OS_mkfs((void *)RamDiskMemoryAddress, "/ramdev0", "RAM", CFE_ES_RAM_DISK_SECTOR_SIZE, CFE_ES_RAM_DISK_NUM_SECTORS ); if ( RetStatus != OS_FS_SUCCESS ) { CFE_ES_WriteToSysLog("ES Startup: Error Creating Volatile(RAM) Volume. EC = 0x%08X\n",RetStatus); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } } else { RetStatus = OS_initfs((void *)RamDiskMemoryAddress, "/ramdev0", "RAM", CFE_ES_RAM_DISK_SECTOR_SIZE, CFE_ES_RAM_DISK_NUM_SECTORS ); if ( RetStatus != OS_FS_SUCCESS ) { CFE_ES_WriteToSysLog("ES Startup: Error Initializing Volatile(RAM) Volume. EC = 0x%08X\n",RetStatus); CFE_ES_WriteToSysLog("ES Startup: Formatting Volatile(RAM) Volume.\n"); RetStatus = OS_mkfs((void *)RamDiskMemoryAddress, "/ramdev0", "RAM", CFE_ES_RAM_DISK_SECTOR_SIZE, CFE_ES_RAM_DISK_NUM_SECTORS ); if ( RetStatus != OS_SUCCESS ) { CFE_ES_WriteToSysLog("ES Startup: Error Creating Volatile(RAM) Volume. EC = 0x%08X\n",RetStatus); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } } } /* ** Now, mount the RAM disk */ RetStatus = OS_mount("/ramdev0", CFE_ES_RAM_DISK_MOUNT_STRING); if ( RetStatus != OS_FS_SUCCESS ) { CFE_ES_WriteToSysLog("ES Startup: Error Mounting Volatile(RAM) Volume. EC = 0x%08X\n",RetStatus); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } /* ** During a Processor reset, if the RAM disk has less than a defined ** amount of free space, reformat and re-mount it. ** The parameter being checked is CFE_ES_RAM_DISK_PERCENT_RESERVED ** Note: When CFE_ES_RAM_DISK_PERCENT_RESERVED is set to 0, this feature is ** disabled. */ if ((start_type == CFE_ES_PROCESSOR_RESET) && (CFE_ES_RAM_DISK_PERCENT_RESERVED > 0)) { /* ** See how many blocks are free in the RAM disk */ BlocksFree = OS_fsBlocksFree(CFE_ES_RAM_DISK_MOUNT_STRING); if ( BlocksFree >= 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_ES_RAM_DISK_NUM_SECTORS ) { BlocksFree = CFE_ES_RAM_DISK_NUM_SECTORS - 1; } /* ** Determine if the disk is too full */ BlocksFree = BlocksFree * 100; PercentFree = BlocksFree / CFE_ES_RAM_DISK_NUM_SECTORS; CFE_ES_WriteToSysLog("Volatile Disk has %d Percent free space.\n",PercentFree); if ( PercentFree < CFE_ES_RAM_DISK_PERCENT_RESERVED ) { CFE_ES_WriteToSysLog("ES Startup: Insufficent Free Space on Volatile Disk, Reformatting.\n"); /* ** First, unmount the disk */ RetStatus = OS_unmount(CFE_ES_RAM_DISK_MOUNT_STRING); if ( RetStatus == OS_FS_SUCCESS ) { /* ** Remove the file system from the OSAL */ RetStatus = OS_rmfs("/ramdev0"); if ( RetStatus == OS_FS_SUCCESS ) { /* ** Next, make a new file system on the disk */ RetStatus = OS_mkfs((void *)RamDiskMemoryAddress, "/ramdev0", "RAM", CFE_ES_RAM_DISK_SECTOR_SIZE, CFE_ES_RAM_DISK_NUM_SECTORS ); if ( RetStatus == OS_FS_SUCCESS ) { /* ** Last, remount the disk */ RetStatus = OS_mount("/ramdev0", CFE_ES_RAM_DISK_MOUNT_STRING); if ( RetStatus != OS_FS_SUCCESS ) { CFE_ES_WriteToSysLog("ES Startup: Error Re-Mounting Volatile(RAM) Volume. EC = 0x%08X\n",RetStatus); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } /* end if mount */ } else { CFE_ES_WriteToSysLog("ES Startup: Error Re-Formating Volatile(RAM) Volume. EC = 0x%08X\n",RetStatus); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } /* end if mkfs */ } else /* could not Remove File system */ { CFE_ES_WriteToSysLog("ES Startup: Error Removing Volatile(RAM) Volume. EC = 0x%08X\n",RetStatus); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } /* end if OS_rmfs */ } else /* could not un-mount disk */ { CFE_ES_WriteToSysLog("ES Startup: Error Un-Mounting Volatile(RAM) Volume. EC = 0x%08X\n",RetStatus); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } } /* end if enough free space */ } 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",BlocksFree); /* ** Delay to allow the message to be read */ OS_TaskDelay(CFE_ES_PANIC_DELAY); /* ** cFE Cannot continue to start up. */ CFE_PSP_Panic(CFE_PSP_PANIC_VOLATILE_DISK); } /* end if BlocksFree */ } /* end if processor reset */ } /* end function */