SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
Closing or aborting an opened file is mandatory. Closing the file frees the file resources from the device memory and sets the last file copy (if one exists) as the active one.
If the host application decides not to write an opened file due to an error, use abort instead of close.
The abort function requires the file handle. How to abort a file without using the file handle is described in the file commit-rollback function.
A file that was not closed or aborted appears in the file system; its storage is allocated, but it might have no valid copy. Such files can be observed by the SL_FS_INFO_NOT_VALID flag, and the file flags can be retrieved by the sl_FsGetFileList () or sl_FsGetInfo () functions.
For a file opened with the FAILSAFE flag that has a valid copy (from a previous write operation), invoking the abort function sets the nonactive copy as the active one, so that the next read operation reads the valid copy and not the one that has been aborted.
In the case of an unexpected or sudden shutdown, each file opened for write that has not been closed is treated as if abort has been called for this file.
The sl_FsClose() function returns 0 for success, and a negative number for an error.
Table 9-7 shows a partial list of errors that might be returned by the close after write function.
Error | Description |
---|---|
SL_ERROR_FS_INVALID_HANDLE | The input file handle is illegal. |
SL_ERROR_FS_CERT_CHAIN_ERROR_SECURITY_ALERT | For a secure signed file, testing the certificate chain of trust failed, and a security alert is triggered. |
SL_ERROR_FS_CERT_IN_THE_CHAIN_REVOKED_SECURITY_ALERT | For a secure signed file, the certificate chain of trust exists in the revoked list, and a security alert is triggered. |
SL_ERROR_FS_WRONG_SIGNATURE_SECURITY_ALERT | For a secure signed file, the signature test failed, and a security alert is triggered. |
SL_ERROR_FS_WRONG_CERTIFICATE_FILE_NAME | For a secure signed file, if one of the certificates in the chain of trust is missing, it does not trigger security alerts. |
Close nonsigned file example:
_i32 FileHdl;
_i16 Status;
const _u32 SignatureLen;
_u8* pSignature, pCeritificateFileName;
pCeritificateFileName = 0;
pSignature = 0;
SignatureLen = 0;
Status = sl_FsClose(FileHdl,pCeritificateFileName,pSignature,SignatureLen);
if( Status < 0 )
{
/* error */
/* abort */
sl_FsClose(FileHdl,0,'A',1);
}
Abort file example:
_i32 FileHdl;
_i16 Status;
const _u8 Signature;
const _u32 SignatureLen;
_u8* pCeritificateFileName;
pCeritificateFileName = 0;
Signature = 'A';
SignatureLen = 1;
Status = sl_FsClose(FileHdl,pCeritificateFileName,Signature,SignatureLen);
if( Status < 0 )
{
/*error */
}