Пример #1
0
/*--------------------------------------------------------------------------------------
    Name: OS_fsBlocksFree

    Purpose: Returns the number of free blocks in a volume
 
    Returns: OS_FS_ERR_INVALID_POINTER if name is NULL
             OS_FS_ERR_PATH_TOO_LONG if the name is too long
             OS_FS_ERROR if the OS call failed
             The number of blocks free in a volume if success
---------------------------------------------------------------------------------------*/
int32 OS_fsBlocksFree (const char *name)
{

   int            status;
   int32          NameStatus;
   struct statvfs stat_buf;
   char           tmpFileName[OS_MAX_LOCAL_PATH_LEN +1];
   
   if ( name == NULL )
   {
      return(OS_FS_ERR_INVALID_POINTER);
   }
   
   /*
   ** Check the length of the volume name
   */
   if ( strlen(name) >= OS_MAX_PATH_LEN )
   {
      return(OS_FS_ERR_PATH_TOO_LONG);
   }

   /*
   ** Translate the path
   */
   NameStatus = OS_TranslatePath(name, tmpFileName);
   
   status = statvfs(tmpFileName, &stat_buf);
   
   if ( status == 0 )
   {
      return(stat_buf.f_bfree);
   }
   return OS_FS_ERROR;

}/* end OS_fsBlocksFree */
Пример #2
0
int32 OS_stat   (const char *path, os_fstat_t  *filestats)
{
    int ret_val;
    char local_path[OS_MAX_LOCAL_PATH_LEN];
  
    /*
    ** Check to see if the file pointers are NULL
    */
    if (path == NULL || filestats == 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;

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

    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
/*--------------------------------------------------------------------------------------
    Name: OS_FS_GetPhysDriveName

    Purpose: Gets the name of the physical volume underneith the drive,
             when given the mount point of the drive

    Returns: OS_FS_ERR_INVALID_POINTER if either  parameter is NULL
             OS_SUCCESS if success
             OS_FS_ERROR if the mountpoint could not be found
---------------------------------------------------------------------------------------*/
int32 OS_FS_GetPhysDriveName(char * PhysDriveName, char * MountPoint)
{
    char LocalDrvName [OS_MAX_LOCAL_PATH_LEN];
    int32 ReturnCode;
    int32 status;

    if (MountPoint == NULL || PhysDriveName == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Translate the path
    */
    status = OS_TranslatePath((const char *)MountPoint, (char *)LocalDrvName);
    if (status != OS_SUCCESS)
    {
        ReturnCode = OS_FS_ERROR;
    }
    else
    {
        ReturnCode = OS_SUCCESS;
        strcpy(PhysDriveName,LocalDrvName);
    }

    return ReturnCode;
}/* end OS_FS_GetPhysDriveName */
Пример #4
0
/*--------------------------------------------------------------------------------------
    Name: OS_chkfs
    
    Purpose: Checks the drives for inconsisenties and either repairs it or not

    Returns: OS_FS_ERR_INVALID_POINTER if name is NULL
             OS_FS_SUCCESS if success
             OS_FS_ERROR if the OS calls fail

---------------------------------------------------------------------------------------*/
os_fshealth_t OS_chkfs (const char *name, boolean repair)
{  
    STATUS chk_status;
    int32  osal_status;
    int    fd;
    char   local_path [OS_MAX_LOCAL_PATH_LEN];

    /*
    ** Check for a null pointer
    */
    if (name == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Check the length of the volume name
    */
    if ( strlen(name) >= OS_MAX_PATH_LEN )
    {
       return(OS_FS_ERR_PATH_TOO_LONG);
    } 

    osal_status = OS_TranslatePath(name, (char *)local_path);

    fd = open (local_path, O_RDONLY, 0);
    if (fd == ERROR)
    {
        return OS_FS_ERROR;
    }
    
    /* Fix the disk if there are errors */
    if (repair == 1)
    {
        chk_status = ioctl(fd, FIOCHKDSK, DOS_CHK_REPAIR | DOS_CHK_VERB_SILENT);
        close(fd);
        if (chk_status == OK)
            return OS_FS_SUCCESS;
        else
            return OS_FS_ERROR;
    }
    
    /* only check the disk, don't fix anything */
    else
    {
        chk_status = ioctl(fd, FIOCHKDSK, DOS_CHK_ONLY | DOS_CHK_VERB_SILENT);
        close(fd);
        if (chk_status == OK)
           return OS_FS_SUCCESS;
        else
            return OS_FS_ERROR;
    }

    /* code should never get here */
    return OS_FS_ERROR;
}/* end OS_chkfs */
Пример #5
0
/*--------------------------------------------------------------------------------------
    Name: OS_unmount
    
    Purpose: unmounts a drive. and therefore makes all file descriptors pointing into
             the drive obsolete.

    Returns: OS_FS_ERR_INVALID_POINTER if name is NULL
             OS_FS_ERR_PATH_TOO_LONG if the absolute path given is too long
             OS_FS_ERROR if the OS calls failed
             OS_FS_SUCCESS if success
---------------------------------------------------------------------------------------*/
int32 OS_unmount (const char* mountpoint)
{

    int    fd;
    STATUS ret_status;
    int32  osal_status;
    char   local_path [OS_MAX_LOCAL_PATH_LEN];
    int    i;

    if (mountpoint == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    if (strlen(mountpoint) >= OS_MAX_PATH_LEN)
    {
        return OS_FS_ERR_PATH_TOO_LONG;
    }
 
    osal_status = OS_TranslatePath(mountpoint, (char *)local_path);  
    
    /* find the device in the table */
    for (i = 0; i < NUM_TABLE_ENTRIES; i++)
    {
        if (OS_VolumeTable[i].FreeFlag == FALSE && OS_VolumeTable[i].IsMounted == TRUE
             && strcmp(OS_VolumeTable[i].MountPoint, mountpoint) == 0)
            break;
    }

    /* make sure we found the device */
    if (i >= NUM_TABLE_ENTRIES)
        return OS_FS_ERROR;

    fd = open(local_path,O_RDONLY,0);
    
    if (fd == ERROR)
    {
        return OS_FS_ERROR;
    }

    ret_status = ioctl( fd, FIOUNMOUNT,0);

    /* no need to close the fd, because ioctl is doing that for us */

    /* release the informationm from the table */
   OS_VolumeTable[i].IsMounted = FALSE;
   strcpy(OS_VolumeTable[i].MountPoint, "");
    
    if (ret_status == OK)
        return OS_FS_SUCCESS;
    else
        return OS_FS_ERROR;
    
}/* end OS_umount */
Пример #6
0
/*--------------------------------------------------------------------------------------
    Name: OS_fsBytesFree

    Purpose: Returns the number of free bytes in a volume
 
    Returns: OS_FS_ERR_INVALID_POINTER if name is NULL
             OS_FS_ERR_PATH_TOO_LONG if the name is too long
             OS_FS_ERROR if the OS call failed
             OS_FS_SUCCESS if the call succeeds 
---------------------------------------------------------------------------------------*/
int32 OS_fsBytesFree (const char *name, uint64 *bytes_free)
{
   int               status;
   rtems_status_code rtems_sc;
   int32             NameStatus;
   struct statvfs    stat_buf;
   uint64            bytes_free_local;
   char              tmpFileName[OS_MAX_LOCAL_PATH_LEN +1];

   if ( name == NULL || bytes_free == NULL )
   {
      return(OS_FS_ERR_INVALID_POINTER);
   }

   /*
   ** Check the length of the volume name
   */
   if ( strlen(name) >= OS_MAX_PATH_LEN )
   {
      return(OS_FS_ERR_PATH_TOO_LONG);
   }

   /*
   ** Translate the path
   */
   NameStatus = OS_TranslatePath(name, tmpFileName);

   /*
   ** Lock 
   */
   rtems_sc = rtems_semaphore_obtain (OS_VolumeTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);

   status = statvfs(tmpFileName, &stat_buf);

   /*
   ** Unlock
   */
   rtems_sc = rtems_semaphore_release (OS_VolumeTableSem);

   if ( status == 0 )
   {
      bytes_free_local = stat_buf.f_bfree * stat_buf.f_bsize;
      *bytes_free = bytes_free_local;
      return(OS_FS_SUCCESS);
   }
   else
   {
      return(OS_FS_ERROR);
   }

}/* end OS_fsBytesFree */
Пример #7
0
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 */
Пример #8
0
int32 OS_mkdir (const char *path, uint32 access)
{
   int status;
   mode_t mode;
   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;
    }


    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }
    
    mode = S_IFDIR |S_IRWXU | S_IRWXG | S_IRWXO;
    status = mkdir(local_path, mode);

    if (status != ERROR)
    {
        return OS_FS_SUCCESS;
    }
    else
    {
        return OS_FS_ERROR;
    }
    
}/* end OS_mkdir */
Пример #9
0
int32  OS_rmdir (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;
    }


    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return OS_FS_ERR_PATH_INVALID;
    }
    
    status = rmdir(local_path);
    
    if (status != ERROR)
    {
        return OS_FS_SUCCESS;
    }
    else
    {
        return OS_FS_ERROR;
    }
    
}/* end OS_rmdir */
Пример #10
0
os_dirp_t OS_opendir (const char *path)
{

    os_dirp_t dirdescptr;
    char local_path[OS_MAX_LOCAL_PATH_LEN];

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

    /*
    ** Check to see if the path is too long
    */      
    if (strlen(path) > OS_MAX_PATH_LEN)
    {
        return NULL;
    }
   
    /*
    ** Translate the path
    */
    if ( OS_TranslatePath(path, (char *)local_path) != OS_FS_SUCCESS )
    {
        return NULL;
    }
   
    dirdescptr = opendir( (char*) local_path);
    
    if (dirdescptr == NULL)
    {
        return NULL;
    }
    else
    {
        return dirdescptr;
    }
    
} /* end OS_opendir */
Пример #11
0
/*--------------------------------------------------------------------------------------
    Name: OS_fsBlocksFree

    Purpose: Returns the number of free blocks in a volume

    Returns: OS_FS_INVALID_POINTER if name is NULL
             OS_FS_ERROR if the OS call failed
             The number of bytes free in a volume if success
---------------------------------------------------------------------------------------*/
int32 OS_fsBlocksFree (const char *name)
{

   int           status;
   int32         NameStatus;
   struct statfs stat_buf;
   char          tmpFileName[128];

   if ( name == NULL )
   {
      return(OS_FS_ERR_INVALID_POINTER);
   }
   strncpy(tmpFileName,name,128);
   NameStatus = OS_TranslatePath(name, tmpFileName);
   status = statfs(tmpFileName, &stat_buf);

   if ( status == 0 )
   {
      return(stat_buf.f_bfree);
   }
   return OS_FS_ERROR;

}/* end OS_fsBlocksFree */
Пример #12
0
/*--------------------------------------------------------------------------------------
    Name: OS_fsBytesFree

    Purpose: Returns the number of free bytes in a volume
 
    Returns: OS_FS_ERR_INVALID_POINTER if name is NULL
             OS_FS_ERR_PATH_TOO_LONG if the name is too long
             OS_FS_ERROR if the OS call failed
             OS_FS_SUCCESS if success
---------------------------------------------------------------------------------------*/
int32 OS_fsBytesFree (const char *name, uint64 *bytes_free)
{
   int             status;
   int32           NameStatus;
   struct statvfs  stat_buf;
   uint64          bytes_free_local;
   char            tmpFileName[OS_MAX_LOCAL_PATH_LEN +1];

   if ( name == NULL || bytes_free == NULL )
   {
      return(OS_FS_ERR_INVALID_POINTER);
   }

   /*
   ** Check the length of the volume name
   */
   if ( strlen(name) >= OS_MAX_PATH_LEN )
   {
      return(OS_FS_ERR_PATH_TOO_LONG);
   }

   /*
   ** Translate the path
   */
   NameStatus = OS_TranslatePath(name, tmpFileName);

   status = statvfs(tmpFileName, &stat_buf);
   if ( status == 0 )
   {
      bytes_free_local = stat_buf.f_bfree * stat_buf.f_bsize;
      *bytes_free = bytes_free_local;
      return(OS_FS_SUCCESS);
   }
   return(OS_FS_ERROR);

}/* end OS_fsBytesFree */
Пример #13
0
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 */
Пример #14
0
/*--------------------------------------------------------------------------------------
    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 */
Пример #15
0
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 */
Пример #16
0
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 */
Пример #17
0
int32 OS_fsBytesFree (const char *name, uint64 *bytes_free)
{
    int    fd;
    int    i;
    STATUS status;
    uint64 bytes_free_local;
    int32  osal_status;
    char   local_path [OS_MAX_LOCAL_PATH_LEN];

    /*
    ** check for a NULL pointer
    */
    if (name == NULL || bytes_free == NULL)
    {
        return OS_FS_ERR_INVALID_POINTER;
    }

    /*
    ** Check the length of the volume name
    */
    if ( strlen(name) >= OS_MAX_PATH_LEN )
    {
       return(OS_FS_ERR_PATH_TOO_LONG);
    } 

    /*
    ** Search for the volume
    */
    for (i = 0; i < NUM_TABLE_ENTRIES; i++)
    {
        if (OS_VolumeTable[i].FreeFlag == FALSE && OS_VolumeTable[i].IsMounted == TRUE
             && strcmp(OS_VolumeTable[i].MountPoint, name) == 0)
            break;
    }

    /*
    **  make sure we found the device 
    */
    if (i >= NUM_TABLE_ENTRIES)
    {
        return OS_FS_ERROR;
    }

    /*
    ** get the local name
    */
    osal_status = OS_TranslatePath((const char *)name, (char *)local_path);
  
    /*
    ** Try to open the file
    */ 
    fd = open (local_path, O_RDONLY, 0);
    if (fd == ERROR)
    {
       if ( errnoGet() ==  ENOSPC )
       {
          /*
          ** There is no space to even open the file, so return 0 blocks free.
          */
          *bytes_free = 0;
          return OS_FS_SUCCESS;
       }
       else
       {
          return OS_FS_ERROR;
       }
    }

    /*
    ** Find out how much space is available
    */
    status = ioctl(fd, FIONFREE64, (unsigned long ) &bytes_free_local);
    if (status == ERROR)
    {
        close(fd);
        return OS_FS_ERROR;
    }

    /*
    ** Close the file
    */
    close(fd);    

    /*
    ** Assign the free bytes value 
    */
    *bytes_free = bytes_free_local;

    return (OS_FS_SUCCESS);
    
}
Пример #18
0
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 */
Пример #19
0
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 */
Пример #20
0
/*--------------------------------------------------------------------------------------
    Name: OS_unmount
    
    Purpose: unmounts a drive. and therefore makes all file descriptors pointing into
             the drive obsolete.

    Returns: OS_FS_ERR_INVALID_POINTER if name is NULL
             OS_FS_ERR_PATH_TOO_LONG if the absolute path given is too long
             OS_FS_ERROR if the OS calls failed
             OS_FS_SUCCESS if success
---------------------------------------------------------------------------------------*/
int32 OS_unmount (const char *mountpoint)
{
   char              local_path [OS_MAX_LOCAL_PATH_LEN];
   int32             status;
   rtems_status_code rtems_sc;
   int               i;
    
   if (mountpoint == NULL)
   {
       return OS_FS_ERR_INVALID_POINTER;
   }

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

   status = OS_TranslatePath(mountpoint, (char *)local_path);
    
   /*
   ** Lock 
   */
   rtems_sc = rtems_semaphore_obtain (OS_VolumeTableSem, RTEMS_WAIT, RTEMS_NO_TIMEOUT);

   for (i = 0; i < NUM_TABLE_ENTRIES; i++)
   {
       if (OS_VolumeTable[i].FreeFlag == FALSE && OS_VolumeTable[i].IsMounted == TRUE
            && strcmp(OS_VolumeTable[i].MountPoint, mountpoint) == 0)
           break;
   }

   /* make sure we found the device */
   if (i >= NUM_TABLE_ENTRIES)
   {
       printf("OSAL: Error: unmount of %s failed: invalid volume table entry.\n",
                     local_path);
       rtems_sc = rtems_semaphore_release (OS_VolumeTableSem);
       return OS_FS_ERROR;
   }

   if (OS_VolumeTable[i].VolumeType == RAM_DISK)
   {
      /*
      ** Try to unmount the disk
      */
      if ( unmount(local_path) < 0) 
      {
         printf("OSAL: RTEMS unmount of %s failed :%s\n",local_path, strerror(errno));
         rtems_sc = rtems_semaphore_release (OS_VolumeTableSem);
         return OS_FS_ERROR;
      } 

      /* release the information from the table */
      OS_VolumeTable[i].IsMounted = FALSE;
      strcpy(OS_VolumeTable[i].MountPoint, "");
  
   } 
   else if ( OS_VolumeTable[i].VolumeType == FS_BASED )
   {

      /* release the information from the table */
      OS_VolumeTable[i].IsMounted = FALSE;
      strcpy(OS_VolumeTable[i].MountPoint, "");

   } 
   else
   {
       /* 
       ** VolumeType is not supported right now 
       */
       rtems_sc = rtems_semaphore_release (OS_VolumeTableSem);
       return OS_FS_ERROR;
   }

   /*
   ** Unlock
   */
   rtems_sc = rtems_semaphore_release (OS_VolumeTableSem);
   return OS_FS_SUCCESS;
    
}/* end OS_umount */
Пример #21
0
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 */
Пример #22
0
/*--------------------------------------------------------------------------------------
    Name: OS_ModuleLoad
    
    Purpose: Loads an object file into the running operating system

    Parameters: 

    Returns: OS_ERROR if the module cannot be loaded
             OS_INVALID_POINTER if one of the parameters is NULL
             OS_ERR_NO_FREE_IDS if the module table is full
             OS_ERR_NAME_TAKEN if the name is in use
             OS_SUCCESS if the module is loaded successfuly
---------------------------------------------------------------------------------------*/
int32 OS_ModuleLoad ( uint32 *module_id, const char *module_name, const char *filename )
{
   int         i;
   uint32      possible_moduleid;
   char        translated_path[OS_MAX_LOCAL_PATH_LEN];
   int32       return_code;
   void       *function_lib;     /*  Handle to shared lib file */
   const char *dl_error;    /*  Pointer to error string   */
   sigset_t    previous;
   sigset_t    mask;

   /*
   ** Check parameters
   */
   if (( filename == NULL ) || (module_id == NULL ) || (module_name == NULL))
   {
      return(OS_INVALID_POINTER);
   }
 
   OS_InterruptSafeLock(&OS_module_table_mut, &mask, &previous); 

   /*
   ** Find a free module id
   */
   for( possible_moduleid = 0; possible_moduleid < OS_MAX_MODULES; possible_moduleid++)
   {
       if (OS_module_table[possible_moduleid].free == TRUE)
       {
           break;
       }
   }

   /* 
   ** Check to see if the id is out of bounds 
   */
   if( possible_moduleid >= OS_MAX_MODULES || OS_module_table[possible_moduleid].free != TRUE)
   {
       OS_InterruptSafeUnlock(&OS_module_table_mut, &previous); 
       return OS_ERR_NO_FREE_IDS;
   }

   /* 
   ** Check to see if the module file is already loaded 
   */
   for (i = 0; i < OS_MAX_MODULES; i++)
   {
       if ((OS_module_table[i].free == FALSE) &&
          ( strcmp((char*) module_name, OS_module_table[i].name) == 0)) 
       {       
           OS_InterruptSafeUnlock(&OS_module_table_mut, &previous); 
           return OS_ERR_NAME_TAKEN;
       }
   }

   /* 
   ** Set the possible task Id to not free so that
   ** no other task can try to use it 
   */
   OS_module_table[possible_moduleid].free = FALSE ;
   OS_InterruptSafeUnlock(&OS_module_table_mut, &previous); 
 
   /*
   ** Translate the filename to the Host System
   */     
   return_code = OS_TranslatePath((const char *)filename, (char *)translated_path); 
   if ( return_code != OS_SUCCESS )
   {
      OS_module_table[possible_moduleid].free = TRUE;
      return(return_code);
   }

   /*
   ** File is ready to load
   */
   
   /* 
   ** Open the loadble bundle .. just opening it loads it into the system.
   */
   function_lib = dlopen(translated_path, RTLD_LAZY | RTLD_GLOBAL);
   dl_error = dlerror();
   if( dl_error )
   {
      OS_module_table[possible_moduleid].free = TRUE;
      return(OS_ERROR);
   }

   /*
   ** fill out the OS_module_table entry for this new module
   */
   OS_module_table[possible_moduleid].entry_point = 0; /* Only for certain targets */
   OS_module_table[possible_moduleid].host_module_id = function_lib;
   strncpy(OS_module_table[possible_moduleid].filename , filename, OS_MAX_PATH_LEN);
   strncpy(OS_module_table[possible_moduleid].name , module_name, OS_MAX_API_NAME);
 
   /*
   ** Return the OSAPI Module ID
   */
   *module_id = possible_moduleid;
     
   return(OS_SUCCESS);
   
}/* end OS_ModuleLoad */
Пример #23
0
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 */