Beispiel #1
0
int _rename_r( struct _reent *r, const char *oldname, const char *newname )
{
    char *actname_old, *actname_new;
    int devid_old, devid_new;
    const DM_INSTANCE_DATA *pinst;

    // Look for device, return error if not found or if function not implemented
    if( ( devid_old = find_dm_entry( oldname, &actname_old ) ) == -1 )
    {
        r->_errno = ENODEV;
        return -1;
    }
    if( ( devid_new = find_dm_entry( newname, &actname_new ) ) == -1 )
    {
        r->_errno = ENODEV;
        return -1;
    }
    if( devid_old == devid_new )
    {
        pinst = dm_get_instance_at( devid_old );
        if( pinst->pdev->p_rename_r == NULL )
        {
            r->_errno = EPERM;
            return -1;
        }

        // Device found, call its function
        return pinst->pdev->p_rename_r( r, actname_old, actname_new, pinst->pdata );
    }
    // Cannot rename between different devices (EXDEV)
    r->_errno = EXDEV;
    return -1;
}
Beispiel #2
0
int _unlink_r( struct _reent *r, const char *fname )
{
  const DM_DEVICE* pdev;
  char* actname;
  int devid;
 
  if( !fname || *fname == '\0' )
  {
    r->_errno = ENOENT; 
    return -1;
  }
  // Look for device, return error if not found or if function not implemented
  if( ( devid = find_dm_entry( fname, &actname ) ) == -1 )
  {
    r->_errno = ENODEV;
    return -1; 
  }
  pdev = dm_get_device_at( devid );
  if( pdev->p_unlink_r == NULL )
  {
    r->_errno = ENOSYS;
    return -1;   
  }
 
  // And call the unlink function
  return pdev->p_unlink_r( r, actname );  
}
Beispiel #3
0
// ****************************************************************************
// _mkdir_r
int _mkdir_r( struct _reent *r, const char *path, mkdir_mode_t mode )
{
	char *actname;
	int res, devid;
	const DM_INSTANCE_DATA *pinst;

	// Look for device, return error if not found or if function not implemented
	if( ( devid = find_dm_entry( path, &actname ) ) == -1 ) {
		r->_errno = ENODEV;
		return -1;
	}
	pinst = dm_get_instance_at( devid );
	if( pinst->pdev->p_mkdir_r == NULL ) {
		r->_errno = EPERM;
		return -1;
	}

	// Device found, call its function
	return pinst->pdev->p_mkdir_r( r, actname - 1, mode, pinst->pdata );
}
Beispiel #4
0
int rmdir( const char *path )
{
    char* actname;
    int devid;
    const DM_INSTANCE_DATA *pinst;

    // Look for device, return error if not found or if function not implemented
    if( ( devid = find_dm_entry( path, &actname ) ) == -1 )
    {
        _REENT->_errno = ENODEV;
        return -1;
    }
    pinst = dm_get_instance_at( devid );
    if( pinst->pdev->p_rmdir_r == NULL )
    {
        _REENT->_errno = ENOSYS;
        return -1;
    }

    // Device found, call its function
    return pinst->pdev->p_rmdir_r( _REENT, actname, pinst->pdata );
}
Beispiel #5
0
// ****************************************************************************
// _unlink_r
int _unlink_r( struct _reent *r, const char *fname )
{
    char* actname;
    int devid;
    const DM_INSTANCE_DATA *pinst;

    // Look for device, return error if not found or if function not implemented
    if( ( devid = find_dm_entry( fname, &actname ) ) == -1 )
    {
        r->_errno = ENODEV;
        return -1;
    }
    pinst = dm_get_instance_at( devid );
    if( pinst->pdev->p_unlink_r == NULL )
    {
        r->_errno = ENOSYS;
        return -1;
    }

    // Device found, call its function
    return pinst->pdev->p_unlink_r( r, actname, pinst->pdata );
}
Beispiel #6
0
// *****************************************************************************
// _open_r
int _open_r( struct _reent *r, const char *name, int flags, int mode )
{
	char *actname;
	int res, devid;
	const DM_INSTANCE_DATA *pinst;

	// Look for device, return error if not found or if function not implemented
	if( ( devid = find_dm_entry( name, &actname ) ) == -1 ) {
		r->_errno = ENODEV;
		return -1;
	}
	pinst = dm_get_instance_at( devid );
	if( pinst->pdev->p_open_r == NULL ) {
		r->_errno = ENOSYS;
		return -1;
	}

	// Device found, call its function
	if( ( res = pinst->pdev->p_open_r( r, actname, flags, mode, pinst->pdata ) ) < 0 )
		return res;
	return DM_MAKE_DESC( devid, res );
}