Example #1
0
File: win32.c Project: Gatada/atv2
/*!
  Initialization routine. This is the only thing that doesn't
  get called via a function pointer. In fact *we* are the
  ones to set that up.
 */
CdIo *
cdio_open_am_win32 (const char *psz_orig_source, const char *psz_access_mode)
{

#ifdef HAVE_WIN32_CDROM
  CdIo *ret;
  _img_private_t *_data;
  char *psz_source;

  cdio_funcs_t _funcs;

  memset( &_funcs, 0, sizeof(_funcs) );

  _funcs.eject_media        = _cdio_eject_media;
  _funcs.free               = _free_win32;
  _funcs.get_arg            = _get_arg_win32;
  _funcs.get_cdtext         = get_cdtext_generic;
  _funcs.get_default_device = cdio_get_default_device_win32;
  _funcs.get_devices        = cdio_get_devices_win32;
  _funcs.get_disc_last_lsn     = get_disc_last_lsn_win32;
  _funcs.get_discmode       = get_discmode_win32;
  _funcs.get_drive_cap         = get_drive_cap_mmc;
  _funcs.get_first_track_num= get_first_track_num_generic;
  _funcs.get_hwinfo         = NULL;
  _funcs.get_mcn            = _cdio_get_mcn;
  _funcs.get_num_tracks     = get_num_tracks_generic;
  _funcs.get_track_channels    = get_track_channels_generic,
  _funcs.get_track_copy_permit = get_track_copy_permit_generic,
  _funcs.get_track_format   = _cdio_get_track_format;
  _funcs.get_track_green    = _cdio_get_track_green;
  _funcs.get_track_lba         = NULL; /* This could be done if need be. */
  _funcs.get_track_msf      = _cdio_get_track_msf;
  _funcs.get_track_preemphasis = get_track_preemphasis_generic,
  _funcs.lseek              = NULL;
  _funcs.read               = NULL;
  _funcs.read_audio_sectors = _cdio_read_audio_sectors;
  _funcs.read_mode1_sector  = _cdio_read_mode1_sector;
  _funcs.read_mode1_sectors = _cdio_read_mode1_sectors;
  _funcs.read_mode2_sector  = _cdio_read_mode2_sector;
  _funcs.read_mode2_sectors = _cdio_read_mode2_sectors;
  _funcs.read_toc           = &read_toc_win32;
  _funcs.run_scsi_mmc_cmd   = &run_scsi_cmd_win32;
  _funcs.set_arg            = set_arg_win32;
  _funcs.set_blocksize         = set_blocksize_mmc;
  _funcs.set_speed             = set_speed_mmc;

  _data                 = _cdio_malloc (sizeof (_img_private_t));
  _data->access_mode    = str_to_access_mode_win32(psz_access_mode);
  _data->gen.init       = false;
  _data->gen.fd         = -1;

  if (NULL == psz_orig_source) {
    psz_source=cdio_get_default_device_win32();
    if (NULL == psz_source) return NULL;
    set_arg_win32(_data, "source", psz_source);
    free(psz_source);
  } else {
    if (cdio_is_device_win32(psz_orig_source))
      set_arg_win32(_data, "source", psz_orig_source);
    else {
      /* The below would be okay if all device drivers worked this way. */
#if 0
      cdio_info ("source %s is a not a device", psz_orig_source);
#endif
      free(_data);
      return NULL;
    }
  }

  ret = cdio_new ((void *)_data, &_funcs);
  if (ret == NULL) return NULL;

  if (_cdio_init_win32(_data))
    return ret;
  else {
    _free_win32 (_data);
    return NULL;
  }
  
#else 
  return NULL;
#endif /* HAVE_WIN32_CDROM */

}
Example #2
0
/*!
  Initialization routine. This is the only thing that doesn't
  get called via a function pointer. In fact *we* are the
  ones to set that up.
 */
