请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
器件型号:CC3235SF 工具与软件:
您好!
我在删除文件时遇到问题。 我可以成功写入文件、但当我尝试删除文件时、我收到了安全警报。 这是我的写入/删除函数。
int32_t appDeviceWriteFile(unsigned char *fileName, uint8_t *p_buf, size_t len)
{
/* Holds file system handle. */
int32_t fileHandle = -1;
/* Holds return value. */
int32_t retVal = -1;
/* Create a secure file if not exists and open it for write. */
fileHandle = sl_FsOpen(fileName, \
SL_FS_CREATE | SL_FS_OVERWRITE | \
SL_FS_CREATE_MAX_SIZE( len ) | \
SL_FS_CREATE_SECURE | SL_FS_CREATE_PUBLIC_WRITE | \
SL_FS_CREATE_NOSIGNATURE, (_u32 *)&g_tokens[SL_FS_TOKEN_MASTER]);
/* Check if handle has a valid value. */
if(0 > fileHandle)
{
/* Error happened, abort. */
sl_FsClose(fileHandle, NULL, (uint8_t *)'A', 1);
/* Print error. */
ERR_PRINT(ERROR_FILE_SYSTEM_OP);
}
else
{
/* Preferred in secure file that the Offset and
* the length will be aligned to 16 bytes. */
retVal = sl_FsWrite(fileHandle, 0, p_buf, len);
/* Check for an error. */
if(0 > retVal)
{
/* Error happened, abort. */
sl_FsClose(fileHandle, NULL, (uint8_t *)'A', 1);
/* Print error. */
ERR_PRINT(ERROR_FILE_SYSTEM_OP);
}
/* Close file in storage device. */
retVal = sl_FsClose(fileHandle, NULL, NULL , 0);
/* Check for an error. */
if(0 > retVal)
{
/* Error happened, abort. */
sl_FsClose(fileHandle, NULL, (uint8_t *)'A', 1);
/* Print error. */
ERR_PRINT(ERROR_FILE_SYSTEM_OP);
}
/* Get tokens for the given file. */
ERR_CHECK(appDeviceGetFileInfo(fileName), ERROR_NO_ERROR);
}
/* Return result. */
return retVal;
}
int32_t appDeviceDeleteFile(unsigned char *fileName, size_t len)
{
/* Holds file system handle. */
int32_t fileHandle = -1;
/* Holds return value. */
int32_t retVal = -1;
/* Create a secure file if not exists and open it for write. */
fileHandle = sl_FsOpen(fileName, \
SL_FS_CREATE | SL_FS_OVERWRITE | \
SL_FS_CREATE_MAX_SIZE( len ) | \
SL_FS_CREATE_SECURE | SL_FS_CREATE_PUBLIC_WRITE | \
SL_FS_CREATE_NOSIGNATURE, (_u32 *)&g_tokens[SL_FS_TOKEN_MASTER]);
/* Check if handle has a valid value. */
if(0 > fileHandle)
{
/* Error happened, abort. */
sl_FsClose(fileHandle, NULL, (uint8_t *)'A', 1);
/* Print error. */
ERR_PRINT(ERROR_FILE_SYSTEM_OP);
}
else
{
/* Delete the file. */
retVal = sl_FsDel(fileName, g_tokens[SL_FS_TOKEN_MASTER]);
/* Check for an error. */
if(0 > retVal)
{
/* Error happened, abort. */
sl_FsClose(fileHandle, NULL, (uint8_t *)'A', 1);
/* Print error. */
ERR_PRINT(ERROR_FILE_SYSTEM_OP);
}
/* Close file in storage device. */
retVal = sl_FsClose(fileHandle, NULL, NULL , 0);
/* Check for an error. */
if(0 > retVal)
{
/* Error happened, abort. */
sl_FsClose(fileHandle, NULL, (uint8_t *)'A', 1);
/* Print error. */
ERR_PRINT(ERROR_FILE_SYSTEM_OP);
}
/* Get tokens for the given file. */
ERR_CHECK(appDeviceGetFileInfo(fileName), ERROR_NO_ERROR);
}
}
我应该如何删除该文件? 打开状态或其他问题有问题吗?
祝你度过美好的一天!