コード例 #1
0
ファイル: osfileapi.c プロジェクト: iamjy/osal
int32 OS_remove (const char *path)
{
    int status;
    char local_path[OS_MAX_PATH_LEN];
    
    if (path == NULL)
        return OS_FS_ERR_INVALID_POINTER;

    if (strlen(path) >= OS_MAX_PATH_LEN)
        return OS_FS_ERR_PATH_TOO_LONG;
   
    /* make a local copy of the path */
    strcpy(local_path, path);
    if(OS_NameChange(local_path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    
    /* check if the name of the file is too long */
    if (OS_check_name_length(local_path) == OS_FS_ERROR)
        return OS_FS_ERR_NAME_TOO_LONG;

    status = remove (local_path);
    if (status != ERROR)
        return OS_FS_SUCCESS;
    else
        return OS_FS_ERROR;
    
} /* end OS_remove */
コード例 #2
0
ファイル: osfileapi.c プロジェクト: iamjy/osal
int32 OS_stat   (const char *path, os_fstat_t  *filestats)
{
    int ret_val;
    char local_path[OS_MAX_PATH_LEN];
    
    if (path == NULL || filestats == NULL)
        return OS_FS_ERR_INVALID_POINTER;

    if (strlen(path) >= OS_MAX_PATH_LEN)
        return OS_FS_ERR_PATH_TOO_LONG;
   
    /* make a local copy of the path */
    strcpy(local_path, path);
    if(OS_NameChange(local_path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    
    /* check if the name of the file is too long */
    if (OS_check_name_length(local_path) == OS_FS_ERROR)
        return OS_FS_ERROR;

    ret_val = stat( (char*) local_path, filestats);
    if (ret_val == ERROR)
        return OS_FS_ERROR;
    else
        return OS_FS_SUCCESS;
    
} /* end OS_stat */
コード例 #3
0
ファイル: osfileapi.c プロジェクト: felipeprov/osal
int32 OS_remove (const char *path)
{
    int  status;
    char local_path[OS_MAX_LOCAL_PATH_LEN];

    /*
    ** Check to see if the path pointer is NULL
    */
    if (path == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }
   
    /*
    ** Check to see if the path is too long
    */
    if (strlen(path) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /* 
    ** check if the name of the file is too long 
    */
    if (OS_check_name_length(path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }
   
    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    /*
    ** Call the system to remove the file
    */
    status = remove (local_path);
    if (status != ERROR)
    {
        return OS_FS_SUCCESS;
    }
    else
    {
        return OS_FS_ERROR;
    }
    
} /* end OS_remove */
コード例 #4
0
ファイル: osfileapi.c プロジェクト: TomCrowley-ME/me_sim_test
int32 OS_mv (const char *src, const char *dest)
{
   int i;
   int32 status;

   /*
   ** Validate the source and destination
   ** These checks may seem redundant because OS_cp and OS_remove also do
   ** the same checks, but this call needs to abort before doing a copy
   ** in some cases.
   */

   /*
   ** Check to see if the path pointers are NULL
   */
   if (src == NULL || dest == NULL)
   {
        return OS_FS_ERR_INVALID_POINTER;
   }

   /*
   ** Check to see if the paths are too long
   */
   if (strlen(src) >= OS_MAX_PATH_LEN)
   {
       return OS_FS_ERR_PATH_TOO_LONG;
   }

   if (strlen(dest) >= OS_MAX_PATH_LEN)
   {
       return OS_FS_ERR_PATH_TOO_LONG;
   }

   /*
   ** check if the names of the files are too long
   */
   if (OS_check_name_length(src) != OS_FS_SUCCESS)
   {
       return OS_FS_ERR_NAME_TOO_LONG;
   }

   if (OS_check_name_length(dest) != OS_FS_SUCCESS)
   {
       return OS_FS_ERR_NAME_TOO_LONG;
   }

   /*
   ** Make sure the source file is not open by the OSAL before doing the move
   */
   for ( i =0; i < OS_MAX_NUM_OPEN_FILES; i++)
   {
       if ((OS_FDTable[i].IsValid == TRUE) &&
          (strcmp(OS_FDTable[i].Path, src) == 0))
       {
          return OS_FS_ERROR;
       }
   }

   status = OS_cp (src, dest);
   if ( status == OS_FS_SUCCESS )
   {
      status = OS_remove(src);
   }

   return ( status);

}/*end OS_mv */
コード例 #5
0
ファイル: osfileapi.c プロジェクト: TomCrowley-ME/me_sim_test
int32 OS_cp (const char *src, const char *dest)
{
    int  i;
    int  status;
    char src_path[OS_MAX_LOCAL_PATH_LEN];
    char dest_path[OS_MAX_LOCAL_PATH_LEN];

    /*
    ** Check to see if the path pointers are NULL
    */
    if (src == NULL || dest == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Check to see if the paths are too long
    */
    if (strlen(src) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    if (strlen(dest) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /*
    ** check if the names of the files are too long
    */
    if (OS_check_name_length(src) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    if (OS_check_name_length(dest) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(src, (char *)src_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(dest, (char *)dest_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    /*
    ** Make sure the destintation file is not open by the OSAL before doing the copy
    ** This may be caught by the host OS open call but it does not hurt to
    ** be consistent
    */
    for ( i =0; i < OS_MAX_NUM_OPEN_FILES; i++)
    {
        if ((OS_FDTable[i].IsValid == TRUE) &&
          (strcmp(OS_FDTable[i].Path, dest) == 0))
        {
           return OS_FS_ERROR;
        }
    }

    status = cp(src_path, dest_path);

    if (status != ERROR)
    {
       return OS_FS_SUCCESS;
    }
    else
    {
       return OS_FS_ERROR;
    }

}/*end OS_cp */
コード例 #6
0
ファイル: osfileapi.c プロジェクト: TomCrowley-ME/me_sim_test
/*--------------------------------------------------------------------------------------
    Name: OS_rename

    Purpose: renames a file

    Returns: OS_FS_SUCCESS if the rename works
             OS_FS_ERROR if the file could not be opened or renamed.
             OS_FS_ERR_INVALID_POINTER if old_filename or new_filename are NULL
             OS_FS_ERR_PATH_INVALID if path cannot be parsed
             OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally
             OS_FS_ERR_NAME_TOO_LONG if the new name is too long to be stored locally
---------------------------------------------------------------------------------------*/
int32 OS_rename (const char *old_filename, const char *new_filename)
{
    int status,i;
    char old_path[OS_MAX_LOCAL_PATH_LEN];
    char new_path[OS_MAX_LOCAL_PATH_LEN];

    /*
    ** Check to see if the path pointers are NULL
    */
    if (old_filename == NULL || new_filename == NULL)
        return OS_FS_ERR_INVALID_POINTER;

    /*
    ** Check to see if the paths are too long
    */
    if (strlen(old_filename) >= OS_MAX_PATH_LEN)
        return OS_FS_ERR_PATH_TOO_LONG;

    if (strlen(new_filename) >= OS_MAX_PATH_LEN)
        return OS_FS_ERR_PATH_TOO_LONG;

    /*
    ** check if the names of the files are too long
    */
    if (OS_check_name_length(old_filename) != OS_FS_SUCCESS)
        return OS_FS_ERR_NAME_TOO_LONG;

    if (OS_check_name_length(new_filename) != OS_FS_SUCCESS)
        return OS_FS_ERR_NAME_TOO_LONG;

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(old_filename, (char *)old_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(new_filename, (char *)new_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    status = rename (old_path, new_path);

    if (status != ERROR)
    {
        for ( i =0; i < OS_MAX_NUM_OPEN_FILES; i++)
        {
            if (strcmp(OS_FDTable[i].Path, old_filename) == 0 &&
                OS_FDTable[i].IsValid == TRUE)
            {
                strncpy (OS_FDTable[i].Path, new_filename, OS_MAX_PATH_LEN);
            }
        }
        return OS_FS_SUCCESS;
    }
    else
    {
       return OS_FS_ERROR;
    }

}/*end OS_rename */
コード例 #7
0
ファイル: osfileapi.c プロジェクト: TomCrowley-ME/me_sim_test
int32 OS_remove (const char *path)
{
    int  i;
    int  status;
    char local_path[OS_MAX_LOCAL_PATH_LEN];

    /*
    ** Check to see if the path pointer is NULL
    */
    if (path == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Check to see if the path is too long
    */
    if (strlen(path) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /*
    ** check if the name of the file is too long
    */
    if (OS_check_name_length(path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    /*
    ** Make sure the file is not open by the OSAL before deleting it
    */
    for ( i =0; i < OS_MAX_NUM_OPEN_FILES; i++)
    {
       if ((OS_FDTable[i].IsValid == TRUE) &&
          (strcmp(OS_FDTable[i].Path, path) == 0))
       {
          return OS_FS_ERROR;
       }
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    status = remove (local_path);
    if (status == OK)
    {
        return OS_FS_SUCCESS;
    }
    else
    {
        return OS_FS_ERROR;
    }

} /* end OS_remove */
コード例 #8
0
ファイル: osfileapi.c プロジェクト: TomCrowley-ME/me_sim_test
int32 OS_open   (const char *path,  int32 access,  uint32  mode)
{
    int    status;
    char   local_path[OS_MAX_LOCAL_PATH_LEN];
    uint32 PossibleFD;
    int    perm;

    /*
    ** Check to see if the path pointer is NULL
    */
    if (path == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Check to see if the path is too long
    */
    if (strlen(path) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /*
    ** check if the name of the file is too long
    */
    if (OS_check_name_length(path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    /*
    ** Check for a valid access mode
    */
    switch(access)
    {
        case OS_READ_ONLY:
            perm = O_RDONLY;
            break;
        case OS_WRITE_ONLY:
            perm = O_WRONLY | O_CREAT;
            break;
        case OS_READ_WRITE:
            perm = O_RDWR | O_CREAT;
            break;
        default:
            return OS_FS_ERROR;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    semTake(OS_FDTableMutex,WAIT_FOREVER);

    for ( PossibleFD = 0; PossibleFD < OS_MAX_NUM_OPEN_FILES; PossibleFD++)
    {
        if( OS_FDTable[PossibleFD].IsValid == FALSE)
        {
            break;
        }
    }

    if (PossibleFD >= OS_MAX_NUM_OPEN_FILES)
    {
        semGive(OS_FDTableMutex);
        return OS_FS_ERR_NO_FREE_FDS;
    }

    /* Mark the table entry as valid so no other
     * task can take that ID */
    OS_FDTable[PossibleFD].IsValid =    TRUE;

    semGive(OS_FDTableMutex);

    /* Open the file */
    status = open(local_path, (int) perm, (int) mode);

    semTake(OS_FDTableMutex,WAIT_FOREVER);

    if (status != ERROR)
    {
        /* fill in the table before returning */

        OS_FDTable[PossibleFD].OSfd =       status;
        strncpy(OS_FDTable[PossibleFD].Path, path, OS_MAX_PATH_LEN);
        OS_FDTable[PossibleFD].User =       OS_FindCreator();
        semGive(OS_FDTableMutex);

        return PossibleFD;
    }
    else
    {   OS_FDTable[PossibleFD].IsValid = FALSE;
        semGive(OS_FDTableMutex);
        return OS_FS_ERROR;
    }

} /* end OS_open */
コード例 #9
0
ファイル: osfileapi.c プロジェクト: felipeprov/osal
int32 OS_cp (const char *src, const char *dest)
{
    int  src_fd;
    int  dest_fd;
    char src_path[OS_MAX_LOCAL_PATH_LEN];
    char dest_path[OS_MAX_LOCAL_PATH_LEN];
    char data_buffer[512];
    int  bytes_read;
    int  bytes_written;

    /*
    ** Check to see if the path pointers are NULL
    */    
    if (src == NULL || dest == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Check to see if the paths are too long
    */
    if (strlen(src) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }
    
    if (strlen(dest) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /* 
    ** check if the names of the files are too long 
    */
    if (OS_check_name_length(src) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    if (OS_check_name_length(dest) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(src, (char *)src_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(dest, (char *)dest_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    /*
    ** Do the copy
    */
    if((src_fd = open(src_path, O_RDONLY)) == -1) 
    {
       return OS_FS_ERR_PATH_INVALID;
    }

    if((dest_fd = open(dest_path, O_WRONLY | O_CREAT | O_TRUNC, 0666)) == -1)
    {
       close(src_fd);
       return OS_FS_ERR_PATH_INVALID;
    }
 
    while((bytes_read = read(src_fd, data_buffer, sizeof(data_buffer))) > 0)
    {
       bytes_written = write(dest_fd, data_buffer, bytes_read);
       if ( bytes_written < 0 )
       {
          close(src_fd);
          close(dest_fd);
          return OS_FS_ERROR;
       }
    }

    close(src_fd);
    close(dest_fd);

    if ( bytes_read < 0 )
    {
       return OS_FS_ERROR;
    }
    else
    {
       return OS_FS_SUCCESS;
    }
     
}/*end OS_cp */
コード例 #10
0
ファイル: osfileapi.c プロジェクト: felipeprov/osal
int32 OS_open   (const char *path,  int32 access,  uint32  mode)
{
    int               status;
    rtems_status_code rtems_sc;
    char              local_path[OS_MAX_LOCAL_PATH_LEN];
    int               perm;
    uint32            PossibleFD;
    
    /*
    ** Check to see if the path pointer is NULL
    */
    if (path == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }
   
    /*
    ** Check to see if the path is too long
    */
    if (strlen(path) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /* 
    ** check if the name of the file is too long 
    */
    if (OS_check_name_length(path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }
   
    /*
    ** Check for a valid access mode
    */
    switch(access)
    {
        case OS_READ_ONLY:
            perm = O_RDONLY;
            break;
        case OS_WRITE_ONLY:
            perm = O_WRONLY;
            break;
        case OS_READ_WRITE:
            perm = O_RDWR;
            break;
        default:
            return OS_FS_ERROR;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }
    
   rtems_sc = rtems_semaphore_obtain (OS_FDTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);

    for ( PossibleFD = 0; PossibleFD < OS_MAX_NUM_OPEN_FILES; PossibleFD++)
    {
        if( OS_FDTable[PossibleFD].IsValid == FALSE)
        {
            break;
        }
    }

    if (PossibleFD >= OS_MAX_NUM_OPEN_FILES)
    {
        rtems_sc = rtems_semaphore_release (OS_FDTableSem);
        return OS_FS_ERR_NO_FREE_FDS;
    }

    /* 
    ** Mark the table entry as valid so no other 
    ** task can take that ID 
    */
    OS_FDTable[PossibleFD].IsValid = TRUE;

    rtems_sc = rtems_semaphore_release (OS_FDTableSem);

    /* open the file  */
    status =  open(local_path, perm, mode);

    if (status != ERROR)
    {
        rtems_sc = rtems_semaphore_obtain (OS_FDTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
        /* fill in the table before returning */
        OS_FDTable[PossibleFD].OSfd =       status;
        strncpy(OS_FDTable[PossibleFD].Path, path, OS_MAX_PATH_LEN);
        OS_FDTable[PossibleFD].User =       OS_FindCreator();
        rtems_sc = rtems_semaphore_release (OS_FDTableSem);
        
        return PossibleFD;
    }
    else
    {
        rtems_sc = rtems_semaphore_obtain (OS_FDTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
        /* Operation failed, so reset to false */
        OS_FDTable[PossibleFD].IsValid = FALSE;
        rtems_sc = rtems_semaphore_release (OS_FDTableSem);
        return OS_FS_ERROR;
    }
 
} /* end OS_open */
コード例 #11
0
ファイル: osfileapi.c プロジェクト: felipeprov/osal
int32 OS_creat  (const char *path, int32  access)
{
    int    status;
    char   local_path[OS_MAX_LOCAL_PATH_LEN];
    int    perm;
    mode_t mode;
    uint32 PossibleFD;

    /*
    ** Check to see if the path pointer is NULL
    */
    if (path == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }
   
    /*
    ** Check to see if the path is too long
    */
    if (strlen(path) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /* 
    ** check if the name of the file is too long 
    */
    if (OS_check_name_length(path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    /*
    ** Check for a valid access mode
    ** For creating a file, OS_READ_ONLY does not make sense
    */
    switch(access)
    {
        case OS_WRITE_ONLY:
            perm = O_WRONLY;
            break;
        case OS_READ_WRITE:
            perm = O_RDWR;
            break;
        default:
            return OS_FS_ERROR;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }
    
    pthread_mutex_lock(&OS_FDTableMutex);

    for ( PossibleFD = 0; PossibleFD < OS_MAX_NUM_OPEN_FILES; PossibleFD++)
    {
        if( OS_FDTable[PossibleFD].IsValid == FALSE)
        {
            break;
        }
    }

    if (PossibleFD >= OS_MAX_NUM_OPEN_FILES)
    {
        pthread_mutex_unlock(&OS_FDTableMutex);
        return OS_FS_ERR_NO_FREE_FDS;
    }


    /* Mark the table entry as valid so no other 
     * task can take that ID */
    OS_FDTable[PossibleFD].IsValid =    TRUE;

    pthread_mutex_unlock(&OS_FDTableMutex);

    mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
   
    status =  open(local_path, perm | O_CREAT | O_TRUNC, mode);

    pthread_mutex_lock(&OS_FDTableMutex);

    if (status != ERROR)
    {
        /* fill in the table before returning */
        OS_FDTable[PossibleFD].OSfd =       status;
        strncpy(OS_FDTable[PossibleFD].Path, path, OS_MAX_PATH_LEN);
        OS_FDTable[PossibleFD].User =       OS_FindCreator();
        pthread_mutex_unlock(&OS_FDTableMutex);
        return PossibleFD;
    }
    else
    {
        /* Operation failed, so reset to false */
        OS_FDTable[PossibleFD].IsValid = FALSE;
        pthread_mutex_unlock(&OS_FDTableMutex);
        return OS_FS_ERROR;
    }
 
} /* end OS_creat */
コード例 #12
0
ファイル: osfileapi.c プロジェクト: iamjy/osal
int32 OS_open   (const char *path,  int32 access,  uint32  mode)
{
    int status;
    char local_path[OS_MAX_PATH_LEN];
    int perm;
    uint32 PossibleFD;
    
    
    if(path == NULL)
       return OS_FS_ERR_INVALID_POINTER;

    if (strlen(path) >= OS_MAX_PATH_LEN)
        return OS_FS_ERR_PATH_TOO_LONG;
   
    /* make a local copy of the path */
    strcpy(local_path, path);
    if(OS_NameChange(local_path) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_PATH_INVALID;
    }


    
    /* check if the name of the file is too long */
    if (OS_check_name_length(local_path) == OS_FS_ERROR)
        return OS_FS_ERR_NAME_TOO_LONG;
    
    pthread_mutex_lock(&OS_FDTableMutex);

    for ( PossibleFD = 0; PossibleFD < OS_MAX_NUM_OPEN_FILES; PossibleFD++)
    {
        if( OS_FDTable[PossibleFD].IsValid == FALSE)
        {
            break;
        }
    }


    if (PossibleFD >= OS_MAX_NUM_OPEN_FILES)
    {
        pthread_mutex_unlock(&OS_FDTableMutex);

        return OS_FS_ERR_NO_FREE_FDS;
    }

    /* Mark the table entry as valid so no other 
     * task can take that ID */
    OS_FDTable[PossibleFD].IsValid = TRUE;

    pthread_mutex_unlock(&OS_FDTableMutex);


    switch(access)
    {
        case OS_READ_ONLY:
            perm = O_RDONLY;
            break;
        case OS_WRITE_ONLY:
            perm = O_WRONLY;
            break;
        case OS_READ_WRITE:
            perm = O_RDWR;
            break;
        default:
            return OS_FS_ERROR;
    }

    /* open the file with the R/W permissions */

    status =  open(local_path,perm);

    pthread_mutex_lock(&OS_FDTableMutex);

    if (status != ERROR)
    {
        /* fill in the table before returning */
        OS_FDTable[PossibleFD].OSfd =       status;
        strncpy(OS_FDTable[PossibleFD].Path, path, OS_MAX_API_NAME);
        OS_FDTable[PossibleFD].User =       OS_FindCreator();
        pthread_mutex_unlock(&OS_FDTableMutex);
        
        return PossibleFD;
    }
    else
    {
        /* Operation failed, so reset to false */
        OS_FDTable[PossibleFD].IsValid = FALSE;
        pthread_mutex_unlock(&OS_FDTableMutex);
        return OS_FS_ERROR;
    }
 
} /* end OS_open */
コード例 #13
0
ファイル: osfileapi.c プロジェクト: gpgreen/osal-beagleboard
int32 OS_mv (const char *src, const char *dest)
{
    int status,i;
    char src_path[OS_MAX_LOCAL_PATH_LEN];
    char dest_path[OS_MAX_LOCAL_PATH_LEN];

    /*
    ** Check to see if the path pointers are NULL
    */    
    if (src == NULL || dest == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Check to see if the paths are too long
    */
    if (strlen(src) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }
    
    if (strlen(dest) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }

    /* 
    ** check if the names of the files are too long 
    */
    if (OS_check_name_length(src) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }

    if (OS_check_name_length(dest) != OS_FS_SUCCESS)
    {
        return OS_FS_ERR_NAME_TOO_LONG;
    }


    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(src, (char *)src_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }

    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(dest, (char *)dest_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }


    status = rename((const char*)src_path, (const char *)dest_path);

    if (status != ERROR)
    {
        for ( i =0; i < OS_MAX_NUM_OPEN_FILES; i++) 
        {
            if (strcmp(OS_FDTable[i].Path, src) == 0 &&
                OS_FDTable[i].IsValid == TRUE)
            {
                strncpy (OS_FDTable[i].Path, dest, OS_MAX_PATH_LEN);  
            } 
        }
        return OS_FS_SUCCESS;
    }
    else
    {
        return OS_FS_ERROR;
    }
}/*end OS_mv */