/*****************************************************************************
Function   : NV_File_Exist
Description: Judge the NV file is exist.
Input      : pcDir - the directory of NV file.
             pcFile- the name of NV file.
Return     : OK, or ERROR
Other      :
*****************************************************************************/
VOS_INT32 NV_File_Exist(VOS_CHAR *pcDir, VOS_CHAR *pcFile)
{
    VOS_INT32                           lRslt;
    VOS_CHAR                            acFilePath[MAX_PATH] = {0};

    strncpy(acFilePath, pcDir, (MAX_PATH - 1));

    if (VOS_NULL_PTR != pcFile)
    {
        strncat(acFilePath, pcFile, (MAX_PATH - VOS_StrLen(acFilePath) - 1));
    }

    lRslt = DRV_FILE_ACCESS(acFilePath, NV_FILE_EXIST_OK);

    return lRslt;
}
VOS_UINT32 OM_LittleImgInitLogFile(VOS_UINT32 ulFileSize)
{
    LOG_FILE_DISK_INFO_STRU stDiskInfo;

    /* 创建LOG文件对应的信号量 */
    if (VOS_OK != VOS_SmMCreate("FILE", VOS_SEMA4_FIFO, &g_stLogFileSaveInfo.ulSem))
    {
        g_ulLittleImgLogErr = LOG_OPERATION_CREATE_SEM_FAIL;

        return VOS_ERR;
    }

    if (VOS_OK != VOS_SmP(g_stLogFileSaveInfo.ulSem, LOG_SEM_TIMEOUT_VALUE))
    {
        g_ulLittleImgLogErr = LOG_OPERATION_POST_SEM_FAIL;

        return VOS_ERR;
    }

    /* 判断LOG目录是否已经存在 */
    if (VOS_OK != DRV_FILE_ACCESS(g_acLogFileSaveDir, 0))
    {
        /* 如果目录不存在则创建LOG目录 */
        if(DRV_ERROR == DRV_FILE_MKDIR(g_acLogFileSaveDir))
        {
            g_ulLittleImgLogErr = LOG_OPERATION_MKDIR_FAIL;
            VOS_SmV(g_stLogFileSaveInfo.ulSem);
            return VOS_ERR;
        }
    }

    g_stLogFileSaveInfo.ulFileMinId = 1;
    g_stLogFileSaveInfo.ulFileMaxId = 1;
    g_stLogFileSaveInfo.ulCurLogFileMaxSize = ulFileSize * LOG_FILE_UNIT_SIZE;

    /* 调用底软接口返回 */
    if (DRV_ERROR == DRV_FILE_GET_DISKSPACE(
                    g_acFileSystemRoot,
                    (VOS_UINT*)&stDiskInfo.ulDiskSpace,
                    (VOS_UINT*)&stDiskInfo.ulUsedSpace,
                    (VOS_UINT*)&stDiskInfo.ulValidSpace))
    {
        PS_LOG(WUEPS_PID_OM, 0, PS_PRINT_ERROR, "OM_LittleImgInitLogFile: DRV_FILE_GET_DISKSPACE Failed!");
        return VOS_ERR;
    }

    g_stLogFileSaveInfo.ulFSFreeSpace = stDiskInfo.ulValidSpace;

    /* 如果NV项中文件大小不合法,修改为默认值 */
    if (g_stLogFileSaveInfo.ulCurLogFileMaxSize > g_stLogFileSaveInfo.ulFSFreeSpace)
    {
        g_stLogFileSaveInfo.ulCurLogFileMaxSize = LOG_FILE_SIZE * LOG_FILE_UNIT_SIZE;
    }

    /* 如果默认值大于文件系统大小,返回失败 */
    if (g_stLogFileSaveInfo.ulCurLogFileMaxSize > g_stLogFileSaveInfo.ulFSFreeSpace)
    {
        g_ulLittleImgLogErr = LOG_OPERATION_LENGTH_TOOBIG;
        VOS_SmV(g_stLogFileSaveInfo.ulSem);
        return VOS_ERR;
    }

    if (VOS_OK != OM_LittleImgCreateLogFile(g_stLogFileSaveInfo.ulCurLogFileMaxSize))
    {
        LogPrint("\r\n OM_LittleImgInitLogFile: Create Log File Failed.! \r\n");
        VOS_SmV(g_stLogFileSaveInfo.ulSem);
        return VOS_ERR;
    }

    g_ulLogFileSaveFlg = LOG_FILE_ENABLE;

    VOS_SmV(g_stLogFileSaveInfo.ulSem);

    return VOS_OK;

}