Esempio n. 1
0
/*---------------------------------------------------------------------------
 *            MCP_HAL_FS_Open
 *---------------------------------------------------------------------------
 *
 * Synopsis:  the file name should include all file-system and drive specification as
 *             used by convention in the target platform.
 *
 * Return:    MCP_HAL_FS_STATUS_SUCCESS if success, MCP_HAL_FS_STATUS_ERROR_OPENING_FILE otherwise
 *
 */
McpHalFsStatus MCP_HAL_FS_Open(const McpUtf8* fullPathFileName, McpHalFsOpenFlags flags, McpHalFsFileDesc *fd)
{
        /* TODO (a0798989): support UTF-8 */
        int filehandle;
    int openFlags;

    openFlags = 0;
    *fd = MCP_HAL_FS_INVALID_FILE_DESC;
    
    if(flags & MCP_HAL_FS_O_APPEND)
        openFlags = openFlags | O_APPEND;
    if(flags & MCP_HAL_FS_O_CREATE)
        openFlags = openFlags | O_CREAT;
    if(flags & MCP_HAL_FS_O_EXCL)
        openFlags = openFlags | O_EXCL;
    if(flags & MCP_HAL_FS_O_RDONLY)
        openFlags = openFlags | O_RDONLY;
    if(flags & MCP_HAL_FS_O_RDWR)
        openFlags = openFlags | O_RDWR;
    if(flags & MCP_HAL_FS_O_TRUNC)
        openFlags = openFlags | O_TRUNC;
    if(flags & MCP_HAL_FS_O_WRONLY)
        openFlags = openFlags | O_WRONLY;

	filehandle = open( (char *)fullPathFileName, openFlags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );

    if ( -1 == filehandle ) {
        MCP_HAL_LOG_INFO(__FILE__, __LINE__, MCP_HAL_LOG_MODULE_TYPE_HAL_FS, ("MCP_HAL_FS_Open: failed to open %s", fullPathFileName));
        return _McpHalFs_ConvertLinuxErrorToFsError();
    }

    MCP_HAL_LOG_INFO(__FILE__, __LINE__, MCP_HAL_LOG_MODULE_TYPE_HAL_FS, ("MCP_HAL_FS_Open: opened %s", fullPathFileName));

    *fd = filehandle;
    return MCP_HAL_FS_STATUS_SUCCESS;
}
Esempio n. 2
0
/*---------------------------------------------------------------------------
 *            MCP_HAL_FS_OpenDir
 *---------------------------------------------------------------------------
 *
 * Synopsis:  open a directory for reading,
 *
 *  Returns:    MCP_HAL_FS_STATUS_SUCCESS - if successful,
 *              MCP_HAL_FS_STATUS_ERROR_INVALID_DIRECTORY_HANDLE_VALUE - if failed 
 */
McpHalFsStatus MCP_HAL_FS_OpenDir( const McpUtf8 *dirFullPathName, McpHalFsDirDesc *dirDesc )
{
    McpU32  directoryHandle;

    *dirDesc = (McpHalFsDirDesc)MCP_HAL_FS_INVALID_DIRECTORY_DESC;

    if((directoryHandle = _McpHalFs_GetFreeScpaceInDirStructurArray()) == MCP_HAL_FS_INVALID_DIRECTORY_DESC)
        return MCP_HAL_FS_STATUS_ERROR_MAX_DIRECTORY_HANDLE;

    strncpy((char*)_mcpHalFs_DirStructureArray[directoryHandle].path,
                                (char*)dirFullPathName,
                                MCP_HAL_CONFIG_FS_MAX_PATH_LEN_CHARS);

    _mcpHalFs_DirStructureArray[directoryHandle].searchHandle = opendir((char *)dirFullPathName);   
    if(_mcpHalFs_DirStructureArray[directoryHandle].searchHandle == NULL)
    {
        MCP_HAL_LOG_INFO(__FILE__, __LINE__, MCP_HAL_LOG_MODULE_TYPE_HAL_FS, ("MCP_HAL_FS_OpenDir: opendir failed: %s\n", strerror(errno)));
        return MCP_HAL_FS_STATUS_ERROR_INVALID_DIRECTORY_HANDLE_VALUE;
    }

    *dirDesc = directoryHandle;
    return  MCP_HAL_FS_STATUS_SUCCESS;
}
Esempio n. 3
0
/*---------------------------------------------------------------------------
 *            MCP_HAL_FS_Stat
 *---------------------------------------------------------------------------
 *
 * Synopsis:  get information of a file or folder - name, size, type, 
 *            created/modified/accessed time, and Read/Write/Delete         . 
 *            access permissions.
 *
 * Returns: MCP_HAL_FS_STATUS_SUCCESS - if successful,
 *              other -  Operation failed.
 */
