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
29 #include <sys/ioctl.h>
36 #include "wine/debug.h"
38 #ifdef HAVE_LINUX_CDROM_H
39 # include <linux/cdrom.h>
41 #ifdef HAVE_LINUX_UCDROM_H
42 # include <linux/ucdrom.h>
44 #ifdef HAVE_SYS_CDIO_H
45 # include <sys/cdio.h>
48 WINE_DEFAULT_DEBUG_CHANNEL(cdrom);
50 /* FIXME: this is needed because we can't open simultaneously several times /dev/cdrom
51 * this should be removed when a proper device interface is implemented
57 static struct cdrom_cache cdrom_cache[26];
59 /******************************************************************
64 static int CDROM_Open(HANDLE hDevice, DWORD clientID)
66 int dev = LOWORD(clientID);
68 if (dev >= 26) return -1;
70 if (!cdrom_cache[dev].count)
76 if (GetDriveTypeA(root) != DRIVE_CDROM) return -1;
77 cdrom_cache[dev].fd = open(DRIVE_GetDevice(dev), O_RDONLY|O_NONBLOCK);
78 if (cdrom_cache[dev].fd == -1)
80 FIXME("Can't open %s: %s\n", root, strerror(errno));
84 cdrom_cache[dev].count++;
85 return cdrom_cache[dev].fd;
88 /******************************************************************
93 static void CDROM_Close(DWORD clientID, int fd)
95 int dev = LOWORD(clientID);
97 if (dev >= 26 || fd != cdrom_cache[dev].fd) FIXME("how come\n");
98 if (--cdrom_cache[dev].count == 0)
99 close(cdrom_cache[dev].fd);
102 /******************************************************************
103 * CDROM_GetStatusCode
107 static DWORD CDROM_GetStatusCode(int io)
109 if (io == 0) return 0;
112 case EIO: return STATUS_NO_MEDIA_IN_DEVICE;
114 FIXME("Unmapped error code %d: %s\n", errno, strerror(errno));
115 return STATUS_IO_DEVICE_ERROR;
118 static DWORD CDROM_GetControl(int dev, CDROM_AUDIO_CONTROL* cac)
120 cac->LbaFormat = 0; /* FIXME */
121 cac->LogicalBlocksPerSecond = 1; /* FIXME */
122 return STATUS_NOT_SUPPORTED;
125 static DWORD CDROM_GetDeviceNumber(int dev, STORAGE_DEVICE_NUMBER* devnum)
127 return STATUS_NOT_SUPPORTED;
130 static DWORD CDROM_GetDriveGeometry(int dev, DISK_GEOMETRY* dg)
133 dg->Cylinders.s.LowPart = 1; /* FIXME */
134 dg->Cylinders.s.HighPart = 0; /* FIXME */
135 dg->MediaType = 1; /* FIXME */
136 dg->TracksPerCylinder = 1; /* FIXME */
137 dg->SectorsPerTrack = 1; /* FIXME */
138 dg->BytesPerSector= 1; /* FIXME */
140 return STATUS_NOT_SUPPORTED;
143 /**************************************************************************
144 * CDROM_Reset [internal]
146 static DWORD CDROM_ResetAudio(int dev)
149 return CDROM_GetStatusCode(ioctl(dev, CDROMRESET));
150 #elif defined(__FreeBSD__) || defined(__NetBSD__)
151 return CDROM_GetStatusCode(ioctl(dev, CDIOCRESET, NULL));
153 return STATUS_NOT_SUPPORTED;
157 /******************************************************************
162 static DWORD CDROM_SetTray(int dev, BOOL doEject)
165 return CDROM_GetStatusCode(ioctl(dev, doEject ? CDROMEJECT : CDROMCLOSETRAY));
166 #elif defined(__FreeBSD__) || defined(__NetBSD__)
167 return CDROM_GetStatusCode((ioctl(dev, CDIOCALLOW, NULL)) ||
168 (ioctl(dev, doEject ? CDIOCEJECT : CDIOCCLOSE, NULL)) ||
169 (ioctl(dev, CDIOCPREVENT, NULL)));
171 return STATUS_NOT_SUPPORTED;
175 /******************************************************************
176 * CDROM_ControlEjection
180 static DWORD CDROM_ControlEjection(int dev, const PREVENT_MEDIA_REMOVAL* rmv)
182 int val = rmv->PreventMediaRemoval;
184 return CDROM_GetStatusCode(ioctl(dev, CDROM_LOCKDOOR, val));
185 #elif defined(__FreeBSD__) || defined(__NetBSD__)
186 return CDROM_GetStatusCode(ioctl(dev, (val) ? CDIOCPREVENT : CDIOCALLOW, NULL));
188 return STATUS_NOT_SUPPORTED;
192 /******************************************************************
197 static DWORD CDROM_ReadTOC(int dev, CDROM_TOC* toc)
199 DWORD ret = STATUS_NOT_SUPPORTED;
203 struct cdrom_tochdr hdr;
204 struct cdrom_tocentry entry;
206 io = ioctl(dev, CDROMREADTOCHDR, &hdr);
209 WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
212 toc->FirstTrack = hdr.cdth_trk0;
213 toc->LastTrack = hdr.cdth_trk1;
215 TRACE("from=%d to=%d\n", toc->FirstTrack, toc->LastTrack);
217 for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
219 if (i == toc->LastTrack + 1)
221 entry.cdte_track = CDROM_LEADOUT;
223 entry.cdte_track = i;
225 entry.cdte_format = CDROM_MSF;
226 io = ioctl(dev, CDROMREADTOCENTRY, &entry);
228 WARN("error read entry (%s)\n", strerror(errno));
231 toc->TrackData[i - toc->FirstTrack].Control = entry.cdte_ctrl;
232 toc->TrackData[i - toc->FirstTrack].Adr = entry.cdte_adr;
233 /* marking last track with leadout value as index */
234 toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.cdte_track;
235 toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
236 toc->TrackData[i - toc->FirstTrack].Address[1] = entry.cdte_addr.msf.minute;
237 toc->TrackData[i - toc->FirstTrack].Address[2] = entry.cdte_addr.msf.second;
238 toc->TrackData[i - toc->FirstTrack].Address[3] = entry.cdte_addr.msf.frame;
241 ret = CDROM_GetStatusCode(io);
242 #elif defined(__FreeBSD__) || defined(__NetBSD__)
244 struct ioc_toc_header hdr;
245 struct ioc_read_toc_entry entry;
246 struct cd_toc_entry toc_buffer;
248 io = ioctl(dev, CDIOREADTOCHEADER, &hdr);
251 WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
254 toc->FirstTrack = hdr.starting_track;
255 toc->LastTrack = hdr.ending_track;
257 TRACE("from=%d to=%d\n", toc->FirstTrack, toc->LastTrack);
259 for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
261 if (i == toc->LastTrack + 1)
264 entry.starting_track = LEADOUT;
266 entry.starting_track = i;
268 memset((char *)&toc_buffer, 0, sizeof(toc_buffer));
269 entry.address_format = CD_MSF_FORMAT;
270 entry.data_len = sizeof(toc_buffer);
271 entry.data = &toc_buffer;
272 io = ioctl(dev, CDIOREADTOCENTRYS, &entry);
274 WARN("error read entry (%s)\n", strerror(errno));
277 toc->TrackData[i - toc->FirstTrack].Control = toc_buffer.control;
278 toc->TrackData[i - toc->FirstTrack].Adr = toc_buffer.addr_type;
279 /* marking last track with leadout value as index */
280 toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.starting_track;
281 toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
282 toc->TrackData[i - toc->FirstTrack].Address[1] = toc_buffer.addr.msf.minute;
283 toc->TrackData[i - toc->FirstTrack].Address[2] = toc_buffer.addr.msf.second;
284 toc->TrackData[i - toc->FirstTrack].Address[3] = toc_buffer.addr.msf.frame;
287 ret = CDROM_GetStatusCode(io);
289 ret = STATUS_NOT_SUPPORTED;
294 /******************************************************************
299 static DWORD CDROM_GetDiskData(int dev, CDROM_DISK_DATA* data)
305 if ((ret = CDROM_ReadTOC(dev, &toc)) != 0) return ret;
307 for (i = toc.FirstTrack; i <= toc.LastTrack; i++) {
308 if (toc.TrackData[i].Control & 0x04)
309 data->DiskData |= CDROM_DISK_DATA_TRACK;
311 data->DiskData |= CDROM_DISK_AUDIO_TRACK;
316 /******************************************************************
321 static DWORD CDROM_ReadQChannel(int dev, const CDROM_SUB_Q_DATA_FORMAT* fmt,
322 SUB_Q_CHANNEL_DATA* data)
324 DWORD ret = STATUS_NOT_SUPPORTED;
326 SUB_Q_HEADER* hdr = (SUB_Q_HEADER*)data;
330 struct cdrom_subchnl sc;
331 sc.cdsc_format = CDROM_MSF;
333 io = ioctl(dev, CDROMSUBCHNL, &sc);
336 TRACE("opened or no_media (%s)!\n", strerror(errno));
337 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
341 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
343 switch (sc.cdsc_audiostatus) {
344 case CDROM_AUDIO_INVALID:
345 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
347 case CDROM_AUDIO_NO_STATUS:
348 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
350 case CDROM_AUDIO_PLAY:
351 hdr->AudioStatus = AUDIO_STATUS_IN_PROGRESS;
353 case CDROM_AUDIO_PAUSED:
354 hdr->AudioStatus = AUDIO_STATUS_PAUSED;
356 case CDROM_AUDIO_COMPLETED:
357 hdr->AudioStatus = AUDIO_STATUS_PLAY_COMPLETE;
359 case CDROM_AUDIO_ERROR:
360 hdr->AudioStatus = AUDIO_STATUS_PLAY_ERROR;
363 TRACE("status=%02X !\n", sc.cdsc_audiostatus);
368 case IOCTL_CDROM_CURRENT_POSITION:
369 size = sizeof(SUB_Q_CURRENT_POSITION);
370 data->CurrentPosition.FormatCode = sc.cdsc_format;
371 data->CurrentPosition.Control = sc.cdsc_ctrl;
372 data->CurrentPosition.ADR = sc.cdsc_adr;
373 data->CurrentPosition.TrackNumber = sc.cdsc_trk;
374 data->CurrentPosition.IndexNumber = sc.cdsc_ind;
376 data->CurrentPosition.AbsoluteAddress[0] = 0;
377 data->CurrentPosition.AbsoluteAddress[1] = sc.cdsc_absaddr.msf.minute;
378 data->CurrentPosition.AbsoluteAddress[2] = sc.cdsc_absaddr.msf.second;
379 data->CurrentPosition.AbsoluteAddress[3] = sc.cdsc_absaddr.msf.frame;
381 data->CurrentPosition.TrackRelativeAddress[0] = 0;
382 data->CurrentPosition.TrackRelativeAddress[1] = sc.cdsc_reladdr.msf.minute;
383 data->CurrentPosition.TrackRelativeAddress[2] = sc.cdsc_reladdr.msf.second;
384 data->CurrentPosition.TrackRelativeAddress[3] = sc.cdsc_reladdr.msf.frame;
386 case IOCTL_CDROM_MEDIA_CATALOG:
387 size = sizeof(SUB_Q_MEDIA_CATALOG_NUMBER);
388 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
390 struct cdrom_mcn mcn;
391 if ((io = ioctl(dev, CDROM_GET_MCN, &mcn)) == -1) goto end;
393 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
394 data->MediaCatalog.Mcval = 0; /* FIXME */
395 memcpy(data->MediaCatalog.MediaCatalog, mcn.medium_catalog_number, 14);
396 data->MediaCatalog.MediaCatalog[14] = 0;
399 case IOCTL_CDROM_TRACK_ISRC:
400 size = sizeof(SUB_Q_CURRENT_POSITION);
401 FIXME("TrackIsrc: NIY on linux");
402 data->TrackIsrc.FormatCode = IOCTL_CDROM_TRACK_ISRC;
403 data->TrackIsrc.Tcval = 0;
409 ret = CDROM_GetStatusCode(io);
410 #elif defined(__FreeBSD__) || defined(__NetBSD__)
411 struct ioc_read_subchannel read_sc;
412 struct cd_sub_channel_info sc;
414 read_sc.address_format = CD_MSF_FORMAT;
416 read_sc.data_len = sizeof(sc);
420 case IOCTL_CDROM_CURRENT_POSITION:
421 read_sc.data_format = CD_CURRENT_POSITION;
423 case IOCTL_CDROM_MEDIA_CATALOG:
424 read_sc.data_format = CD_MEDIA_CATALOG;
426 case IOCTL_CDROM_TRACK_ISRC:
427 read_sc.data_format = CD_TRACK_INFO;
428 sc.what.track_info.track_number = data->TrackIsrc.Track;
431 io = ioctl(dev, CDIOCREADSUBCHANNEL, &read_sc);
434 TRACE("opened or no_media (%s)!\n", strerror(errno));
435 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
439 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
441 switch (sc.header.audio_status) {
442 case CD_AS_AUDIO_INVALID:
443 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
445 case CD_AS_NO_STATUS:
446 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
448 case CD_AS_PLAY_IN_PROGRESS:
449 hdr->AudioStatus = AUDIO_STATUS_IN_PROGRESS;
451 case CD_AS_PLAY_PAUSED:
452 hdr->AudioStatus = AUDIO_STATUS_PAUSED;
454 case CD_AS_PLAY_COMPLETED:
455 hdr->AudioStatus = AUDIO_STATUS_PLAY_COMPLETE;
457 case CD_AS_PLAY_ERROR:
458 hdr->AudioStatus = AUDIO_STATUS_PLAY_ERROR;
461 TRACE("status=%02X !\n", sc.header.audio_status);
465 case IOCTL_CDROM_CURRENT_POSITION:
466 size = sizeof(SUB_Q_CURRENT_POSITION);
467 data->CurrentPosition.FormatCode = sc.what.position.data_format;
468 data->CurrentPosition.Control = sc.what.position.control;
469 data->CurrentPosition.ADR = sc.what.position.addr_type;
470 data->CurrentPosition.TrackNumber = sc.what.position.track_number;
471 data->CurrentPosition.IndexNumber = sc.what.position.index_number;
473 data->CurrentPosition.AbsoluteAddress[0] = 0;
474 data->CurrentPosition.AbsoluteAddress[1] = sc.what.position.absaddr.msf.minute;
475 data->CurrentPosition.AbsoluteAddress[2] = sc.what.position.absaddr.msf.second;
476 data->CurrentPosition.AbsoluteAddress[3] = sc.what.position.absaddr.msf.frame;
477 data->CurrentPosition.TrackRelativeAddress[0] = 0;
478 data->CurrentPosition.TrackRelativeAddress[1] = sc.what.position.reladdr.msf.minute;
479 data->CurrentPosition.TrackRelativeAddress[2] = sc.what.position.reladdr.msf.second;
480 data->CurrentPosition.TrackRelativeAddress[3] = sc.what.position.reladdr.msf.frame;
482 case IOCTL_CDROM_MEDIA_CATALOG:
483 size = sizeof(SUB_Q_MEDIA_CATALOG_NUMBER);
484 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
485 data->MediaCatalog.FormatCode = sc.what.media_catalog.data_format;
486 data->MediaCatalog.Mcval = sc.what.media_catalog.mc_valid;
487 memcpy(data->MediaCatalog.MediaCatalog, sc.what.media_catalog.mc_number, 15);
489 case IOCTL_CDROM_TRACK_ISRC:
490 size = sizeof(SUB_Q_CURRENT_POSITION);
491 data->TrackIsrc.Tcval = sc.what.track_info.ti_valid;
492 memcpy(data->TrackIsrc.TrackIsrc, sc.what.track_info.ti_number, 15);
497 ret = CDROM_GetStatusCode(io);
502 /******************************************************************
507 static DWORD CDROM_Verify(int dev)
509 /* quick implementation */
510 CDROM_SUB_Q_DATA_FORMAT fmt;
511 SUB_Q_CHANNEL_DATA data;
513 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
514 return CDROM_ReadQChannel(dev, &fmt, &data) ? 0 : 1;
517 /******************************************************************
522 static DWORD CDROM_PlayAudioMSF(int dev, const CDROM_PLAY_AUDIO_MSF* audio_msf)
524 DWORD ret = STATUS_NOT_SUPPORTED;
526 struct cdrom_msf msf;
529 msf.cdmsf_min0 = audio_msf->StartingM;
530 msf.cdmsf_sec0 = audio_msf->StartingS;
531 msf.cdmsf_frame0 = audio_msf->StartingF;
532 msf.cdmsf_min1 = audio_msf->EndingM;
533 msf.cdmsf_sec1 = audio_msf->EndingS;
534 msf.cdmsf_frame1 = audio_msf->EndingF;
536 io = ioctl(dev, CDROMSTART);
539 WARN("motor doesn't start !\n");
542 io = ioctl(dev, CDROMPLAYMSF, &msf);
545 WARN("device doesn't play !\n");
548 TRACE("msf = %d:%d:%d %d:%d:%d\n",
549 msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0,
550 msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1);
552 ret = CDROM_GetStatusCode(io);
553 #elif defined(__FreeBSD__) || defined(__NetBSD__)
554 struct ioc_play_msf msf;
557 msf.start_m = audio_msf->StartingM;
558 msf.start_s = audio_msf->StartingS;
559 msf.start_f = audio_msf->StartingF;
560 msf.end_m = audio_msf->EndingM;
561 msf.end_s = audio_msf->EndingS;
562 msf.end_f = audio_msf->EndingF;
564 io = ioctl(dev, CDIOCSTART, NULL);
567 WARN("motor doesn't start !\n");
570 io = ioctl(dev, CDIOCPLAYMSF, &msf);
573 WARN("device doesn't play !\n");
576 TRACE("msf = %d:%d:%d %d:%d:%d\n",
577 msf.start_m, msf.start_s, msf.start_f,
578 msf.end_m, msf.end_s, msf.end_f);
580 ret = CDROM_GetStatusCode(io);
585 /******************************************************************
590 static DWORD CDROM_SeekAudioMSF(int dev, const CDROM_SEEK_AUDIO_MSF* audio_msf)
593 struct cdrom_msf0 msf;
594 msf.minute = audio_msf->M;
595 msf.second = audio_msf->S;
596 msf.frame = audio_msf->F;
598 return CDROM_GetStatusCode(ioctl(dev, CDROMSEEK, &msf));
599 #elif defined(__FreeBSD__) || defined(__NetBSD__)
600 FIXME("Could a BSD expert implement the seek function ?\n");
601 return STATUS_NOT_SUPPORTED;
603 return STATUS_NOT_SUPPORTED;
607 /******************************************************************
612 static DWORD CDROM_PauseAudio(int dev)
615 return CDROM_GetStatusCode(ioctl(dev, CDROMPAUSE));
616 #elif defined(__FreeBSD__) || defined(__NetBSD__)
617 return CDROM_GetStatusCode(ioctl(dev, CDIOCPAUSE, NULL));
619 return STATUS_NOT_SUPPORTED;
623 /******************************************************************
628 static DWORD CDROM_ResumeAudio(int dev)
631 return CDROM_GetStatusCode(ioctl(dev, CDROMRESUME));
632 #elif defined(__FreeBSD__) || defined(__NetBSD__)
633 return CDROM_GetStatusCode(ioctl(dev, CDIOCRESUME, NULL));
635 return STATUS_NOT_SUPPORTED;
639 /******************************************************************
644 static DWORD CDROM_StopAudio(int dev)
647 return CDROM_GetStatusCode(ioctl(dev, CDROMSTOP));
648 #elif defined(__FreeBSD__) || defined(__NetBSD__)
649 return CDROM_GetStatusCode(ioctl(dev, CDIOCSTOP, NULL));
651 return STATUS_NOT_SUPPORTED;
655 /******************************************************************
660 static DWORD CDROM_GetVolume(int dev, VOLUME_CONTROL* vc)
663 struct cdrom_volctrl volc;
666 io = ioctl(dev, CDROMVOLREAD, &volc);
669 vc->PortVolume[0] = volc.channel0;
670 vc->PortVolume[1] = volc.channel1;
671 vc->PortVolume[2] = volc.channel2;
672 vc->PortVolume[3] = volc.channel3;
674 return CDROM_GetStatusCode(io);
675 #elif defined(__FreeBSD__) || defined(__NetBSD__)
679 io = ioctl(dev, CDIOCGETVOL, &volc);
682 vc->PortVolume[0] = volc.vol[0];
683 vc->PortVolume[1] = volc.vol[1];
684 vc->PortVolume[2] = volc.vol[2];
685 vc->PortVolume[3] = volc.vol[3];
687 return CDROM_GetStatusCode(io);
689 return STATUS_NOT_SUPPORTED;
693 /******************************************************************
698 static DWORD CDROM_SetVolume(int dev, const VOLUME_CONTROL* vc)
701 struct cdrom_volctrl volc;
703 volc.channel0 = vc->PortVolume[0];
704 volc.channel1 = vc->PortVolume[1];
705 volc.channel2 = vc->PortVolume[2];
706 volc.channel3 = vc->PortVolume[3];
708 return CDROM_GetStatusCode(ioctl(dev, CDROMVOLCTRL, &volc));
709 #elif defined(__FreeBSD__) || defined(__NetBSD__)
712 volc.vol[0] = vc->PortVolume[0];
713 volc.vol[1] = vc->PortVolume[1];
714 volc.vol[2] = vc->PortVolume[2];
715 volc.vol[3] = vc->PortVolume[3];
717 return CDROM_GetStatusCode(ioctl(dev, CDIOCSETVOL, &volc));
719 return STATUS_NOT_SUPPORTED;
723 /******************************************************************
728 static DWORD CDROM_RawRead(int dev, const RAW_READ_INFO* raw, void* buffer, DWORD len, DWORD* sz)
730 int ret = STATUS_NOT_SUPPORTED;
734 switch (raw->TrackMode)
736 case YellowMode2: sectSize = 2336; break;
737 case XAForm2: sectSize = 2328; break;
738 case CDDA: sectSize = 2352; break;
739 default: return STATUS_INVALID_PARAMETER;
741 if (len < raw->SectorCount * sectSize) return STATUS_BUFFER_TOO_SMALL;
742 /* strangely enough, it seems that sector offsets are always indicated with a size of 2048,
743 * even if a larger size if read...
747 struct cdrom_read cdr;
748 struct cdrom_read_audio cdra;
750 switch (raw->TrackMode)
753 if (raw->DiskOffset.s.HighPart) FIXME("Unsupported value\n");
754 cdr.cdread_lba = raw->DiskOffset.s.LowPart; /* FIXME ? */
755 cdr.cdread_bufaddr = buffer;
756 cdr.cdread_buflen = raw->SectorCount * sectSize;
757 io = ioctl(dev, CDROMREADMODE2, &cdr);
760 FIXME("XAForm2: NIY\n");
763 /* FIXME: the output doesn't seem 100% correct... in fact output is shifted
764 * between by NT2K box and this... should check on the same drive...
765 * otherwise, I fear a 2352/2368 mismatch somewhere in one of the drivers
767 * Anyway, that's not critical at all. We're talking of 16/32 bytes, we're
768 * talking of 0.2 ms of sound
771 if (raw->DiskOffset.s.HighPart & ~2047) FIXME("Unsupported value\n");
772 cdra.addr.lba = ((raw->DiskOffset.s.LowPart >> 11) |
773 (raw->DiskOffset.s.HighPart << (32 - 11))) - 1;
774 FIXME("reading at %u\n", cdra.addr.lba);
775 cdra.addr_format = CDROM_LBA;
776 cdra.nframes = raw->SectorCount;
778 io = ioctl(dev, CDROMREADAUDIO, &cdra);
782 #elif defined(__FreeBSD__)
784 struct ioc_read_audio ira;
786 switch (raw->TrackMode)
789 FIXME("YellowMode2: NIY\n");
792 FIXME("XAForm2: NIY\n");
796 if (raw->DiskOffset.s.HighPart & ~2047) FIXME("Unsupported value\n");
797 ira.address.lba = ((raw->DiskOffset.s.LowPart >> 11) |
798 raw->DiskOffset.s.HighPart << (32 - 11)) - 1;
799 ira.address_format = CD_LBA_FORMAT;
800 ira.nframes = raw->SectorCount;
802 io = ioctl(dev, CDIOCREADAUDIO, &ira);
806 #elif defined(__NetBSD__)
808 switch (raw->TrackMode)
811 FIXME("YellowMode2: NIY\n");
814 FIXME("XAForm2: NIY\n");
817 FIXME("CDDA: NIY\n");
822 *sz = sectSize * raw->SectorCount;
823 ret = CDROM_GetStatusCode(io);
827 /******************************************************************
828 * CDROM_DeviceIoControl
832 BOOL CDROM_DeviceIoControl(DWORD clientID, HANDLE hDevice, DWORD dwIoControlCode,
833 LPVOID lpInBuffer, DWORD nInBufferSize,
834 LPVOID lpOutBuffer, DWORD nOutBufferSize,
835 LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
841 TRACE("%lx[%c] %lx %lx %ld %lx %ld %lx %lx\n",
842 (DWORD)hDevice, 'A' + LOWORD(clientID), dwIoControlCode, (DWORD)lpInBuffer, nInBufferSize,
843 (DWORD)lpOutBuffer, nOutBufferSize, (DWORD)lpBytesReturned, (DWORD)lpOverlapped);
845 if (lpBytesReturned) *lpBytesReturned = 0;
848 FIXME("Overlapped isn't implemented yet\n");
849 SetLastError(STATUS_NOT_SUPPORTED);
854 dev = CDROM_Open(hDevice, clientID);
857 CDROM_GetStatusCode(-1);
861 switch (dwIoControlCode)
863 case IOCTL_STORAGE_CHECK_VERIFY:
864 case IOCTL_CDROM_CHECK_VERIFY:
866 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
867 error = STATUS_INVALID_PARAMETER;
868 else error = CDROM_Verify(dev);
871 /* EPP case IOCTL_STORAGE_CHECK_VERIFY2: */
873 /* EPP case IOCTL_STORAGE_FIND_NEW_DEVICES: */
874 /* EPP case IOCTL_CDROM_FIND_NEW_DEVICES: */
876 case IOCTL_STORAGE_LOAD_MEDIA:
877 case IOCTL_CDROM_LOAD_MEDIA:
879 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
880 error = STATUS_INVALID_PARAMETER;
881 else error = CDROM_SetTray(dev, FALSE);
883 case IOCTL_STORAGE_EJECT_MEDIA:
885 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
886 error = STATUS_INVALID_PARAMETER;
887 else error = CDROM_SetTray(dev, TRUE);
890 case IOCTL_DISK_MEDIA_REMOVAL:
891 case IOCTL_STORAGE_MEDIA_REMOVAL:
892 case IOCTL_STORAGE_EJECTION_CONTROL:
893 /* FIXME the last ioctl:s is not the same as the two others...
894 * lockcount/owner should be handled */
896 if (lpOutBuffer != NULL || nOutBufferSize != 0) error = STATUS_INVALID_PARAMETER;
897 else if (nInBufferSize < sizeof(PREVENT_MEDIA_REMOVAL)) error = STATUS_BUFFER_TOO_SMALL;
898 else error = CDROM_ControlEjection(dev, (const PREVENT_MEDIA_REMOVAL*)lpInBuffer);
901 /* EPP case IOCTL_STORAGE_GET_MEDIA_TYPES: */
903 case IOCTL_STORAGE_GET_DEVICE_NUMBER:
904 sz = sizeof(STORAGE_DEVICE_NUMBER);
905 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
906 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
907 else error = CDROM_GetDeviceNumber(dev, (STORAGE_DEVICE_NUMBER*)lpOutBuffer);
910 case IOCTL_STORAGE_RESET_DEVICE:
912 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
913 error = STATUS_INVALID_PARAMETER;
914 else error = CDROM_ResetAudio(dev);
917 case IOCTL_CDROM_GET_CONTROL:
918 sz = sizeof(CDROM_AUDIO_CONTROL);
919 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
920 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
921 else error = CDROM_GetControl(dev, (CDROM_AUDIO_CONTROL*)lpOutBuffer);
924 case IOCTL_CDROM_GET_DRIVE_GEOMETRY:
925 sz = sizeof(DISK_GEOMETRY);
926 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
927 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
928 else error = CDROM_GetDriveGeometry(dev, (DISK_GEOMETRY*)lpOutBuffer);
931 case IOCTL_CDROM_DISK_TYPE:
932 sz = sizeof(CDROM_DISK_DATA);
933 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
934 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
935 else error = CDROM_GetDiskData(dev, (CDROM_DISK_DATA*)lpOutBuffer);
938 /* EPP case IOCTL_CDROM_GET_LAST_SESSION: */
940 case IOCTL_CDROM_READ_Q_CHANNEL:
941 sz = sizeof(SUB_Q_CHANNEL_DATA);
942 if (lpInBuffer == NULL || nInBufferSize < sizeof(CDROM_SUB_Q_DATA_FORMAT))
943 error = STATUS_INVALID_PARAMETER;
944 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
945 else error = CDROM_ReadQChannel(dev, (const CDROM_SUB_Q_DATA_FORMAT*)lpInBuffer,
946 (SUB_Q_CHANNEL_DATA*)lpOutBuffer);
949 case IOCTL_CDROM_READ_TOC:
950 sz = sizeof(CDROM_TOC);
951 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
952 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
953 else error = CDROM_ReadTOC(dev, (CDROM_TOC*)lpOutBuffer);
956 /* EPP case IOCTL_CDROM_READ_TOC_EX: */
958 case IOCTL_CDROM_PAUSE_AUDIO:
960 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
961 error = STATUS_INVALID_PARAMETER;
962 else error = CDROM_PauseAudio(dev);
964 case IOCTL_CDROM_PLAY_AUDIO_MSF:
966 if (lpOutBuffer != NULL || nOutBufferSize != 0) error = STATUS_INVALID_PARAMETER;
967 else if (nInBufferSize < sizeof(CDROM_PLAY_AUDIO_MSF)) error = STATUS_BUFFER_TOO_SMALL;
968 else error = CDROM_PlayAudioMSF(dev, (const CDROM_PLAY_AUDIO_MSF*)lpInBuffer);
970 case IOCTL_CDROM_RESUME_AUDIO:
972 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
973 error = STATUS_INVALID_PARAMETER;
974 else error = CDROM_ResumeAudio(dev);
976 case IOCTL_CDROM_SEEK_AUDIO_MSF:
978 if (lpOutBuffer != NULL || nOutBufferSize != 0) error = STATUS_INVALID_PARAMETER;
979 else if (nInBufferSize < sizeof(CDROM_SEEK_AUDIO_MSF)) error = STATUS_BUFFER_TOO_SMALL;
980 else error = CDROM_SeekAudioMSF(dev, (const CDROM_SEEK_AUDIO_MSF*)lpInBuffer);
982 case IOCTL_CDROM_STOP_AUDIO:
984 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
985 error = STATUS_INVALID_PARAMETER;
986 else error = CDROM_StopAudio(dev);
988 case IOCTL_CDROM_GET_VOLUME:
989 sz = sizeof(VOLUME_CONTROL);
990 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
991 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
992 else error = CDROM_GetVolume(dev, (VOLUME_CONTROL*)lpOutBuffer);
994 case IOCTL_CDROM_SET_VOLUME:
996 if (lpInBuffer == NULL || nInBufferSize < sizeof(VOLUME_CONTROL) || lpOutBuffer != NULL)
997 error = STATUS_INVALID_PARAMETER;
998 else error = CDROM_SetVolume(dev, (const VOLUME_CONTROL*)lpInBuffer);
1000 case IOCTL_CDROM_RAW_READ:
1002 if (nInBufferSize < sizeof(RAW_READ_INFO)) error = STATUS_INVALID_PARAMETER;
1003 else if (lpOutBuffer == NULL) error = STATUS_BUFFER_TOO_SMALL;
1004 else error = CDROM_RawRead(dev, (const RAW_READ_INFO*)lpInBuffer,
1005 lpOutBuffer, nOutBufferSize, &sz);
1008 FIXME("Unsupported IOCTL %lx\n", dwIoControlCode);
1010 error = STATUS_INVALID_PARAMETER;
1014 if (lpBytesReturned) *lpBytesReturned = sz;
1017 SetLastError(error);
1020 CDROM_Close(clientID, dev);