Skip to content

Commit

Permalink
Merge pull request nasa#895 from jphickey/fix-893-osal-open-create
Browse files Browse the repository at this point in the history
Fix nasa#893, replace calls to OS_open and OS_creat
  • Loading branch information
yammajamma authored Sep 24, 2020
2 parents ce187a2 + 06e0a63 commit 56254e9
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 114 deletions.
6 changes: 2 additions & 4 deletions fsw/cfe-core/src/es/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
/*
** Open the file in the volatile disk.
*/
Status = OS_open( CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE, OS_READ_ONLY, 0);
Status = OS_OpenCreate(&AppFile, CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE, OS_FILE_FLAG_NONE, OS_READ_ONLY);

if ( Status >= 0 )
{
CFE_ES_WriteToSysLog ("ES Startup: Opened ES App Startup file: %s\n",
CFE_PLATFORM_ES_VOLATILE_STARTUP_FILE);
FileOpened = true;
AppFile = OS_ObjectIdFromInteger(Status);
}
else
{
Expand All @@ -120,13 +119,12 @@ void CFE_ES_StartApplications(uint32 ResetType, const char *StartFilePath )
/*
** Try to Open the file passed in to the cFE start.
*/
Status = OS_open( (const char *)StartFilePath, OS_READ_ONLY, 0);
Status = OS_OpenCreate(&AppFile, StartFilePath, OS_FILE_FLAG_NONE, OS_READ_ONLY);

if ( Status >= 0 )
{
CFE_ES_WriteToSysLog ("ES Startup: Opened ES App Startup file: %s\n",StartFilePath);
FileOpened = true;
AppFile = OS_ObjectIdFromInteger(Status);
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions fsw/cfe-core/src/es/cfe_es_erlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool CFE_ES_RunERLogDump(uint32 ElapsedTime, void *Arg)
}

FileSize = 0;
Status = OS_creat(State->DataFileName, OS_WRITE_ONLY);
Status = OS_OpenCreate(&fd, State->DataFileName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
if(Status < 0)
{
CFE_EVS_SendEvent(CFE_ES_ERLOG2_ERR_EID,CFE_EVS_EventType_ERROR,
Expand All @@ -216,7 +216,6 @@ bool CFE_ES_RunERLogDump(uint32 ElapsedTime, void *Arg)
}
else
{
fd = OS_ObjectIdFromInteger(Status);
CFE_FS_InitHeader(&FileHdr, CFE_ES_ER_LOG_DESC, CFE_FS_SubType_ES_ERLOG);

/* write the cFE header to the file */
Expand Down
9 changes: 3 additions & 6 deletions fsw/cfe-core/src/es/cfe_es_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,9 @@ bool CFE_ES_RunPerfLogDump(uint32 ElapsedTime, void *Arg)
{
case CFE_ES_PerfDumpState_OPEN_FILE:
/* Create the file to dump to */
Status = OS_creat(State->DataFileName, OS_WRITE_ONLY);
if (Status >= 0)
{
State->FileDesc = OS_ObjectIdFromInteger(Status);
}
else
Status = OS_OpenCreate(&State->FileDesc, State->DataFileName,
OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
if (Status < 0)
{
State->FileDesc = OS_OBJECT_ID_UNDEFINED;
CFE_EVS_SendEvent(CFE_ES_PERF_LOG_ERR_EID,CFE_EVS_EventType_ERROR,
Expand Down
4 changes: 1 addition & 3 deletions fsw/cfe-core/src/es/cfe_es_syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ int32 CFE_ES_SysLogDump(const char *Filename)
CFE_FS_Header_t FileHdr;
} Buffer;

Status = OS_creat(Filename, OS_WRITE_ONLY);
Status = OS_OpenCreate(&fd, Filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
if(Status < 0)
{
CFE_EVS_SendEvent(CFE_ES_SYSLOG2_ERR_EID,CFE_EVS_EventType_ERROR,
Expand All @@ -488,8 +488,6 @@ int32 CFE_ES_SysLogDump(const char *Filename)
return CFE_ES_FILE_IO_ERR;
}/* end if */

fd = OS_ObjectIdFromInteger(Status);

CFE_FS_InitHeader(&Buffer.FileHdr, CFE_ES_SYS_LOG_DESC, CFE_FS_SubType_ES_SYSLOG);

TotalSize = 0;
Expand Down
25 changes: 12 additions & 13 deletions fsw/cfe-core/src/es/cfe_es_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1194,21 +1194,21 @@ int32 CFE_ES_QueryAllCmd(const CFE_ES_QueryAll_t *data)
/*
** Check to see if the file already exists
*/
Result = OS_open(QueryAllFilename, OS_READ_ONLY, 0);
Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename,
OS_FILE_FLAG_NONE, OS_READ_ONLY);
if (Result >= 0)
{
FileDescriptor = OS_ObjectIdFromInteger(Result);
OS_close(FileDescriptor);
OS_remove(QueryAllFilename);
}

/*
** Create ES task log data file
*/
Result = OS_creat(QueryAllFilename, OS_WRITE_ONLY);
Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename,
OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
if (Result >= 0)
{
FileDescriptor = OS_ObjectIdFromInteger(Result);
/*
** Initialize cFE file header
*/
Expand Down Expand Up @@ -1292,7 +1292,7 @@ int32 CFE_ES_QueryAllCmd(const CFE_ES_QueryAll_t *data)
{
CFE_ES_TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_OSCREATE_ERR_EID, CFE_EVS_EventType_ERROR,
"Failed to write App Info file, OS_creat RC = 0x%08X",(unsigned int)Result);
"Failed to write App Info file, OS_OpenCreate RC = 0x%08X",(unsigned int)Result);
}

return CFE_SUCCESS;
Expand Down Expand Up @@ -1325,21 +1325,21 @@ int32 CFE_ES_QueryAllTasksCmd(const CFE_ES_QueryAllTasks_t *data)
/*
** Check to see if the file already exists
*/
Result = OS_open(QueryAllFilename, OS_READ_ONLY, 0);
Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename,
OS_FILE_FLAG_NONE, OS_READ_ONLY);
if (Result >= 0)
{
FileDescriptor = OS_ObjectIdFromInteger(Result);
OS_close(FileDescriptor);
OS_remove(QueryAllFilename);
}

/*
** Create ES task log data file
*/
Result = OS_creat(QueryAllFilename, OS_WRITE_ONLY);
Result = OS_OpenCreate(&FileDescriptor, QueryAllFilename,
OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
if (Result >= 0)
{
FileDescriptor = OS_ObjectIdFromInteger(Result);
/*
** Initialize cFE file header
*/
Expand Down Expand Up @@ -1423,7 +1423,7 @@ int32 CFE_ES_QueryAllTasksCmd(const CFE_ES_QueryAllTasks_t *data)
{
CFE_ES_TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_TASKINFO_OSCREATE_ERR_EID, CFE_EVS_EventType_ERROR,
"Failed to write Task Info file, OS_creat RC = 0x%08X",(unsigned int)Result);
"Failed to write Task Info file, OS_OpenCreate RC = 0x%08X",(unsigned int)Result);
}

return CFE_SUCCESS;
Expand Down Expand Up @@ -1803,12 +1803,11 @@ int32 CFE_ES_DumpCDSRegistryCmd(const CFE_ES_DumpCDSRegistry_t *data)
OS_MAX_PATH_LEN, sizeof(CmdPtr->DumpFilename));

/* Create a new dump file, overwriting anything that may have existed previously */
Status = OS_creat(DumpFilename, OS_WRITE_ONLY);
Status = OS_OpenCreate(&FileDescriptor, DumpFilename,
OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);

if (Status >= OS_SUCCESS)
{
FileDescriptor = OS_ObjectIdFromInteger(Status);

/* Initialize the standard cFE File Header for the Dump File */
CFE_FS_InitHeader(&StdFileHeader, "CDS_Registry", CFE_FS_SubType_ES_CDS_REG);

Expand Down
6 changes: 2 additions & 4 deletions fsw/cfe-core/src/evs/cfe_evs_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,17 @@ int32 CFE_EVS_WriteLogDataFileCmd(const CFE_EVS_WriteLogDataFile_t *data)
OS_MAX_PATH_LEN, sizeof(CmdPtr->LogFilename));

/* Create the log file */
Result = OS_creat(LogFilename, OS_WRITE_ONLY);
Result = OS_OpenCreate(&LogFileHandle, LogFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);

if (Result < OS_SUCCESS)
{
EVS_SendEvent(CFE_EVS_ERR_CRLOGFILE_EID, CFE_EVS_EventType_ERROR,
"Write Log File Command Error: OS_creat = 0x%08X, filename = %s",
"Write Log File Command Error: OS_OpenCreate = 0x%08X, filename = %s",
(unsigned int)Result, LogFilename);

}
else
{
LogFileHandle = OS_ObjectIdFromInteger(Result);

/* Result will be overridden if everything works */
Result = CFE_EVS_FILE_WRITE_ERROR;

Expand Down
6 changes: 2 additions & 4 deletions fsw/cfe-core/src/evs/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -1752,18 +1752,16 @@ int32 CFE_EVS_WriteAppDataFileCmd(const CFE_EVS_WriteAppDataFile_t *data)
OS_MAX_PATH_LEN, sizeof(CmdPtr->AppDataFilename));

/* Create Application Data File */
Result = OS_creat(LocalName, OS_WRITE_ONLY);
Result = OS_OpenCreate(&FileHandle, LocalName, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);

if (Result < OS_SUCCESS)
{
EVS_SendEvent(CFE_EVS_ERR_CRDATFILE_EID, CFE_EVS_EventType_ERROR,
"Write App Data Command Error: OS_creat = 0x%08X, filename = %s",
"Write App Data Command Error: OS_OpenCreate = 0x%08X, filename = %s",
(unsigned int)Result, LocalName);
}
else
{
FileHandle = OS_ObjectIdFromInteger(Result);

/* Result will be overridden if everything works */
Result = CFE_EVS_FILE_WRITE_ERROR;

Expand Down
20 changes: 10 additions & 10 deletions fsw/cfe-core/src/inc/cfe_es_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -843,8 +843,8 @@
#define CFE_ES_ONE_APPID_ERR_EID 50


/** \brief <tt> 'Failed to write App Info file, OS_creat returned \%d' </tt>
** \event <tt> 'Failed to write App Info file, OS_creat returned \%d' </tt>
/** \brief <tt> 'Failed to write App Info file, OS_OpenCreate returned \%d' </tt>
** \event <tt> 'Failed to write App Info file, OS_OpenCreate returned \%d' </tt>
**
** \par Type: ERROR
**
Expand All @@ -853,7 +853,7 @@
** This event message is generated when an Executive Services \link #CFE_ES_QUERY_ALL_CC Dump Application
** Data Command \endlink fails to create the dump file.
**
** The \c 'd' parameter identifies, in decimal, the error code returned by #OS_creat when the attempt was made
** The \c 'd' parameter identifies, in decimal, the error code returned by #OS_OpenCreate when the attempt was made
** to create the file.
**/
#define CFE_ES_OSCREATE_ERR_EID 51
Expand Down Expand Up @@ -900,7 +900,7 @@
** Command \endlink fails while attempting to create the specified file.
**
** The \c 's' field identifies the name of the file that was attempted to be created and the \c stat field
** specifies, in hex, the error code returned by the #OS_creat API.
** specifies, in hex, the error code returned by the #OS_OpenCreate API.
**/
#define CFE_ES_SYSLOG2_ERR_EID 55

Expand All @@ -915,7 +915,7 @@
** Command \endlink fails while attempting to create the specified file.
**
** The \c 's' field identifies the name of the file that was attempted to be created and the \c stat field
** specifies, in hex, the error code returned by the #OS_creat API.
** specifies, in hex, the error code returned by the #OS_OpenCreate API.
**/
#define CFE_ES_ERLOG2_ERR_EID 56

Expand Down Expand Up @@ -1072,7 +1072,7 @@
** fails to create the associated logic analyzer dump file.
**
** The \c 's' field identifies the name of the file that was attempted to be created and the \c stat field
** specifies, in decimal, the error code returned by the #OS_creat API.
** specifies, in decimal, the error code returned by the #OS_OpenCreate API.
**/
#define CFE_ES_PERF_LOG_ERR_EID 67

Expand Down Expand Up @@ -1362,7 +1362,7 @@
** is unable to create the specified file on the onboard filesystem.
**
** The \c 's' field identifies the CDS Registry Dump Filename.
** The \c '08X' field identifies error code returned by the API #OS_creat.
** The \c '08X' field identifies error code returned by the API #OS_OpenCreate.
**/
#define CFE_ES_CREATING_CDS_DUMP_ERR_EID 86

Expand All @@ -1385,8 +1385,8 @@
#define CFE_ES_TASKINFO_EID 87


/** \brief <tt> 'Failed to write Task Info file, OS_creat returned \%d' </tt>
** \event <tt> 'Failed to write Task Info file, OS_creat returned \%d' </tt>
/** \brief <tt> 'Failed to write Task Info file, OS_OpenCreate returned \%d' </tt>
** \event <tt> 'Failed to write Task Info file, OS_OpenCreate returned \%d' </tt>
**
** \par Type: ERROR
**
Expand All @@ -1395,7 +1395,7 @@
** This event message is generated when an Executive Services \link #CFE_ES_QUERY_ALL_TASKS_CC Dump Task
** Data Command \endlink fails to create the dump file.
**
** The \c 'd' parameter identifies, in decimal, the error code returned by #OS_creat when the attempt was made
** The \c 'd' parameter identifies, in decimal, the error code returned by #OS_OpenCreate when the attempt was made
** to create the file.
**/
#define CFE_ES_TASKINFO_OSCREATE_ERR_EID 88
Expand Down
8 changes: 4 additions & 4 deletions fsw/cfe-core/src/inc/cfe_evs_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
**/
#define CFE_EVS_ERR_WRLOGFILE_EID 2

/** \brief <tt> 'Write Log File Command Error: OS_creat = 0x\%08X, filename = \%s' </tt>
** \event <tt> 'Write Log File Command Error: OS_creat = 0x\%08X, filename = \%s' </tt>
/** \brief <tt> 'Write Log File Command Error: OS_OpenCreate = 0x\%08X, filename = \%s' </tt>
** \event <tt> 'Write Log File Command Error: OS_OpenCreate = 0x\%08X, filename = \%s' </tt>
**
** \par Type: ERROR
**
Expand Down Expand Up @@ -241,8 +241,8 @@
**/
#define CFE_EVS_ERR_WRDATFILE_EID 12

/** \brief <tt> 'Write App Data Command Error: OS_creat = 0x\%08X, filename = \%s' </tt>
** \event <tt> 'Write App Data Command Error: OS_creat = 0x\%08X, filename = \%s' </tt>
/** \brief <tt> 'Write App Data Command Error: OS_OpenCreate = 0x\%08X, filename = \%s' </tt>
** \event <tt> 'Write App Data Command Error: OS_OpenCreate = 0x\%08X, filename = \%s' </tt>
**
** \par Type: ERROR
**
Expand Down
12 changes: 6 additions & 6 deletions fsw/cfe-core/src/inc/cfe_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
** the given File Descriptor.
**
** \par Assumptions, External Events, and Notes:
** -# The File has already been successfully opened using #OS_open and
** -# The File has already been successfully opened using #OS_OpenCreate and
** the caller has a legitimate File Descriptor.
**
** \param[in] FileDes File Descriptor obtained from a previous call to #OS_open
** \param[in] FileDes File Descriptor obtained from a previous call to #OS_OpenCreate
** that is associated with the file whose header is to be read.
**
** \param[in, out] Hdr Pointer to a variable of type #CFE_FS_Header_t that will be
Expand Down Expand Up @@ -112,12 +112,12 @@ void CFE_FS_InitHeader(CFE_FS_Header_t *Hdr, const char *Description, uint32 Sub
**
**
** \par Assumptions, External Events, and Notes:
** -# The File has already been successfully opened using #OS_open and
** -# The File has already been successfully opened using #OS_OpenCreate and
** the caller has a legitimate File Descriptor.
** -# The \c SubType field has been filled appropriately by the Application.
** -# The \c Description field has been filled appropriately by the Application.
**
** \param[in] FileDes File Descriptor obtained from a previous call to #OS_open
** \param[in] FileDes File Descriptor obtained from a previous call to #OS_OpenCreate
** that is associated with the file whose header is to be read.
**
** \param[in, out] Hdr Pointer to a variable of type #CFE_FS_Header_t that will be
Expand All @@ -140,11 +140,11 @@ int32 CFE_FS_WriteHeader(osal_id_t FileDes, CFE_FS_Header_t *Hdr);
** with the time specified by the caller.
**
** \par Assumptions, External Events, and Notes:
** -# The File has already been successfully opened using #OS_open and
** -# The File has already been successfully opened using #OS_OpenCreate and
** the caller has a legitimate File Descriptor.
** -# The \c NewTimestamp field has been filled appropriately by the Application.
**
** \param[in] FileDes File Descriptor obtained from a previous call to #OS_open
** \param[in] FileDes File Descriptor obtained from a previous call to #OS_OpenCreate
** that is associated with the file whose header is to be read.
**
** \param[in] NewTimestamp A #CFE_TIME_SysTime_t data structure containing the desired time
Expand Down
4 changes: 2 additions & 2 deletions fsw/cfe-core/src/inc/cfe_tbl_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
** -# The length (including terminator) of the filename and/or path exceeds the
** allowable length (see #OS_MAX_PATH_LEN and #OS_MAX_FILE_NAME, respectively)
**
** The \c Status field in the event message indicates the error code returned by the #OS_open
** The \c Status field in the event message indicates the error code returned by the #OS_OpenCreate
** API.
**/
#define CFE_TBL_FILE_ACCESS_ERR_EID 53
Expand Down Expand Up @@ -468,7 +468,7 @@
** This event message is generated when a Table Dump or Table Registry Dump command was
** received and the cFE Table Services is unable to create the specified file.
**
** The \c Status field provides the return status from the #OS_creat function call.
** The \c Status field provides the return status from the #OS_OpenCreate function call.
**/
#define CFE_TBL_CREATING_DUMP_FILE_ERR_EID 62

Expand Down
Loading

0 comments on commit 56254e9

Please sign in to comment.