This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CC3235SF:如何使用 sl_FsDel ()函数删除文件?

Guru**** 2124380 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/wi-fi-group/wifi/f/wi-fi-forum/1381391/cc3235sf-how-to-delete-file-using-sl_fsdel-function

器件型号: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);
    }
}

我应该如何删除该文件? 打开状态或其他问题有问题吗?

祝你度过美好的一天!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    我收到无效令牌错误、但我正在尝试使用主机令牌删除文件。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    static uint32_t appDeviceGetFileInfo(unsigned char *fileName)
    {
       /* Holds struct for file system. */
       SlFsFileInfo_t fileInfo = {0};
       /* Holds return value. */
       int16_t RetVal = -1;
       /* Get information of a specific file. */
       RetVal = sl_FsGetInfo(fileName, g_tokens[SL_FS_TOKEN_MASTER], &fileInfo);
       /* Check if tokens from file system are acquired. */
       if(0 == RetVal)
       {
           /* Copy tokens. */
           g_tokens[SL_FS_TOKEN_READ_ONLY] = fileInfo.Token[SL_FS_TOKEN_READ_ONLY];
           g_tokens[SL_FS_TOKEN_WRITE_ONLY] = fileInfo.Token[SL_FS_TOKEN_WRITE_ONLY];
           g_tokens[SL_FS_TOKEN_WRITE_READ] = fileInfo.Token[SL_FS_TOKEN_WRITE_READ];
       }
       /* Return status value. */
       return RetVal;
    }
    
    /*!
     *  @brief  Function to actually write file to the file system.
     *
     *  @param  fileName    The pointer to the file name.
     *
     *  @param  p_buf       The pointer to buffer containing data to
     *                      be written to the file system.
     *
     *  @param  len         The number of bytes in the buffer that should
     *                      be written to the file system.
     *
     *  @return Returns 0 if write was successful, otherwise the error code.
     *
     */
    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
        {
            sl_FsClose(fileHandle, NULL, (uint8_t *)'A', 1);
            ERR_CHECK(appDeviceGetFileInfo(fileName), ERROR_NO_ERROR);
            /* 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);
        }
        return retVal;
    }

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    感谢您的关注、明天我会跟进。

    此致!

    Rogelio

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    我看代码时没有看到任何具体的错误。 创建文件时、您可以验证 MasterToken 是否确实正在保存到中  

    G_TOKEN[SL_FS_TOKEN_MASTER]。 另一个问题是为什么    在 sl_FsOpen ()函数中包含"\"。

    此致!

    Rogelio