SWRU455M February 2017 – October 2020 CC3120 , CC3120MOD , CC3130 , CC3135 , CC3135MOD , CC3220MOD , CC3220MODA , CC3220R , CC3220S , CC3220SF , CC3230S , CC3230SF , CC3235MODAS , CC3235MODASF , CC3235MODS , CC3235MODSF , CC3235S , CC3235SF
The host can invoke the write command for each file opened for write. For nonsecure files, the write command can be done to random offsets. For secure files, the write operation also encrypts the file, thus writing secure files requires writing to sequential offsets, or writing to a 16-byte-aligned offset buffer, which is also 16-byte-aligned in size.
The file system sets the actual file size as the higher offset than was written; the actual file size can be retrieved by the sl_FsGetInfo() function.
The return value of the write function is the number of bytes written, and a negative value is an error number.
Table 9-6 shows a partial list of errors that might be returned by the write function.
Error | Description |
---|---|
SL_ERROR_FS_OFFSET_OUT_OF_RANGE | The file can be written to offsets which are less than the maximum file size; trying to write a file to an offset which exceeds the maximum file size results in an error. |
SL_ERROR_FS_INVALID_HANDLE | The input file handle is illegal. |
SL_ERROR_FS_OFFSET_NOT_16_BYTE_ALIGN | For a secure file, when trying to write to an offset, this is not sequential. |
SL_ERROR_FS_FILE_ACCESS_IS_DIFFERENT | Trying to read a file which was opened for read. |
Example:
_i32 FileHdl;
_i32 Status;
_u32 Offset = 0;
unsigned char pData[100];
_u32 Len = 0;
Status = sl_FsWrite( FileHdl, Offset, pData, Len );
if( Status < 0 )
{
/* error */
/* abort */
sl_FsClose(FileHdl,0,'A',1);
}