diff --git a/cfe/fsw/cfe-core/src/tbl/cfe_tbl_internal.c b/cfe/fsw/cfe-core/src/tbl/cfe_tbl_internal.c index 9c0869c75..0c1e1d7cb 100644 --- a/cfe/fsw/cfe-core/src/tbl/cfe_tbl_internal.c +++ b/cfe/fsw/cfe-core/src/tbl/cfe_tbl_internal.c @@ -41,6 +41,7 @@ #include "cfe_psp.h" #include #include +#include /******************************************************************* ** @@ -947,18 +948,113 @@ int32 CFE_TBL_LoadFromFile(CFE_TBL_LoadBuff_t *WorkingBufferPtr, uint32 NumBytes; uint8 ExtraByte; + char TblDiskPath[OS_MAX_PATH_LEN]; + char FileNameOnly[OS_MAX_PATH_LEN]; + char GzFilePath[OS_MAX_PATH_LEN]; + size_t StringLength; + boolean IsGzFile = FALSE; + int32 TblGzFd; + uint32 i; + if (FilenameLen > (OS_MAX_PATH_LEN-1)) { Status = CFE_TBL_ERR_FILENAME_TOO_LONG; } else { - /* Try to open the specified table file */ - FileDescriptor = OS_open(Filename, OS_READ_ONLY, 0); + /* + ** Try to Open zipped the table file. + */ + snprintf(GzFilePath, sizeof(GzFilePath), "%s.gz", Filename); + TblGzFd = OS_open( (const char *)GzFilePath, O_RDONLY, 0); + + /* + ** Check to see if the code is a Gzip file + */ + if ( TblGzFd >= 0 ) + { + /* + ** Close file if it is available. + */ + OS_close(TblGzFd); + + /* + ** Build up the destination path in the RAM disk + */ + (void) CFE_SB_MessageStringGet(TblDiskPath, + CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING"/", + NULL, + sizeof(TblDiskPath), + sizeof(CFE_PLATFORM_ES_RAM_DISK_MOUNT_STRING"/")); + + /* + ** Extract the filename from the path + */ + Status = CFE_FS_ExtractFilenameFromPath(GzFilePath, FileNameOnly); + + if ( Status == CFE_SUCCESS ) + { + if ((strlen(TblDiskPath) + strlen(FileNameOnly)) < OS_MAX_PATH_LEN) + { + /* + ** Cat the Filename to the RamDiskPath + */ + strcat(TblDiskPath, FileNameOnly); + + /* + ** Remove the ".gz" prefix from the filename + ** Already Determined that the filename ends in ".gz" + */ + StringLength = strlen(TblDiskPath); + TblDiskPath[StringLength - 3] = '\0'; + + /* + ** Decompress the file: + */ + Status = CFE_FS_Decompress(GzFilePath, TblDiskPath); + + if ( Status != OS_SUCCESS ) + { + CFE_ES_WriteToSysLog("CFE_TBL: Unable to decompress Table File: %s , EC = 0x%08X\n", GzFilePath, Status); + + return(CFE_TBL_ERR_LOAD_INCOMPLETE); + } + else + { + IsGzFile = TRUE; + } + + } + else + { + /* Can't include the name string since it could be too long for the message */ + CFE_ES_WriteToSysLog("CFE_TBL: Table path plus file name length (%d) exceeds max allowed (%d)\n", + (int)(strlen(TblDiskPath) + strlen(FileNameOnly)), OS_MAX_PATH_LEN); + + + return(CFE_TBL_ERR_LOAD_INCOMPLETE); + } + + } + else + { + CFE_ES_WriteToSysLog("CFE_TBL: Unable to extract filename from path: %s EC = 0x%08X.\n",GzFilePath, Status); + return(CFE_TBL_ERR_LOAD_INCOMPLETE); + } + + } + else + { + /* Try to open the specified table file */ + strncpy(TblDiskPath, (const char *) Filename, (size_t) sizeof(TblDiskPath)); + } + + /* Try to open the specified table file */ + FileDescriptor = OS_open(TblDiskPath, OS_READ_ONLY, 0); if (FileDescriptor >= 0) { - Status = CFE_TBL_ReadHeaders(FileDescriptor, &StdFileHeader, &TblFileHeader, Filename); + Status = CFE_TBL_ReadHeaders(FileDescriptor, &StdFileHeader, &TblFileHeader, TblDiskPath); if (Status == CFE_SUCCESS) { @@ -1002,7 +1098,7 @@ int32 CFE_TBL_LoadFromFile(CFE_TBL_LoadBuff_t *WorkingBufferPtr, } memset(WorkingBufferPtr->DataSource, 0, OS_MAX_PATH_LEN); - strncpy(WorkingBufferPtr->DataSource, Filename, OS_MAX_PATH_LEN); + strncpy(WorkingBufferPtr->DataSource, TblDiskPath, OS_MAX_PATH_LEN); /* Save file creation time for later storage into Registry */ WorkingBufferPtr->FileCreateTimeSecs = StdFileHeader.TimeSeconds; @@ -1028,6 +1124,20 @@ int32 CFE_TBL_LoadFromFile(CFE_TBL_LoadBuff_t *WorkingBufferPtr, /* Return error code obtained from OS_open */ Status = FileDescriptor; } + + /* + ** Remove the temporary RAM disk file + */ + if ( IsGzFile == TRUE ) + { + Status = OS_remove(TblDiskPath); + + if (Status != OS_SUCCESS) + { + CFE_ES_WriteToSysLog("CFE_TBL: Error removing temp RAM disk file, EC = 0x%08X\n", + (unsigned int) Status); + } + } } return Status; diff --git a/osal/src/os/posix/osfileapi.c b/osal/src/os/posix/osfileapi.c index 722eb8259..9e76a3821 100644 --- a/osal/src/os/posix/osfileapi.c +++ b/osal/src/os/posix/osfileapi.c @@ -1263,6 +1263,14 @@ int32 OS_check_name_length(const char *path) */ name_ptr ++; + /* + * Discard Gzip file extension. + */ + if(!strcmp(strrchr(name_ptr, '.'), ".gz")) + { + name_ptr+=3; + } + /* * Reject paths whose final component is too long. */ diff --git a/osal/src/os/rtems/osfileapi.c b/osal/src/os/rtems/osfileapi.c index afd721366..bc45061bf 100644 --- a/osal/src/os/rtems/osfileapi.c +++ b/osal/src/os/rtems/osfileapi.c @@ -1359,6 +1359,14 @@ int32 OS_check_name_length(const char *path) */ name_ptr ++; + /* + * Discard Gzip file extension. + */ + if(!strcmp(strrchr(name_ptr, '.'), ".gz")) + { + name_ptr+=3; + } + /* * Reject paths whose final component is too long. */