CdIo_t *
cdio_open_am_win32 (const char *psz_orig_source, const char *psz_access_mode)
{

#ifdef HAVE_WIN32_CDROM
  CdIo_t *ret;
  _img_private_t *_data;
  char *psz_source;

  cdio_funcs_t _funcs;

  memset( &_funcs, 0, sizeof(_funcs) );

  _funcs.audio_get_volume       = audio_get_volume_win32;
  _funcs.audio_pause            = audio_pause_win32;
  _funcs.audio_play_msf         = audio_play_msf_win32;
#if 0
  _funcs.audio_play_track_index = audio_play_track_index_win32;
#endif
  _funcs.audio_read_subchannel  = audio_read_subchannel_win32;
  _funcs.audio_resume           = audio_resume_win32;
  _funcs.audio_set_volume       = audio_set_volume_win32;
  _funcs.audio_stop             = audio_stop_win32;
  _funcs.eject_media            = eject_media_win32;
  _funcs.free                   = free_win32;
  _funcs.get_arg                = get_arg_win32;
  _funcs.get_cdtext             = get_cdtext_generic;
  _funcs.get_cdtext_raw         = read_cdtext_generic;
  _funcs.get_default_device     = cdio_get_default_device_win32;
  _funcs.get_devices            = cdio_get_devices_win32;
  _funcs.get_disc_last_lsn      = get_disc_last_lsn_win32;
  _funcs.get_discmode           = get_discmode_win32;
  _funcs.get_drive_cap          = get_drive_cap_mmc;
  _funcs.get_first_track_num    = get_first_track_num_generic;
  _funcs.get_hwinfo             = NULL;
  _funcs.get_media_changed      = get_media_changed_mmc;
  _funcs.get_mcn                = _cdio_get_mcn;
  _funcs.get_num_tracks         = get_num_tracks_generic;
  _funcs.get_track_channels     = get_track_channels_generic,
  _funcs.get_track_copy_permit  = get_track_copy_permit_generic,
  _funcs.get_track_format       = _cdio_get_track_format;
  _funcs.get_track_green        = _cdio_get_track_green;
  _funcs.get_track_lba          = NULL; /* This could be done if need be. */
  _funcs.get_track_msf          = _cdio_get_track_msf;
  _funcs.get_track_preemphasis  = get_track_preemphasis_generic,
  _funcs.lseek                  = NULL;
  _funcs.read                   = NULL;
  _funcs.read_audio_sectors     = read_audio_sectors;
  _funcs.read_data_sectors      = read_data_sectors_win32;
  _funcs.read_mode1_sector      = read_mode1_sector_win32;
  _funcs.read_mode1_sectors     = read_mode1_sectors_win32;
  _funcs.read_mode2_sector      = read_mode2_sector_win32;
  _funcs.read_mode2_sectors     = read_mode2_sectors_win32;
  _funcs.read_toc               = read_toc_win32;
  _funcs.run_mmc_cmd            = run_mmc_cmd_win32;
  _funcs.set_arg                = set_arg_win32;
  _funcs.set_blocksize          = set_blocksize_mmc;
  _funcs.set_speed              = set_drive_speed_mmc;

  _data                 = calloc(1, sizeof (_img_private_t));
  _data->access_mode    = str_to_access_mode_win32(psz_access_mode);
  _data->gen.init       = false;
  _data->gen.fd         = -1;

  if (NULL == psz_orig_source) {
    psz_source=cdio_get_default_device_win32();
    if (NULL == psz_source) return NULL;
    set_arg_win32(_data, "source", psz_source);
    free(psz_source);
  } else {
    if (cdio_is_device_win32(psz_orig_source))
      set_arg_win32(_data, "source", psz_orig_source);
    else {
      /* The below would be okay as an info message if all device
	 drivers worked this way. */
      cdio_debug ("source %s is a not a device", psz_orig_source);
      free(_data);
      return NULL;
    }
  }

  ret = cdio_new ((void *)_data, &_funcs);
  if (ret == NULL) return NULL;

  if (init_win32(_data))
    return ret;
  else {
    free_win32 (_data);
    return NULL;
  }
  
#else 
  return NULL;
#endif /* HAVE_WIN32_CDROM */

}
Example #3
0
/*!
  Initialize internal structures for CD device.
 */
bool
init_win32ioctl (_img_private_t *env)
{
#ifdef WIN32
  OSVERSIONINFO ov;
#endif

#ifdef _XBOX
  ANSI_STRING filename;
  OBJECT_ATTRIBUTES attributes;
  IO_STATUS_BLOCK status;
  HANDLE hDevice;
  NTSTATUS error;
#else
  unsigned int len=strlen(env->gen.source_name);
  char psz_win32_drive[7];
  DWORD dw_access_flags;
#endif
  
  cdio_debug("using winNT/2K/XP ioctl layer");

#ifdef WIN32
  memset(&ov,0,sizeof(OSVERSIONINFO));
  ov.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
  GetVersionEx(&ov);
  
  if((ov.dwPlatformId==VER_PLATFORM_WIN32_NT) &&        
     (ov.dwMajorVersion>4))
    dw_access_flags = GENERIC_READ|GENERIC_WRITE;  /* add gen write on W2k/XP */
  else dw_access_flags = GENERIC_READ;
#endif

  if (cdio_is_device_win32(env->gen.source_name)) 
  {
#ifdef _XBOX
    //	Use XBOX cdrom, no matter what drive letter is given.
    RtlInitAnsiString(&filename,"\\Device\\Cdrom0");
    InitializeObjectAttributes(&attributes, &filename, OBJ_CASE_INSENSITIVE,
			       NULL);
    error = NtCreateFile( &hDevice, 
			  GENERIC_READ |SYNCHRONIZE | FILE_READ_ATTRIBUTES, 
			  &attributes, 
			  &status, 
			  NULL, 
			  0,
			  FILE_SHARE_READ,
			  FILE_OPEN,	
			  FILE_NON_DIRECTORY_FILE 
			  | FILE_SYNCHRONOUS_IO_NONALERT );
    
    if (!NT_SUCCESS(error))
    {
	  return false;
    }
	env->h_device_handle = hDevice;
#else
    sprintf( psz_win32_drive, "\\\\.\\%c:", env->gen.source_name[len-2] );

    env->h_device_handle = CreateFile( psz_win32_drive, 
				       dw_access_flags,
				       FILE_SHARE_READ | FILE_SHARE_WRITE, 
				       NULL, 
				       OPEN_EXISTING,
				       FILE_ATTRIBUTE_NORMAL, 
				       NULL );

    if( env->h_device_handle == INVALID_HANDLE_VALUE )
    {
	  /* No good. try toggle write. */
	  dw_access_flags ^= GENERIC_WRITE;  
	  env->h_device_handle = CreateFile( psz_win32_drive, 
					     dw_access_flags, 
					     FILE_SHARE_READ,  
					     NULL, 
					     OPEN_EXISTING, 
					     FILE_ATTRIBUTE_NORMAL, 
					     NULL );
	  if (env->h_device_handle == NULL)
		return false;
    }
#endif
    env->b_ioctl_init = true;
    return true;
  }
  return false;
}