1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /* Main file for CD-ROM support
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1999, 2001 Eric Pouech
6 * Copyright 2000 Andreas Mohr
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
37 #include <sys/types.h>
39 #ifdef HAVE_SYS_IOCTL_H
40 #include <sys/ioctl.h>
45 #ifdef HAVE_LINUX_MAJOR_H
46 # include <linux/major.h>
48 #ifdef HAVE_LINUX_HDREG_H
49 # include <linux/hdreg.h>
51 #ifdef HAVE_LINUX_PARAM_H
52 # include <linux/param.h>
54 #ifdef HAVE_LINUX_CDROM_H
55 # include <linux/cdrom.h>
57 #ifdef HAVE_LINUX_UCDROM_H
58 # include <linux/ucdrom.h>
60 #ifdef HAVE_SYS_CDIO_H
61 # include <sys/cdio.h>
71 #include "wine/debug.h"
73 WINE_DEFAULT_DEBUG_CHANNEL(cdrom
);
78 # define IDE6_MAJOR 88
81 # define IDE7_MAJOR 89
84 # ifdef CDROM_SEND_PACKET
85 /* structure for CDROM_PACKET_COMMAND ioctl */
86 /* not all Linux versions have all the fields, so we define the
87 * structure ourselves to make sure */
88 struct linux_cdrom_generic_command
90 unsigned char cmd
[CDROM_PACKET_SIZE
];
91 unsigned char *buffer
;
94 struct request_sense
*sense
;
95 unsigned char data_direction
;
100 # endif /* CDROM_SEND_PACKET */
104 /* FIXME: this is needed because we can't open simultaneously several times /dev/cdrom
105 * this should be removed when a proper device interface is implemented
111 static struct cdrom_cache cdrom_cache
[26];
113 /******************************************************************
114 * CDROM_GetIdeInterface
116 * Determines the ide interface (the number after the ide), and the
117 * number of the device on that interface for ide cdroms.
118 * Returns false if the info could not be get
120 * NOTE: this function is used in CDROM_InitRegistry and CDROM_GetAddress
122 static int CDROM_GetIdeInterface(int dev
, int* iface
, int* device
)
127 #ifdef SG_EMULATED_HOST
128 if (ioctl(dev
, SG_EMULATED_HOST
) != -1) {
129 FIXME("not implemented for true scsi drives\n");
133 if ( fstat(dev
, &st
) == -1 || ! S_ISBLK(st
.st_mode
)) {
134 FIXME("cdrom not a block device!!!\n");
137 switch (major(st
.st_rdev
)) {
138 case IDE0_MAJOR
: *iface
= 0; break;
139 case IDE1_MAJOR
: *iface
= 1; break;
140 case IDE2_MAJOR
: *iface
= 2; break;
141 case IDE3_MAJOR
: *iface
= 3; break;
142 case IDE4_MAJOR
: *iface
= 4; break;
143 case IDE5_MAJOR
: *iface
= 5; break;
144 case IDE6_MAJOR
: *iface
= 6; break;
145 case IDE7_MAJOR
: *iface
= 7; break;
146 case SCSI_CDROM_MAJOR
: *iface
= 11; break;
148 FIXME("CD-ROM device with major ID %d not supported\n", major(st
.st_rdev
));
151 *device
= (minor(st
.st_rdev
) == 63 ? 1 : 0);
154 #elif defined(__FreeBSD__) || defined(__NetBSD__)
155 FIXME("not implemented for BSD\n");
158 FIXME("not implemented for nonlinux\n");
164 /******************************************************************
167 * Initializes registry to contain scsi info about the cdrom in NT.
168 * All devices (even not real scsi ones) have this info in NT.
169 * TODO: for now it only works for non scsi devices
170 * NOTE: programs usually read these registry entries after sending the
171 * IOCTL_SCSI_GET_ADDRESS ioctl to the cdrom
173 void CDROM_InitRegistry(int dev
)
175 int portnum
, targetid
;
177 OBJECT_ATTRIBUTES attr
;
178 UNICODE_STRING nameW
;
190 attr
.Length
= sizeof(attr
);
191 attr
.RootDirectory
= HKEY_LOCAL_MACHINE
;
192 attr
.ObjectName
= &nameW
;
194 attr
.SecurityDescriptor
= NULL
;
195 attr
.SecurityQualityOfService
= NULL
;
197 if ( ! CDROM_GetIdeInterface(dev
, &portnum
, &targetid
))
200 /* Ensure there is Scsi key */
201 if (!RtlCreateUnicodeStringFromAsciiz( &nameW
, "HARDWARE\\DEVICEMAP\\Scsi" ) ||
202 NtCreateKey( &scsiKey
, KEY_ALL_ACCESS
, &attr
, 0,
203 NULL
, REG_OPTION_VOLATILE
, &disp
))
205 ERR("Cannot create DEVICEMAP\\Scsi registry key\n" );
208 RtlFreeUnicodeString( &nameW
);
210 snprintf(buffer
,40,"Scsi Port %d",portnum
);
211 attr
.RootDirectory
= scsiKey
;
212 if (!RtlCreateUnicodeStringFromAsciiz( &nameW
, buffer
) ||
213 NtCreateKey( &portKey
, KEY_ALL_ACCESS
, &attr
, 0,
214 NULL
, REG_OPTION_VOLATILE
, &disp
))
216 ERR("Cannot create DEVICEMAP\\Scsi Port registry key\n" );
219 RtlFreeUnicodeString( &nameW
);
221 RtlCreateUnicodeStringFromAsciiz( &nameW
, "Driver" );
223 RtlMultiByteToUnicodeN( dataW
, 50, &lenW
, data
, strlen(data
));
224 NtSetValueKey( portKey
, &nameW
, 0, REG_SZ
, (BYTE
*)dataW
, lenW
);
225 RtlFreeUnicodeString( &nameW
);
227 RtlCreateUnicodeStringFromAsciiz( &nameW
, "FirstBusTimeScanInMs" );
228 NtSetValueKey( portKey
,&nameW
, 0, REG_DWORD
, (BYTE
*)&value
, sizeof(DWORD
));
229 RtlFreeUnicodeString( &nameW
);
232 if (ioctl(dev
,HDIO_GET_DMA
, &dma
) != -1) {
234 TRACE("setting dma to %lx\n", value
);
237 RtlCreateUnicodeStringFromAsciiz( &nameW
, "DMAEnabled" );
238 NtSetValueKey( portKey
,&nameW
, 0, REG_DWORD
, (BYTE
*)&value
, sizeof(DWORD
));
239 RtlFreeUnicodeString( &nameW
);
241 attr
.RootDirectory
= portKey
;
242 if (!RtlCreateUnicodeStringFromAsciiz( &nameW
, "Scsi Bus 0" ) ||
243 NtCreateKey( &busKey
, KEY_ALL_ACCESS
, &attr
, 0,
244 NULL
, REG_OPTION_VOLATILE
, &disp
))
246 ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus registry key\n" );
249 RtlFreeUnicodeString( &nameW
);
251 attr
.RootDirectory
= busKey
;
252 if (!RtlCreateUnicodeStringFromAsciiz( &nameW
, "Initiator Id 255" ) ||
253 NtCreateKey( &targetKey
, KEY_ALL_ACCESS
, &attr
, 0,
254 NULL
, REG_OPTION_VOLATILE
, &disp
))
256 ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus\\Initiator Id 255 registry key\n" );
259 RtlFreeUnicodeString( &nameW
);
260 NtClose( targetKey
);
262 snprintf(buffer
,40,"Target Id %d", targetid
);
263 attr
.RootDirectory
= busKey
;
264 if (!RtlCreateUnicodeStringFromAsciiz( &nameW
, buffer
) ||
265 NtCreateKey( &targetKey
, KEY_ALL_ACCESS
, &attr
, 0,
266 NULL
, REG_OPTION_VOLATILE
, &disp
))
268 ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus 0\\Target Id registry key\n" );
271 RtlFreeUnicodeString( &nameW
);
273 RtlCreateUnicodeStringFromAsciiz( &nameW
, "Type" );
274 data
= "CdRomPeripheral";
275 RtlMultiByteToUnicodeN( dataW
, 50, &lenW
, data
, strlen(data
));
276 NtSetValueKey( targetKey
, &nameW
, 0, REG_SZ
, (BYTE
*)dataW
, lenW
);
277 RtlFreeUnicodeString( &nameW
);
278 /* FIXME - maybe read the real identifier?? */
279 RtlCreateUnicodeStringFromAsciiz( &nameW
, "Identifier" );
281 RtlMultiByteToUnicodeN( dataW
, 50, &lenW
, data
, strlen(data
));
282 NtSetValueKey( targetKey
, &nameW
, 0, REG_SZ
, (BYTE
*)dataW
, lenW
);
283 RtlFreeUnicodeString( &nameW
);
284 /* FIXME - we always use Cdrom0 - do not know about the nt behaviour */
285 RtlCreateUnicodeStringFromAsciiz( &nameW
, "DeviceName" );
287 RtlMultiByteToUnicodeN( dataW
, 50, &lenW
, data
, strlen(data
));
288 NtSetValueKey( targetKey
, &nameW
, 0, REG_SZ
, (BYTE
*)dataW
, lenW
);
289 RtlFreeUnicodeString( &nameW
);
291 NtClose( targetKey
);
298 /******************************************************************
303 static int CDROM_Open(HANDLE hDevice
, DWORD clientID
)
305 int dev
= LOWORD(clientID
);
307 if (dev
>= 26) return -1;
309 if (!cdrom_cache
[dev
].count
)
314 strcpy(root
, "A:\\");
316 if (GetDriveTypeA(root
) != DRIVE_CDROM
) return -1;
317 if (!(device
= DRIVE_GetDevice(dev
))) return -1;
318 cdrom_cache
[dev
].fd
= open(device
, O_RDONLY
|O_NONBLOCK
);
319 if (cdrom_cache
[dev
].fd
== -1)
321 FIXME("Can't open configured CD-ROM drive at %s (device %s): %s\n", root
, DRIVE_GetDevice(dev
), strerror(errno
));
325 cdrom_cache
[dev
].count
++;
326 return cdrom_cache
[dev
].fd
;
329 /******************************************************************
334 static void CDROM_Close(DWORD clientID
, int fd
)
336 int dev
= LOWORD(clientID
);
338 if (dev
>= 26 || fd
!= cdrom_cache
[dev
].fd
) FIXME("how come\n");
339 if (--cdrom_cache
[dev
].count
== 0)
340 close(cdrom_cache
[dev
].fd
);
343 /******************************************************************
344 * CDROM_GetStatusCode
348 static DWORD
CDROM_GetStatusCode(int io
)
350 if (io
== 0) return 0;
357 return STATUS_NO_MEDIA_IN_DEVICE
;
359 return STATUS_ACCESS_DENIED
;
361 FIXME("Unmapped error code %d: %s\n", errno
, strerror(errno
));
362 return STATUS_IO_DEVICE_ERROR
;
365 static DWORD
CDROM_GetControl(int dev
, CDROM_AUDIO_CONTROL
* cac
)
367 cac
->LbaFormat
= 0; /* FIXME */
368 cac
->LogicalBlocksPerSecond
= 1; /* FIXME */
369 return STATUS_NOT_SUPPORTED
;
372 static DWORD
CDROM_GetDeviceNumber(int dev
, STORAGE_DEVICE_NUMBER
* devnum
)
374 return STATUS_NOT_SUPPORTED
;
377 static DWORD
CDROM_GetDriveGeometry(int dev
, DISK_GEOMETRY
* dg
)
380 dg
->Cylinders
.s
.LowPart
= 1; /* FIXME */
381 dg
->Cylinders
.s
.HighPart
= 0; /* FIXME */
382 dg
->MediaType
= 1; /* FIXME */
383 dg
->TracksPerCylinder
= 1; /* FIXME */
384 dg
->SectorsPerTrack
= 1; /* FIXME */
385 dg
->BytesPerSector
= 1; /* FIXME */
387 return STATUS_NOT_SUPPORTED
;
390 /**************************************************************************
391 * CDROM_Reset [internal]
393 static DWORD
CDROM_ResetAudio(int dev
)
396 return CDROM_GetStatusCode(ioctl(dev
, CDROMRESET
));
397 #elif defined(__FreeBSD__) || defined(__NetBSD__)
398 return CDROM_GetStatusCode(ioctl(dev
, CDIOCRESET
, NULL
));
400 return STATUS_NOT_SUPPORTED
;
404 /******************************************************************
409 static DWORD
CDROM_SetTray(int dev
, BOOL doEject
)
412 return CDROM_GetStatusCode(ioctl(dev
, doEject
? CDROMEJECT
: CDROMCLOSETRAY
));
413 #elif defined(__FreeBSD__) || defined(__NetBSD__)
414 return CDROM_GetStatusCode((ioctl(dev
, CDIOCALLOW
, NULL
)) ||
415 (ioctl(dev
, doEject
? CDIOCEJECT
: CDIOCCLOSE
, NULL
)) ||
416 (ioctl(dev
, CDIOCPREVENT
, NULL
)));
418 return STATUS_NOT_SUPPORTED
;
422 /******************************************************************
423 * CDROM_ControlEjection
427 static DWORD
CDROM_ControlEjection(int dev
, const PREVENT_MEDIA_REMOVAL
* rmv
)
430 return CDROM_GetStatusCode(ioctl(dev
, CDROM_LOCKDOOR
, rmv
->PreventMediaRemoval
));
431 #elif defined(__FreeBSD__) || defined(__NetBSD__)
432 return CDROM_GetStatusCode(ioctl(dev
, (rmv
->PreventMediaRemoval
) ? CDIOCPREVENT
: CDIOCALLOW
, NULL
));
434 return STATUS_NOT_SUPPORTED
;
438 /******************************************************************
443 static DWORD
CDROM_ReadTOC(int dev
, CDROM_TOC
* toc
)
445 DWORD ret
= STATUS_NOT_SUPPORTED
;
449 struct cdrom_tochdr hdr
;
450 struct cdrom_tocentry entry
;
452 io
= ioctl(dev
, CDROMREADTOCHDR
, &hdr
);
455 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
458 toc
->FirstTrack
= hdr
.cdth_trk0
;
459 toc
->LastTrack
= hdr
.cdth_trk1
;
461 TRACE("from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
463 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
465 if (i
== toc
->LastTrack
+ 1)
467 entry
.cdte_track
= CDROM_LEADOUT
;
469 entry
.cdte_track
= i
;
471 entry
.cdte_format
= CDROM_MSF
;
472 io
= ioctl(dev
, CDROMREADTOCENTRY
, &entry
);
474 WARN("error read entry (%s)\n", strerror(errno
));
477 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= entry
.cdte_ctrl
;
478 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= entry
.cdte_adr
;
479 /* marking last track with leadout value as index */
480 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.cdte_track
;
481 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
482 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = entry
.cdte_addr
.msf
.minute
;
483 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = entry
.cdte_addr
.msf
.second
;
484 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = entry
.cdte_addr
.msf
.frame
;
487 ret
= CDROM_GetStatusCode(io
);
488 #elif defined(__FreeBSD__) || defined(__NetBSD__)
490 struct ioc_toc_header hdr
;
491 struct ioc_read_toc_entry entry
;
492 struct cd_toc_entry toc_buffer
;
494 io
= ioctl(dev
, CDIOREADTOCHEADER
, &hdr
);
497 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
500 toc
->FirstTrack
= hdr
.starting_track
;
501 toc
->LastTrack
= hdr
.ending_track
;
503 TRACE("from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
505 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
507 if (i
== toc
->LastTrack
+ 1)
510 entry
.starting_track
= LEADOUT
;
512 entry
.starting_track
= i
;
514 memset((char *)&toc_buffer
, 0, sizeof(toc_buffer
));
515 entry
.address_format
= CD_MSF_FORMAT
;
516 entry
.data_len
= sizeof(toc_buffer
);
517 entry
.data
= &toc_buffer
;
518 io
= ioctl(dev
, CDIOREADTOCENTRYS
, &entry
);
520 WARN("error read entry (%s)\n", strerror(errno
));
523 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= toc_buffer
.control
;
524 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= toc_buffer
.addr_type
;
525 /* marking last track with leadout value as index */
526 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.starting_track
;
527 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
528 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = toc_buffer
.addr
.msf
.minute
;
529 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = toc_buffer
.addr
.msf
.second
;
530 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = toc_buffer
.addr
.msf
.frame
;
533 ret
= CDROM_GetStatusCode(io
);
535 ret
= STATUS_NOT_SUPPORTED
;
540 /******************************************************************
545 static DWORD
CDROM_GetDiskData(int dev
, CDROM_DISK_DATA
* data
)
551 if ((ret
= CDROM_ReadTOC(dev
, &toc
)) != 0) return ret
;
553 for (i
= toc
.FirstTrack
; i
<= toc
.LastTrack
; i
++) {
554 if (toc
.TrackData
[i
].Control
& 0x04)
555 data
->DiskData
|= CDROM_DISK_DATA_TRACK
;
557 data
->DiskData
|= CDROM_DISK_AUDIO_TRACK
;
562 /******************************************************************
567 static DWORD
CDROM_ReadQChannel(int dev
, const CDROM_SUB_Q_DATA_FORMAT
* fmt
,
568 SUB_Q_CHANNEL_DATA
* data
)
570 DWORD ret
= STATUS_NOT_SUPPORTED
;
573 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
575 struct cdrom_subchnl sc
;
576 sc
.cdsc_format
= CDROM_MSF
;
578 io
= ioctl(dev
, CDROMSUBCHNL
, &sc
);
581 TRACE("opened or no_media (%s)!\n", strerror(errno
));
582 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
586 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
588 switch (sc
.cdsc_audiostatus
) {
589 case CDROM_AUDIO_INVALID
:
590 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
592 case CDROM_AUDIO_NO_STATUS
:
593 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
595 case CDROM_AUDIO_PLAY
:
596 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
598 case CDROM_AUDIO_PAUSED
:
599 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
601 case CDROM_AUDIO_COMPLETED
:
602 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
604 case CDROM_AUDIO_ERROR
:
605 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
608 TRACE("status=%02X !\n", sc
.cdsc_audiostatus
);
613 case IOCTL_CDROM_CURRENT_POSITION
:
614 size
= sizeof(SUB_Q_CURRENT_POSITION
);
615 data
->CurrentPosition
.FormatCode
= sc
.cdsc_format
;
616 data
->CurrentPosition
.Control
= sc
.cdsc_ctrl
;
617 data
->CurrentPosition
.ADR
= sc
.cdsc_adr
;
618 data
->CurrentPosition
.TrackNumber
= sc
.cdsc_trk
;
619 data
->CurrentPosition
.IndexNumber
= sc
.cdsc_ind
;
621 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
622 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.cdsc_absaddr
.msf
.minute
;
623 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.cdsc_absaddr
.msf
.second
;
624 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.cdsc_absaddr
.msf
.frame
;
626 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
627 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.cdsc_reladdr
.msf
.minute
;
628 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.cdsc_reladdr
.msf
.second
;
629 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.cdsc_reladdr
.msf
.frame
;
631 case IOCTL_CDROM_MEDIA_CATALOG
:
632 size
= sizeof(SUB_Q_MEDIA_CATALOG_NUMBER
);
633 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
635 struct cdrom_mcn mcn
;
636 if ((io
= ioctl(dev
, CDROM_GET_MCN
, &mcn
)) == -1) goto end
;
638 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
639 data
->MediaCatalog
.Mcval
= 0; /* FIXME */
640 memcpy(data
->MediaCatalog
.MediaCatalog
, mcn
.medium_catalog_number
, 14);
641 data
->MediaCatalog
.MediaCatalog
[14] = 0;
644 case IOCTL_CDROM_TRACK_ISRC
:
645 size
= sizeof(SUB_Q_CURRENT_POSITION
);
646 FIXME("TrackIsrc: NIY on linux\n");
647 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
648 data
->TrackIsrc
.Tcval
= 0;
654 ret
= CDROM_GetStatusCode(io
);
655 #elif defined(__FreeBSD__) || defined(__NetBSD__)
657 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
659 struct ioc_read_subchannel read_sc
;
660 struct cd_sub_channel_info sc
;
662 read_sc
.address_format
= CD_MSF_FORMAT
;
664 read_sc
.data_len
= sizeof(sc
);
668 case IOCTL_CDROM_CURRENT_POSITION
:
669 read_sc
.data_format
= CD_CURRENT_POSITION
;
671 case IOCTL_CDROM_MEDIA_CATALOG
:
672 read_sc
.data_format
= CD_MEDIA_CATALOG
;
674 case IOCTL_CDROM_TRACK_ISRC
:
675 read_sc
.data_format
= CD_TRACK_INFO
;
676 sc
.what
.track_info
.track_number
= data
->TrackIsrc
.Track
;
679 io
= ioctl(dev
, CDIOCREADSUBCHANNEL
, &read_sc
);
682 TRACE("opened or no_media (%s)!\n", strerror(errno
));
683 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
687 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
689 switch (sc
.header
.audio_status
) {
690 case CD_AS_AUDIO_INVALID
:
691 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
693 case CD_AS_NO_STATUS
:
694 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
696 case CD_AS_PLAY_IN_PROGRESS
:
697 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
699 case CD_AS_PLAY_PAUSED
:
700 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
702 case CD_AS_PLAY_COMPLETED
:
703 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
705 case CD_AS_PLAY_ERROR
:
706 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
709 TRACE("status=%02X !\n", sc
.header
.audio_status
);
713 case IOCTL_CDROM_CURRENT_POSITION
:
714 size
= sizeof(SUB_Q_CURRENT_POSITION
);
715 data
->CurrentPosition
.FormatCode
= sc
.what
.position
.data_format
;
716 data
->CurrentPosition
.Control
= sc
.what
.position
.control
;
717 data
->CurrentPosition
.ADR
= sc
.what
.position
.addr_type
;
718 data
->CurrentPosition
.TrackNumber
= sc
.what
.position
.track_number
;
719 data
->CurrentPosition
.IndexNumber
= sc
.what
.position
.index_number
;
721 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
722 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.what
.position
.absaddr
.msf
.minute
;
723 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.what
.position
.absaddr
.msf
.second
;
724 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.what
.position
.absaddr
.msf
.frame
;
725 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
726 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.what
.position
.reladdr
.msf
.minute
;
727 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.what
.position
.reladdr
.msf
.second
;
728 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.what
.position
.reladdr
.msf
.frame
;
730 case IOCTL_CDROM_MEDIA_CATALOG
:
731 size
= sizeof(SUB_Q_MEDIA_CATALOG_NUMBER
);
732 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
733 data
->MediaCatalog
.FormatCode
= sc
.what
.media_catalog
.data_format
;
734 data
->MediaCatalog
.Mcval
= sc
.what
.media_catalog
.mc_valid
;
735 memcpy(data
->MediaCatalog
.MediaCatalog
, sc
.what
.media_catalog
.mc_number
, 15);
737 case IOCTL_CDROM_TRACK_ISRC
:
738 size
= sizeof(SUB_Q_CURRENT_POSITION
);
739 data
->TrackIsrc
.Tcval
= sc
.what
.track_info
.ti_valid
;
740 memcpy(data
->TrackIsrc
.TrackIsrc
, sc
.what
.track_info
.ti_number
, 15);
745 ret
= CDROM_GetStatusCode(io
);
750 /******************************************************************
755 static DWORD
CDROM_Verify(int dev
)
757 /* quick implementation */
758 CDROM_SUB_Q_DATA_FORMAT fmt
;
759 SUB_Q_CHANNEL_DATA data
;
761 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
762 return CDROM_ReadQChannel(dev
, &fmt
, &data
) ? 0 : 1;
765 /******************************************************************
770 static DWORD
CDROM_PlayAudioMSF(int dev
, const CDROM_PLAY_AUDIO_MSF
* audio_msf
)
772 DWORD ret
= STATUS_NOT_SUPPORTED
;
774 struct cdrom_msf msf
;
777 msf
.cdmsf_min0
= audio_msf
->StartingM
;
778 msf
.cdmsf_sec0
= audio_msf
->StartingS
;
779 msf
.cdmsf_frame0
= audio_msf
->StartingF
;
780 msf
.cdmsf_min1
= audio_msf
->EndingM
;
781 msf
.cdmsf_sec1
= audio_msf
->EndingS
;
782 msf
.cdmsf_frame1
= audio_msf
->EndingF
;
784 io
= ioctl(dev
, CDROMSTART
);
787 WARN("motor doesn't start !\n");
790 io
= ioctl(dev
, CDROMPLAYMSF
, &msf
);
793 WARN("device doesn't play !\n");
796 TRACE("msf = %d:%d:%d %d:%d:%d\n",
797 msf
.cdmsf_min0
, msf
.cdmsf_sec0
, msf
.cdmsf_frame0
,
798 msf
.cdmsf_min1
, msf
.cdmsf_sec1
, msf
.cdmsf_frame1
);
800 ret
= CDROM_GetStatusCode(io
);
801 #elif defined(__FreeBSD__) || defined(__NetBSD__)
802 struct ioc_play_msf msf
;
805 msf
.start_m
= audio_msf
->StartingM
;
806 msf
.start_s
= audio_msf
->StartingS
;
807 msf
.start_f
= audio_msf
->StartingF
;
808 msf
.end_m
= audio_msf
->EndingM
;
809 msf
.end_s
= audio_msf
->EndingS
;
810 msf
.end_f
= audio_msf
->EndingF
;
812 io
= ioctl(dev
, CDIOCSTART
, NULL
);
815 WARN("motor doesn't start !\n");
818 io
= ioctl(dev
, CDIOCPLAYMSF
, &msf
);
821 WARN("device doesn't play !\n");
824 TRACE("msf = %d:%d:%d %d:%d:%d\n",
825 msf
.start_m
, msf
.start_s
, msf
.start_f
,
826 msf
.end_m
, msf
.end_s
, msf
.end_f
);
828 ret
= CDROM_GetStatusCode(io
);
833 /******************************************************************
838 static DWORD
CDROM_SeekAudioMSF(int dev
, const CDROM_SEEK_AUDIO_MSF
* audio_msf
)
841 struct cdrom_msf0 msf
;
842 msf
.minute
= audio_msf
->M
;
843 msf
.second
= audio_msf
->S
;
844 msf
.frame
= audio_msf
->F
;
846 return CDROM_GetStatusCode(ioctl(dev
, CDROMSEEK
, &msf
));
847 #elif defined(__FreeBSD__) || defined(__NetBSD__)
848 FIXME("Could a BSD expert implement the seek function ?\n");
849 return STATUS_NOT_SUPPORTED
;
851 return STATUS_NOT_SUPPORTED
;
855 /******************************************************************
860 static DWORD
CDROM_PauseAudio(int dev
)
863 return CDROM_GetStatusCode(ioctl(dev
, CDROMPAUSE
));
864 #elif defined(__FreeBSD__) || defined(__NetBSD__)
865 return CDROM_GetStatusCode(ioctl(dev
, CDIOCPAUSE
, NULL
));
867 return STATUS_NOT_SUPPORTED
;
871 /******************************************************************
876 static DWORD
CDROM_ResumeAudio(int dev
)
879 return CDROM_GetStatusCode(ioctl(dev
, CDROMRESUME
));
880 #elif defined(__FreeBSD__) || defined(__NetBSD__)
881 return CDROM_GetStatusCode(ioctl(dev
, CDIOCRESUME
, NULL
));
883 return STATUS_NOT_SUPPORTED
;
887 /******************************************************************
892 static DWORD
CDROM_StopAudio(int dev
)
895 return CDROM_GetStatusCode(ioctl(dev
, CDROMSTOP
));
896 #elif defined(__FreeBSD__) || defined(__NetBSD__)
897 return CDROM_GetStatusCode(ioctl(dev
, CDIOCSTOP
, NULL
));
899 return STATUS_NOT_SUPPORTED
;
903 /******************************************************************
908 static DWORD
CDROM_GetVolume(int dev
, VOLUME_CONTROL
* vc
)
911 struct cdrom_volctrl volc
;
914 io
= ioctl(dev
, CDROMVOLREAD
, &volc
);
917 vc
->PortVolume
[0] = volc
.channel0
;
918 vc
->PortVolume
[1] = volc
.channel1
;
919 vc
->PortVolume
[2] = volc
.channel2
;
920 vc
->PortVolume
[3] = volc
.channel3
;
922 return CDROM_GetStatusCode(io
);
923 #elif defined(__FreeBSD__) || defined(__NetBSD__)
927 io
= ioctl(dev
, CDIOCGETVOL
, &volc
);
930 vc
->PortVolume
[0] = volc
.vol
[0];
931 vc
->PortVolume
[1] = volc
.vol
[1];
932 vc
->PortVolume
[2] = volc
.vol
[2];
933 vc
->PortVolume
[3] = volc
.vol
[3];
935 return CDROM_GetStatusCode(io
);
937 return STATUS_NOT_SUPPORTED
;
941 /******************************************************************
946 static DWORD
CDROM_SetVolume(int dev
, const VOLUME_CONTROL
* vc
)
949 struct cdrom_volctrl volc
;
951 volc
.channel0
= vc
->PortVolume
[0];
952 volc
.channel1
= vc
->PortVolume
[1];
953 volc
.channel2
= vc
->PortVolume
[2];
954 volc
.channel3
= vc
->PortVolume
[3];
956 return CDROM_GetStatusCode(ioctl(dev
, CDROMVOLCTRL
, &volc
));
957 #elif defined(__FreeBSD__) || defined(__NetBSD__)
960 volc
.vol
[0] = vc
->PortVolume
[0];
961 volc
.vol
[1] = vc
->PortVolume
[1];
962 volc
.vol
[2] = vc
->PortVolume
[2];
963 volc
.vol
[3] = vc
->PortVolume
[3];
965 return CDROM_GetStatusCode(ioctl(dev
, CDIOCSETVOL
, &volc
));
967 return STATUS_NOT_SUPPORTED
;
971 /******************************************************************
976 static DWORD
CDROM_RawRead(int dev
, const RAW_READ_INFO
* raw
, void* buffer
, DWORD len
, DWORD
* sz
)
978 int ret
= STATUS_NOT_SUPPORTED
;
982 switch (raw
->TrackMode
)
984 case YellowMode2
: sectSize
= 2336; break;
985 case XAForm2
: sectSize
= 2328; break;
986 case CDDA
: sectSize
= 2352; break;
987 default: return STATUS_INVALID_PARAMETER
;
989 if (len
< raw
->SectorCount
* sectSize
) return STATUS_BUFFER_TOO_SMALL
;
990 /* strangely enough, it seems that sector offsets are always indicated with a size of 2048,
991 * even if a larger size if read...
995 struct cdrom_read cdr
;
996 struct cdrom_read_audio cdra
;
998 switch (raw
->TrackMode
)
1001 if (raw
->DiskOffset
.s
.HighPart
) FIXME("Unsupported value\n");
1002 cdr
.cdread_lba
= raw
->DiskOffset
.s
.LowPart
; /* FIXME ? */
1003 cdr
.cdread_bufaddr
= buffer
;
1004 cdr
.cdread_buflen
= raw
->SectorCount
* sectSize
;
1005 io
= ioctl(dev
, CDROMREADMODE2
, &cdr
);
1008 FIXME("XAForm2: NIY\n");
1011 /* FIXME: the output doesn't seem 100% correct... in fact output is shifted
1012 * between by NT2K box and this... should check on the same drive...
1013 * otherwise, I fear a 2352/2368 mismatch somewhere in one of the drivers
1015 * Anyway, that's not critical at all. We're talking of 16/32 bytes, we're
1016 * talking of 0.2 ms of sound
1018 /* 2048 = 2 ** 11 */
1019 if (raw
->DiskOffset
.s
.HighPart
& ~2047) FIXME("Unsupported value\n");
1020 cdra
.addr
.lba
= ((raw
->DiskOffset
.s
.LowPart
>> 11) |
1021 (raw
->DiskOffset
.s
.HighPart
<< (32 - 11))) - 1;
1022 FIXME("reading at %u\n", cdra
.addr
.lba
);
1023 cdra
.addr_format
= CDROM_LBA
;
1024 cdra
.nframes
= raw
->SectorCount
;
1026 io
= ioctl(dev
, CDROMREADAUDIO
, &cdra
);
1030 #elif defined(__FreeBSD__)
1032 struct ioc_read_audio ira
;
1034 switch (raw
->TrackMode
)
1037 FIXME("YellowMode2: NIY\n");
1040 FIXME("XAForm2: NIY\n");
1043 /* 2048 = 2 ** 11 */
1044 if (raw
->DiskOffset
.s
.HighPart
& ~2047) FIXME("Unsupported value\n");
1045 ira
.address
.lba
= ((raw
->DiskOffset
.s
.LowPart
>> 11) |
1046 raw
->DiskOffset
.s
.HighPart
<< (32 - 11)) - 1;
1047 ira
.address_format
= CD_LBA_FORMAT
;
1048 ira
.nframes
= raw
->SectorCount
;
1049 ira
.buffer
= buffer
;
1050 io
= ioctl(dev
, CDIOCREADAUDIO
, &ira
);
1054 #elif defined(__NetBSD__)
1056 switch (raw
->TrackMode
)
1059 FIXME("YellowMode2: NIY\n");
1062 FIXME("XAForm2: NIY\n");
1065 FIXME("CDDA: NIY\n");
1070 *sz
= sectSize
* raw
->SectorCount
;
1071 ret
= CDROM_GetStatusCode(io
);
1075 /******************************************************************
1076 * CDROM_ScsiPassThroughDirect
1080 static DWORD
CDROM_ScsiPassThroughDirect(int dev
, PSCSI_PASS_THROUGH_DIRECT pPacket
)
1082 int ret
= STATUS_NOT_SUPPORTED
;
1083 #if defined(linux) && defined(CDROM_SEND_PACKET)
1084 struct linux_cdrom_generic_command cmd
;
1085 struct request_sense sense
;
1088 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH_DIRECT
))
1089 return STATUS_BUFFER_TOO_SMALL
;
1091 if (pPacket
->CdbLength
> 12)
1092 return STATUS_INVALID_PARAMETER
;
1094 if (pPacket
->SenseInfoLength
> sizeof(sense
))
1095 return STATUS_INVALID_PARAMETER
;
1097 memset(&cmd
, 0, sizeof(cmd
));
1098 memset(&sense
, 0, sizeof(sense
));
1100 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1102 cmd
.buffer
= pPacket
->DataBuffer
;
1103 cmd
.buflen
= pPacket
->DataTransferLength
;
1106 cmd
.timeout
= pPacket
->TimeOutValue
*HZ
;
1108 switch (pPacket
->DataIn
)
1110 case SCSI_IOCTL_DATA_OUT
:
1111 cmd
.data_direction
= CGC_DATA_WRITE
;
1113 case SCSI_IOCTL_DATA_IN
:
1114 cmd
.data_direction
= CGC_DATA_READ
;
1116 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1117 cmd
.data_direction
= CGC_DATA_NONE
;
1120 return STATUS_INVALID_PARAMETER
;
1123 io
= ioctl(dev
, CDROM_SEND_PACKET
, &cmd
);
1125 if (pPacket
->SenseInfoLength
!= 0)
1127 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1128 &sense
, pPacket
->SenseInfoLength
);
1131 pPacket
->ScsiStatus
= cmd
.stat
;
1133 ret
= CDROM_GetStatusCode(io
);
1138 /******************************************************************
1139 * CDROM_ScsiPassThrough
1143 static DWORD
CDROM_ScsiPassThrough(int dev
, PSCSI_PASS_THROUGH pPacket
)
1145 int ret
= STATUS_NOT_SUPPORTED
;
1146 #if defined(linux) && defined(CDROM_SEND_PACKET)
1147 struct linux_cdrom_generic_command cmd
;
1148 struct request_sense sense
;
1151 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH
))
1152 return STATUS_BUFFER_TOO_SMALL
;
1154 if (pPacket
->CdbLength
> 12)
1155 return STATUS_INVALID_PARAMETER
;
1157 if (pPacket
->SenseInfoLength
> sizeof(sense
))
1158 return STATUS_INVALID_PARAMETER
;
1160 memset(&cmd
, 0, sizeof(cmd
));
1161 memset(&sense
, 0, sizeof(sense
));
1163 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1165 if ( pPacket
->DataBufferOffset
> 0x1000 )
1167 cmd
.buffer
= (void*)pPacket
->DataBufferOffset
;
1171 cmd
.buffer
= ((void*)pPacket
) + pPacket
->DataBufferOffset
;
1173 cmd
.buflen
= pPacket
->DataTransferLength
;
1176 cmd
.timeout
= pPacket
->TimeOutValue
*HZ
;
1178 switch (pPacket
->DataIn
)
1180 case SCSI_IOCTL_DATA_OUT
:
1181 cmd
.data_direction
= CGC_DATA_WRITE
;
1183 case SCSI_IOCTL_DATA_IN
:
1184 cmd
.data_direction
= CGC_DATA_READ
;
1186 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1187 cmd
.data_direction
= CGC_DATA_NONE
;
1190 return STATUS_INVALID_PARAMETER
;
1193 io
= ioctl(dev
, CDROM_SEND_PACKET
, &cmd
);
1195 if (pPacket
->SenseInfoLength
!= 0)
1197 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1198 &sense
, pPacket
->SenseInfoLength
);
1201 pPacket
->ScsiStatus
= cmd
.stat
;
1203 ret
= CDROM_GetStatusCode(io
);
1208 /******************************************************************
1211 * implements IOCTL_SCSI_GET_ADDRESS
1213 static DWORD
CDROM_GetAddress(int dev
, SCSI_ADDRESS
* address
)
1215 int portnum
, targetid
;
1217 address
->Length
= sizeof(SCSI_ADDRESS
);
1218 address
->PathId
= 0; /* bus number */
1220 if ( ! CDROM_GetIdeInterface(dev
, &portnum
, &targetid
))
1221 return STATUS_NOT_SUPPORTED
;
1223 address
->PortNumber
= portnum
;
1224 address
->TargetId
= targetid
;
1228 /******************************************************************
1229 * CDROM_DeviceIoControl
1233 BOOL
CDROM_DeviceIoControl(DWORD clientID
, HANDLE hDevice
, DWORD dwIoControlCode
,
1234 LPVOID lpInBuffer
, DWORD nInBufferSize
,
1235 LPVOID lpOutBuffer
, DWORD nOutBufferSize
,
1236 LPDWORD lpBytesReturned
, LPOVERLAPPED lpOverlapped
)
1242 TRACE("%lx[%c] %lx %lx %ld %lx %ld %lx %lx\n",
1243 (DWORD
)hDevice
, 'A' + LOWORD(clientID
), dwIoControlCode
, (DWORD
)lpInBuffer
, nInBufferSize
,
1244 (DWORD
)lpOutBuffer
, nOutBufferSize
, (DWORD
)lpBytesReturned
, (DWORD
)lpOverlapped
);
1246 if (lpBytesReturned
) *lpBytesReturned
= 0;
1249 FIXME("Overlapped isn't implemented yet\n");
1250 SetLastError(STATUS_NOT_SUPPORTED
);
1255 dev
= CDROM_Open(hDevice
, clientID
);
1258 CDROM_GetStatusCode(-1);
1262 switch (dwIoControlCode
)
1264 case IOCTL_STORAGE_CHECK_VERIFY
:
1265 case IOCTL_CDROM_CHECK_VERIFY
:
1267 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1268 error
= STATUS_INVALID_PARAMETER
;
1269 else error
= CDROM_Verify(dev
);
1272 /* EPP case IOCTL_STORAGE_CHECK_VERIFY2: */
1274 /* EPP case IOCTL_STORAGE_FIND_NEW_DEVICES: */
1275 /* EPP case IOCTL_CDROM_FIND_NEW_DEVICES: */
1277 case IOCTL_STORAGE_LOAD_MEDIA
:
1278 case IOCTL_CDROM_LOAD_MEDIA
:
1280 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1281 error
= STATUS_INVALID_PARAMETER
;
1282 else error
= CDROM_SetTray(dev
, FALSE
);
1284 case IOCTL_STORAGE_EJECT_MEDIA
:
1286 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1287 error
= STATUS_INVALID_PARAMETER
;
1288 else error
= CDROM_SetTray(dev
, TRUE
);
1291 case IOCTL_CDROM_MEDIA_REMOVAL
:
1292 case IOCTL_DISK_MEDIA_REMOVAL
:
1293 case IOCTL_STORAGE_MEDIA_REMOVAL
:
1294 case IOCTL_STORAGE_EJECTION_CONTROL
:
1295 /* FIXME the last ioctl:s is not the same as the two others...
1296 * lockcount/owner should be handled */
1298 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1299 else if (nInBufferSize
< sizeof(PREVENT_MEDIA_REMOVAL
)) error
= STATUS_BUFFER_TOO_SMALL
;
1300 else error
= CDROM_ControlEjection(dev
, (const PREVENT_MEDIA_REMOVAL
*)lpInBuffer
);
1303 /* EPP case IOCTL_STORAGE_GET_MEDIA_TYPES: */
1305 case IOCTL_STORAGE_GET_DEVICE_NUMBER
:
1306 sz
= sizeof(STORAGE_DEVICE_NUMBER
);
1307 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1308 else if (nOutBufferSize
< sz
) error
= STATUS_BUFFER_TOO_SMALL
;
1309 else error
= CDROM_GetDeviceNumber(dev
, (STORAGE_DEVICE_NUMBER
*)lpOutBuffer
);
1312 case IOCTL_STORAGE_RESET_DEVICE
:
1314 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1315 error
= STATUS_INVALID_PARAMETER
;
1316 else error
= CDROM_ResetAudio(dev
);
1319 case IOCTL_CDROM_GET_CONTROL
:
1320 sz
= sizeof(CDROM_AUDIO_CONTROL
);
1321 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1322 else if (nOutBufferSize
< sz
) error
= STATUS_BUFFER_TOO_SMALL
;
1323 else error
= CDROM_GetControl(dev
, (CDROM_AUDIO_CONTROL
*)lpOutBuffer
);
1326 case IOCTL_CDROM_GET_DRIVE_GEOMETRY
:
1327 sz
= sizeof(DISK_GEOMETRY
);
1328 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1329 else if (nOutBufferSize
< sz
) error
= STATUS_BUFFER_TOO_SMALL
;
1330 else error
= CDROM_GetDriveGeometry(dev
, (DISK_GEOMETRY
*)lpOutBuffer
);
1333 case IOCTL_CDROM_DISK_TYPE
:
1334 sz
= sizeof(CDROM_DISK_DATA
);
1335 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1336 else if (nOutBufferSize
< sz
) error
= STATUS_BUFFER_TOO_SMALL
;
1337 else error
= CDROM_GetDiskData(dev
, (CDROM_DISK_DATA
*)lpOutBuffer
);
1340 /* EPP case IOCTL_CDROM_GET_LAST_SESSION: */
1342 case IOCTL_CDROM_READ_Q_CHANNEL
:
1343 sz
= sizeof(SUB_Q_CHANNEL_DATA
);
1344 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(CDROM_SUB_Q_DATA_FORMAT
))
1345 error
= STATUS_INVALID_PARAMETER
;
1346 else if (nOutBufferSize
< sz
) error
= STATUS_BUFFER_TOO_SMALL
;
1347 else error
= CDROM_ReadQChannel(dev
, (const CDROM_SUB_Q_DATA_FORMAT
*)lpInBuffer
,
1348 (SUB_Q_CHANNEL_DATA
*)lpOutBuffer
);
1351 case IOCTL_CDROM_READ_TOC
:
1352 sz
= sizeof(CDROM_TOC
);
1353 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1354 else if (nOutBufferSize
< sz
) error
= STATUS_BUFFER_TOO_SMALL
;
1355 else error
= CDROM_ReadTOC(dev
, (CDROM_TOC
*)lpOutBuffer
);
1358 /* EPP case IOCTL_CDROM_READ_TOC_EX: */
1360 case IOCTL_CDROM_PAUSE_AUDIO
:
1362 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1363 error
= STATUS_INVALID_PARAMETER
;
1364 else error
= CDROM_PauseAudio(dev
);
1366 case IOCTL_CDROM_PLAY_AUDIO_MSF
:
1368 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1369 else if (nInBufferSize
< sizeof(CDROM_PLAY_AUDIO_MSF
)) error
= STATUS_BUFFER_TOO_SMALL
;
1370 else error
= CDROM_PlayAudioMSF(dev
, (const CDROM_PLAY_AUDIO_MSF
*)lpInBuffer
);
1372 case IOCTL_CDROM_RESUME_AUDIO
:
1374 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1375 error
= STATUS_INVALID_PARAMETER
;
1376 else error
= CDROM_ResumeAudio(dev
);
1378 case IOCTL_CDROM_SEEK_AUDIO_MSF
:
1380 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1381 else if (nInBufferSize
< sizeof(CDROM_SEEK_AUDIO_MSF
)) error
= STATUS_BUFFER_TOO_SMALL
;
1382 else error
= CDROM_SeekAudioMSF(dev
, (const CDROM_SEEK_AUDIO_MSF
*)lpInBuffer
);
1384 case IOCTL_CDROM_STOP_AUDIO
:
1386 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1387 error
= STATUS_INVALID_PARAMETER
;
1388 else error
= CDROM_StopAudio(dev
);
1390 case IOCTL_CDROM_GET_VOLUME
:
1391 sz
= sizeof(VOLUME_CONTROL
);
1392 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1393 else if (nOutBufferSize
< sz
) error
= STATUS_BUFFER_TOO_SMALL
;
1394 else error
= CDROM_GetVolume(dev
, (VOLUME_CONTROL
*)lpOutBuffer
);
1396 case IOCTL_CDROM_SET_VOLUME
:
1398 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(VOLUME_CONTROL
) || lpOutBuffer
!= NULL
)
1399 error
= STATUS_INVALID_PARAMETER
;
1400 else error
= CDROM_SetVolume(dev
, (const VOLUME_CONTROL
*)lpInBuffer
);
1402 case IOCTL_CDROM_RAW_READ
:
1404 if (nInBufferSize
< sizeof(RAW_READ_INFO
)) error
= STATUS_INVALID_PARAMETER
;
1405 else if (lpOutBuffer
== NULL
) error
= STATUS_BUFFER_TOO_SMALL
;
1406 else error
= CDROM_RawRead(dev
, (const RAW_READ_INFO
*)lpInBuffer
,
1407 lpOutBuffer
, nOutBufferSize
, &sz
);
1409 case IOCTL_SCSI_GET_ADDRESS
:
1410 sz
= sizeof(SCSI_ADDRESS
);
1411 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) error
= STATUS_INVALID_PARAMETER
;
1412 else if (nOutBufferSize
< sz
) error
= STATUS_BUFFER_TOO_SMALL
;
1413 else error
= CDROM_GetAddress(dev
, (SCSI_ADDRESS
*)lpOutBuffer
);
1415 case IOCTL_SCSI_PASS_THROUGH_DIRECT
:
1416 sz
= sizeof(SCSI_PASS_THROUGH_DIRECT
);
1417 if (lpOutBuffer
== NULL
) error
= STATUS_INVALID_PARAMETER
;
1418 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH_DIRECT
)) error
= STATUS_BUFFER_TOO_SMALL
;
1419 else error
= CDROM_ScsiPassThroughDirect(dev
, (PSCSI_PASS_THROUGH_DIRECT
)lpOutBuffer
);
1421 case IOCTL_SCSI_PASS_THROUGH
:
1422 sz
= sizeof(SCSI_PASS_THROUGH
);
1423 if (lpOutBuffer
== NULL
) error
= STATUS_INVALID_PARAMETER
;
1424 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH
)) error
= STATUS_BUFFER_TOO_SMALL
;
1425 else error
= CDROM_ScsiPassThrough(dev
, (PSCSI_PASS_THROUGH
)lpOutBuffer
);
1429 FIXME("Unsupported IOCTL %lx\n", dwIoControlCode
);
1431 error
= STATUS_INVALID_PARAMETER
;
1435 if (lpBytesReturned
) *lpBytesReturned
= sz
;
1438 SetLastError(error
);
1441 CDROM_Close(clientID
, dev
);