McpHalFsStatus MCP_HAL_FS_Stat( const McpUtf8* fullPathName, McpHalFsStat* fileStat )
{
    /* TODO (a0798989): support UTF-8 */

        struct stat buf;
    
    if (stat((char *)fullPathName, &buf) == 0)
    {
        /* Get file/dir size */ 
            fileStat->size = buf.st_size;
        
            /* Set either file or directory field */
            fileStat->type = S_ISDIR(buf.st_mode) ? MCP_HAL_FS_DIR : MCP_HAL_FS_FILE;
        
            /* if true read only */
            fileStat->isReadOnly = (buf.st_mode & (S_IRUSR|S_IWUSR)) == S_IRUSR ? MCP_TRUE: MCP_FALSE;

            /* Extract user/group/other file or directory access permissions */
            _McpHalFs_ExtractPermissions(buf.st_mode, fileStat);
            
        /* Extract file creation fields (in UTC) */
            _McpHalFs_ExtractDateAndTime(buf.st_ctime, &fileStat->cTime);
            
            /* Extract file modification fields (in UTC) */
            _McpHalFs_ExtractDateAndTime(buf.st_mtime, &fileStat->mTime);
            
            /* Extract file access fields (in UTC) */
            _McpHalFs_ExtractDateAndTime(buf.st_atime, &fileStat->aTime);

        return MCP_HAL_FS_STATUS_SUCCESS;
    }

    MCP_HAL_LOG_INFO(__FILE__, __LINE__, MCP_HAL_LOG_MODULE_TYPE_HAL_FS, ("Can't find file %s", fullPathName));
    
    return _McpHalFs_ConvertLinuxErrorToFsError();
}
/**
 * \fn     pla_cmdParse_GeneralCmdLine
 * \brief  Parses the initial command line
 *
 * This function parses the initial command line,
 * and returns the BT & NAVC strings,
 * along with the common parameter.
 *
 * \note
 * \param   CmdLine     - Received command Line.
 * \param   **bt_str - returned BT cmd line.
 * \param   **nav_str - returned NAVC cmd line.
 * \return  Port Number
 * \sa      pla_cmdParse_GeneralCmdLine
 */
McpU32 pla_cmdParse_GeneralCmdLine(LPSTR CmdLine, char **bt_str, char **nav_str)
{
    /* Currently, in Linux the serial port name is hardcoded in bthal_config.h.
     * So, put some number in order to prevent assert in a caller function */
    McpU32      uPortNum = -1;
    
    char        *pParam;
    char        *paramParse;
    char        pathfile[256] = "";
    char        logName[30] = "";
    char        logFile[256] = "";
    char        logIp[30] = "";
    char        portStr[30] = "";
    unsigned long port = 0;
    char        *pPort;
    int         i=0;

    MCPF_UNUSED_PARAMETER(bt_str);
    
	pPort = strstr(CmdLine, "-p");
	if(pPort != NULL)
	{
		uPortNum = atoi(pPort+2);
		sprintf((*nav_str), "%s%d", "-p", uPortNum); 
	}

    
    /*Issue Fix -nav*/
    if (0 != (pParam = strstr((const char *)CmdLine, "-nav")))
    {
	
	paramParse = pParam;   
	paramParse += 5;	 
	
	strcat (*nav_str, " ");

	while(*paramParse != '"')
	{
		
              pathfile[i] = *paramParse;
		paramParse++;
		i++;
       }
       strcat (*nav_str, pathfile);

	   		MCP_HAL_LOG_INFO(__FILE__,
                                      __LINE__,
                                      MCP_HAL_LOG_MODULE_TYPE_MCP_MAIN,
                                      ("pla_cmdParse_GeneralCmdLine111: NAV Cmd line \"%s\"", *nav_str));
    }
    else
    {
	strcat (*nav_str, " ");
	strcat (*nav_str, PATHCONFIGFILE);
    }

#ifdef ANDROID
    if (0 != (pParam = strstr((const char *)CmdLine, "--android_log")))
    {
        getParamString(pParam, logName);
        MCP_HAL_LOG_EnableLogToAndroid((const char *)logName);
    }
#endif
    if (0 != (pParam = strstr((const char *)CmdLine, "-logfile")))
    {
        getParamString(pParam, logFile);
        MCP_HAL_LOG_EnableFileLogging((const char *)logFile);
    }
    else if (0 != strstr((const char *)CmdLine, "--log_to_stdout"))
    {
        MCP_HAL_LOG_EnableStdoutLogging();
    }
    else if (0 != (pParam = strstr((const char *)CmdLine, "-log_ip")))
    {
        getParamString(pParam, logIp);
        
        if (0 != (pParam = strstr((const char *)CmdLine, "-log_port")))
        {
            getParamString(pParam, portStr);
            port = atoi((const char *)portStr);
        }
        if (strlen(logIp)>0 && port>0)
        {
            MCP_HAL_LOG_EnableUdpLogging(logIp, port);
            MCP_HAL_LOG_INFO(__FILE__,
                             __LINE__,
                             MCP_HAL_LOG_MODULE_TYPE_MCP_MAIN,
                             ("pla_cmdParse_GeneralCmdLine: UDP logging, IP %s, port %d",
                              logIp, port));
        }
    }
    else if (0 != strstr((const char *)CmdLine, "--help"))
    {
        printf ("btipsd usage :\nbtipsd [options]\n-h, --help : Show this screen\n-r, --run_as_daemon : Run the mcpd as daemon in the background\n-l, --logfile [LOGFILENAME] : Log to specified file\n-d, --log_to_stdout : Log to STDOUT\n-log_ip [IP_ADDRESS] : Target UDP Listener IP for logging\n-log_port [PORT] : Target UDP Listener PORT for logging\n");
#ifdef ANDROID
        printf ("-no_android_log : Disable Android logging\n");
#endif
        return 0;
    }
    
    MCP_HAL_LOG_INFO(__FILE__,
                                      __LINE__,
                                      MCP_HAL_LOG_MODULE_TYPE_MCP_MAIN,
                                      ("pla_cmdParse_GeneralCmdLine: cmd line \"%s\"", CmdLine));
    
    return uPortNum;
  
}