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;
116 return STATUS_NO_MEDIA_IN_DEVICE;
118 FIXME("Unmapped error code %d: %s\n", errno, strerror(errno));
119 return STATUS_IO_DEVICE_ERROR;
122 static DWORD CDROM_GetControl(int dev, CDROM_AUDIO_CONTROL* cac)
124 cac->LbaFormat = 0; /* FIXME */
125 cac->LogicalBlocksPerSecond = 1; /* FIXME */
126 return STATUS_NOT_SUPPORTED;
129 static DWORD CDROM_GetDeviceNumber(int dev, STORAGE_DEVICE_NUMBER* devnum)
131 return STATUS_NOT_SUPPORTED;
134 static DWORD CDROM_GetDriveGeometry(int dev, DISK_GEOMETRY* dg)
137 dg->Cylinders.s.LowPart = 1; /* FIXME */
138 dg->Cylinders.s.HighPart = 0; /* FIXME */
139 dg->MediaType = 1; /* FIXME */
140 dg->TracksPerCylinder = 1; /* FIXME */
141 dg->SectorsPerTrack = 1; /* FIXME */
142 dg->BytesPerSector= 1; /* FIXME */
144 return STATUS_NOT_SUPPORTED;
147 /**************************************************************************
148 * CDROM_Reset [internal]
150 static DWORD CDROM_ResetAudio(int dev)
153 return CDROM_GetStatusCode(ioctl(dev, CDROMRESET));
154 #elif defined(__FreeBSD__) || defined(__NetBSD__)
155 return CDROM_GetStatusCode(ioctl(dev, CDIOCRESET, NULL));
157 return STATUS_NOT_SUPPORTED;
161 /******************************************************************
166 static DWORD CDROM_SetTray(int dev, BOOL doEject)
169 return CDROM_GetStatusCode(ioctl(dev, doEject ? CDROMEJECT : CDROMCLOSETRAY));
170 #elif defined(__FreeBSD__) || defined(__NetBSD__)
171 return CDROM_GetStatusCode((ioctl(dev, CDIOCALLOW, NULL)) ||
172 (ioctl(dev, doEject ? CDIOCEJECT : CDIOCCLOSE, NULL)) ||
173 (ioctl(dev, CDIOCPREVENT, NULL)));
175 return STATUS_NOT_SUPPORTED;
179 /******************************************************************
180 * CDROM_ControlEjection
184 static DWORD CDROM_ControlEjection(int dev, const PREVENT_MEDIA_REMOVAL* rmv)
187 return CDROM_GetStatusCode(ioctl(dev, CDROM_LOCKDOOR, rmv->PreventMediaRemoval));
188 #elif defined(__FreeBSD__) || defined(__NetBSD__)
189 return CDROM_GetStatusCode(ioctl(dev, (rmv->PreventMediaRemoval) ? CDIOCPREVENT : CDIOCALLOW, NULL));
191 return STATUS_NOT_SUPPORTED;
195 /******************************************************************
200 static DWORD CDROM_ReadTOC(int dev, CDROM_TOC* toc)
202 DWORD ret = STATUS_NOT_SUPPORTED;
206 struct cdrom_tochdr hdr;
207 struct cdrom_tocentry entry;
209 io = ioctl(dev, CDROMREADTOCHDR, &hdr);
212 WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
215 toc->FirstTrack = hdr.cdth_trk0;
216 toc->LastTrack = hdr.cdth_trk1;
218 TRACE("from=%d to=%d\n", toc->FirstTrack, toc->LastTrack);
220 for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
222 if (i == toc->LastTrack + 1)
224 entry.cdte_track = CDROM_LEADOUT;
226 entry.cdte_track = i;
228 entry.cdte_format = CDROM_MSF;
229 io = ioctl(dev, CDROMREADTOCENTRY, &entry);
231 WARN("error read entry (%s)\n", strerror(errno));
234 toc->TrackData[i - toc->FirstTrack].Control = entry.cdte_ctrl;
235 toc->TrackData[i - toc->FirstTrack].Adr = entry.cdte_adr;
236 /* marking last track with leadout value as index */
237 toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.cdte_track;
238 toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
239 toc->TrackData[i - toc->FirstTrack].Address[1] = entry.cdte_addr.msf.minute;
240 toc->TrackData[i - toc->FirstTrack].Address[2] = entry.cdte_addr.msf.second;
241 toc->TrackData[i - toc->FirstTrack].Address[3] = entry.cdte_addr.msf.frame;
244 ret = CDROM_GetStatusCode(io);
245 #elif defined(__FreeBSD__) || defined(__NetBSD__)
247 struct ioc_toc_header hdr;
248 struct ioc_read_toc_entry entry;
249 struct cd_toc_entry toc_buffer;
251 io = ioctl(dev, CDIOREADTOCHEADER, &hdr);
254 WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
257 toc->FirstTrack = hdr.starting_track;
258 toc->LastTrack = hdr.ending_track;
260 TRACE("from=%d to=%d\n", toc->FirstTrack, toc->LastTrack);
262 for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
264 if (i == toc->LastTrack + 1)
267 entry.starting_track = LEADOUT;
269 entry.starting_track = i;
271 memset((char *)&toc_buffer, 0, sizeof(toc_buffer));
272 entry.address_format = CD_MSF_FORMAT;
273 entry.data_len = sizeof(toc_buffer);
274 entry.data = &toc_buffer;
275 io = ioctl(dev, CDIOREADTOCENTRYS, &entry);
277 WARN("error read entry (%s)\n", strerror(errno));
280 toc->TrackData[i - toc->FirstTrack].Control = toc_buffer.control;
281 toc->TrackData[i - toc->FirstTrack].Adr = toc_buffer.addr_type;
282 /* marking last track with leadout value as index */
283 toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.starting_track;
284 toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
285 toc->TrackData[i - toc->FirstTrack].Address[1] = toc_buffer.addr.msf.minute;
286 toc->TrackData[i - toc->FirstTrack].Address[2] = toc_buffer.addr.msf.second;
287 toc->TrackData[i - toc->FirstTrack].Address[3] = toc_buffer.addr.msf.frame;
290 ret = CDROM_GetStatusCode(io);
292 ret = STATUS_NOT_SUPPORTED;
297 /******************************************************************
302 static DWORD CDROM_GetDiskData(int dev, CDROM_DISK_DATA* data)
308 if ((ret = CDROM_ReadTOC(dev, &toc)) != 0) return ret;
310 for (i = toc.FirstTrack; i <= toc.LastTrack; i++) {
311 if (toc.TrackData[i].Control & 0x04)
312 data->DiskData |= CDROM_DISK_DATA_TRACK;
314 data->DiskData |= CDROM_DISK_AUDIO_TRACK;
319 /******************************************************************
324 static DWORD CDROM_ReadQChannel(int dev, const CDROM_SUB_Q_DATA_FORMAT* fmt,
325 SUB_Q_CHANNEL_DATA* data)
327 DWORD ret = STATUS_NOT_SUPPORTED;
330 SUB_Q_HEADER* hdr = (SUB_Q_HEADER*)data;
332 struct cdrom_subchnl sc;
333 sc.cdsc_format = CDROM_MSF;
335 io = ioctl(dev, CDROMSUBCHNL, &sc);
338 TRACE("opened or no_media (%s)!\n", strerror(errno));
339 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
343 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
345 switch (sc.cdsc_audiostatus) {
346 case CDROM_AUDIO_INVALID:
347 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
349 case CDROM_AUDIO_NO_STATUS:
350 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
352 case CDROM_AUDIO_PLAY:
353 hdr->AudioStatus = AUDIO_STATUS_IN_PROGRESS;
355 case CDROM_AUDIO_PAUSED:
356 hdr->AudioStatus = AUDIO_STATUS_PAUSED;
358 case CDROM_AUDIO_COMPLETED:
359 hdr->AudioStatus = AUDIO_STATUS_PLAY_COMPLETE;
361 case CDROM_AUDIO_ERROR:
362 hdr->AudioStatus = AUDIO_STATUS_PLAY_ERROR;
365 TRACE("status=%02X !\n", sc.cdsc_audiostatus);
370 case IOCTL_CDROM_CURRENT_POSITION:
371 size = sizeof(SUB_Q_CURRENT_POSITION);
372 data->CurrentPosition.FormatCode = sc.cdsc_format;
373 data->CurrentPosition.Control = sc.cdsc_ctrl;
374 data->CurrentPosition.ADR = sc.cdsc_adr;
375 data->CurrentPosition.TrackNumber = sc.cdsc_trk;
376 data->CurrentPosition.IndexNumber = sc.cdsc_ind;
378 data->CurrentPosition.AbsoluteAddress[0] = 0;
379 data->CurrentPosition.AbsoluteAddress[1] = sc.cdsc_absaddr.msf.minute;
380 data->CurrentPosition.AbsoluteAddress[2] = sc.cdsc_absaddr.msf.second;
381 data->CurrentPosition.AbsoluteAddress[3] = sc.cdsc_absaddr.msf.frame;
383 data->CurrentPosition.TrackRelativeAddress[0] = 0;
384 data->CurrentPosition.TrackRelativeAddress[1] = sc.cdsc_reladdr.msf.minute;
385 data->CurrentPosition.TrackRelativeAddress[2] = sc.cdsc_reladdr.msf.second;
386 data->CurrentPosition.TrackRelativeAddress[3] = sc.cdsc_reladdr.msf.frame;
388 case IOCTL_CDROM_MEDIA_CATALOG:
389 size = sizeof(SUB_Q_MEDIA_CATALOG_NUMBER);
390 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
392 struct cdrom_mcn mcn;
393 if ((io = ioctl(dev, CDROM_GET_MCN, &mcn)) == -1) goto end;
395 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
396 data->MediaCatalog.Mcval = 0; /* FIXME */
397 memcpy(data->MediaCatalog.MediaCatalog, mcn.medium_catalog_number, 14);
398 data->MediaCatalog.MediaCatalog[14] = 0;
401 case IOCTL_CDROM_TRACK_ISRC:
402 size = sizeof(SUB_Q_CURRENT_POSITION);
403 FIXME("TrackIsrc: NIY on linux");
404 data->TrackIsrc.FormatCode = IOCTL_CDROM_TRACK_ISRC;
405 data->TrackIsrc.Tcval = 0;
411 ret = CDROM_GetStatusCode(io);
412 #elif defined(__FreeBSD__) || defined(__NetBSD__)
414 SUB_Q_HEADER* hdr = (SUB_Q_HEADER*)data;
416 struct ioc_read_subchannel read_sc;
417 struct cd_sub_channel_info sc;
419 read_sc.address_format = CD_MSF_FORMAT;
421 read_sc.data_len = sizeof(sc);
425 case IOCTL_CDROM_CURRENT_POSITION:
426 read_sc.data_format = CD_CURRENT_POSITION;
428 case IOCTL_CDROM_MEDIA_CATALOG:
429 read_sc.data_format = CD_MEDIA_CATALOG;
431 case IOCTL_CDROM_TRACK_ISRC:
432 read_sc.data_format = CD_TRACK_INFO;
433 sc.what.track_info.track_number = data->TrackIsrc.Track;
436 io = ioctl(dev, CDIOCREADSUBCHANNEL, &read_sc);
439 TRACE("opened or no_media (%s)!\n", strerror(errno));
440 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
444 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
446 switch (sc.header.audio_status) {
447 case CD_AS_AUDIO_INVALID:
448 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
450 case CD_AS_NO_STATUS:
451 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
453 case CD_AS_PLAY_IN_PROGRESS:
454 hdr->AudioStatus = AUDIO_STATUS_IN_PROGRESS;
456 case CD_AS_PLAY_PAUSED:
457 hdr->AudioStatus = AUDIO_STATUS_PAUSED;
459 case CD_AS_PLAY_COMPLETED:
460 hdr->AudioStatus = AUDIO_STATUS_PLAY_COMPLETE;
462 case CD_AS_PLAY_ERROR:
463 hdr->AudioStatus = AUDIO_STATUS_PLAY_ERROR;
466 TRACE("status=%02X !\n", sc.header.audio_status);
470 case IOCTL_CDROM_CURRENT_POSITION:
471 size = sizeof(SUB_Q_CURRENT_POSITION);
472 data->CurrentPosition.FormatCode = sc.what.position.data_format;
473 data->CurrentPosition.Control = sc.what.position.control;
474 data->CurrentPosition.ADR = sc.what.position.addr_type;
475 data->CurrentPosition.TrackNumber = sc.what.position.track_number;
476 data->CurrentPosition.IndexNumber = sc.what.position.index_number;
478 data->CurrentPosition.AbsoluteAddress[0] = 0;
479 data->CurrentPosition.AbsoluteAddress[1] = sc.what.position.absaddr.msf.minute;
480 data->CurrentPosition.AbsoluteAddress[2] = sc.what.position.absaddr.msf.second;
481 data->CurrentPosition.AbsoluteAddress[3] = sc.what.position.absaddr.msf.frame;
482 data->CurrentPosition.TrackRelativeAddress[0] = 0;
483 data->CurrentPosition.TrackRelativeAddress[1] = sc.what.position.reladdr.msf.minute;
484 data->CurrentPosition.TrackRelativeAddress[2] = sc.what.position.reladdr.msf.second;
485 data->CurrentPosition.TrackRelativeAddress[3] = sc.what.position.reladdr.msf.frame;
487 case IOCTL_CDROM_MEDIA_CATALOG:
488 size = sizeof(SUB_Q_MEDIA_CATALOG_NUMBER);
489 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
490 data->MediaCatalog.FormatCode = sc.what.media_catalog.data_format;
491 data->MediaCatalog.Mcval = sc.what.media_catalog.mc_valid;
492 memcpy(data->MediaCatalog.MediaCatalog, sc.what.media_catalog.mc_number, 15);
494 case IOCTL_CDROM_TRACK_ISRC:
495 size = sizeof(SUB_Q_CURRENT_POSITION);
496 data->TrackIsrc.Tcval = sc.what.track_info.ti_valid;
497 memcpy(data->TrackIsrc.TrackIsrc, sc.what.track_info.ti_number, 15);
502 ret = CDROM_GetStatusCode(io);
507 /******************************************************************
512 static DWORD CDROM_Verify(int dev)
514 /* quick implementation */
515 CDROM_SUB_Q_DATA_FORMAT fmt;
516 SUB_Q_CHANNEL_DATA data;
518 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
519 return CDROM_ReadQChannel(dev, &fmt, &data) ? 0 : 1;
522 /******************************************************************
527 static DWORD CDROM_PlayAudioMSF(int dev, const CDROM_PLAY_AUDIO_MSF* audio_msf)
529 DWORD ret = STATUS_NOT_SUPPORTED;
531 struct cdrom_msf msf;
534 msf.cdmsf_min0 = audio_msf->StartingM;
535 msf.cdmsf_sec0 = audio_msf->StartingS;
536 msf.cdmsf_frame0 = audio_msf->StartingF;
537 msf.cdmsf_min1 = audio_msf->EndingM;
538 msf.cdmsf_sec1 = audio_msf->EndingS;
539 msf.cdmsf_frame1 = audio_msf->EndingF;
541 io = ioctl(dev, CDROMSTART);
544 WARN("motor doesn't start !\n");
547 io = ioctl(dev, CDROMPLAYMSF, &msf);
550 WARN("device doesn't play !\n");
553 TRACE("msf = %d:%d:%d %d:%d:%d\n",
554 msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0,
555 msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1);
557 ret = CDROM_GetStatusCode(io);
558 #elif defined(__FreeBSD__) || defined(__NetBSD__)
559 struct ioc_play_msf msf;
562 msf.start_m = audio_msf->StartingM;
563 msf.start_s = audio_msf->StartingS;
564 msf.start_f = audio_msf->StartingF;
565 msf.end_m = audio_msf->EndingM;
566 msf.end_s = audio_msf->EndingS;
567 msf.end_f = audio_msf->EndingF;
569 io = ioctl(dev, CDIOCSTART, NULL);
572 WARN("motor doesn't start !\n");
575 io = ioctl(dev, CDIOCPLAYMSF, &msf);
578 WARN("device doesn't play !\n");
581 TRACE("msf = %d:%d:%d %d:%d:%d\n",
582 msf.start_m, msf.start_s, msf.start_f,
583 msf.end_m, msf.end_s, msf.end_f);
585 ret = CDROM_GetStatusCode(io);
590 /******************************************************************
595 static DWORD CDROM_SeekAudioMSF(int dev, const CDROM_SEEK_AUDIO_MSF* audio_msf)
598 struct cdrom_msf0 msf;
599 msf.minute = audio_msf->M;
600 msf.second = audio_msf->S;
601 msf.frame = audio_msf->F;
603 return CDROM_GetStatusCode(ioctl(dev, CDROMSEEK, &msf));
604 #elif defined(__FreeBSD__) || defined(__NetBSD__)
605 FIXME("Could a BSD expert implement the seek function ?\n");
606 return STATUS_NOT_SUPPORTED;
608 return STATUS_NOT_SUPPORTED;
612 /******************************************************************
617 static DWORD CDROM_PauseAudio(int dev)
620 return CDROM_GetStatusCode(ioctl(dev, CDROMPAUSE));
621 #elif defined(__FreeBSD__) || defined(__NetBSD__)
622 return CDROM_GetStatusCode(ioctl(dev, CDIOCPAUSE, NULL));
624 return STATUS_NOT_SUPPORTED;
628 /******************************************************************
633 static DWORD CDROM_ResumeAudio(int dev)
636 return CDROM_GetStatusCode(ioctl(dev, CDROMRESUME));
637 #elif defined(__FreeBSD__) || defined(__NetBSD__)
638 return CDROM_GetStatusCode(ioctl(dev, CDIOCRESUME, NULL));
640 return STATUS_NOT_SUPPORTED;
644 /******************************************************************
649 static DWORD CDROM_StopAudio(int dev)
652 return CDROM_GetStatusCode(ioctl(dev, CDROMSTOP));
653 #elif defined(__FreeBSD__) || defined(__NetBSD__)
654 return CDROM_GetStatusCode(ioctl(dev, CDIOCSTOP, NULL));
656 return STATUS_NOT_SUPPORTED;
660 /******************************************************************
665 static DWORD CDROM_GetVolume(int dev, VOLUME_CONTROL* vc)
668 struct cdrom_volctrl volc;
671 io = ioctl(dev, CDROMVOLREAD, &volc);
674 vc->PortVolume[0] = volc.channel0;
675 vc->PortVolume[1] = volc.channel1;
676 vc->PortVolume[2] = volc.channel2;
677 vc->PortVolume[3] = volc.channel3;
679 return CDROM_GetStatusCode(io);
680 #elif defined(__FreeBSD__) || defined(__NetBSD__)
684 io = ioctl(dev, CDIOCGETVOL, &volc);
687 vc->PortVolume[0] = volc.vol[0];
688 vc->PortVolume[1] = volc.vol[1];
689 vc->PortVolume[2] = volc.vol[2];
690 vc->PortVolume[3] = volc.vol[3];
692 return CDROM_GetStatusCode(io);
694 return STATUS_NOT_SUPPORTED;
698 /******************************************************************
703 static DWORD CDROM_SetVolume(int dev, const VOLUME_CONTROL* vc)
706 struct cdrom_volctrl volc;
708 volc.channel0 = vc->PortVolume[0];
709 volc.channel1 = vc->PortVolume[1];
710 volc.channel2 = vc->PortVolume[2];
711 volc.channel3 = vc->PortVolume[3];
713 return CDROM_GetStatusCode(ioctl(dev, CDROMVOLCTRL, &volc));
714 #elif defined(__FreeBSD__) || defined(__NetBSD__)
717 volc.vol[0] = vc->PortVolume[0];
718 volc.vol[1] = vc->PortVolume[1];
719 volc.vol[2] = vc->PortVolume[2];
720 volc.vol[3] = vc->PortVolume[3];
722 return CDROM_GetStatusCode(ioctl(dev, CDIOCSETVOL, &volc));
724 return STATUS_NOT_SUPPORTED;
728 /******************************************************************
733 static DWORD CDROM_RawRead(int dev, const RAW_READ_INFO* raw, void* buffer, DWORD len, DWORD* sz)
735 int ret = STATUS_NOT_SUPPORTED;
739 switch (raw->TrackMode)
741 case YellowMode2: sectSize = 2336; break;
742 case XAForm2: sectSize = 2328; break;
743 case CDDA: sectSize = 2352; break;
744 default: return STATUS_INVALID_PARAMETER;
746 if (len < raw->SectorCount * sectSize) return STATUS_BUFFER_TOO_SMALL;
747 /* strangely enough, it seems that sector offsets are always indicated with a size of 2048,
748 * even if a larger size if read...
752 struct cdrom_read cdr;
753 struct cdrom_read_audio cdra;
755 switch (raw->TrackMode)
758 if (raw->DiskOffset.s.HighPart) FIXME("Unsupported value\n");
759 cdr.cdread_lba = raw->DiskOffset.s.LowPart; /* FIXME ? */
760 cdr.cdread_bufaddr = buffer;
761 cdr.cdread_buflen = raw->SectorCount * sectSize;
762 io = ioctl(dev, CDROMREADMODE2, &cdr);
765 FIXME("XAForm2: NIY\n");
768 /* FIXME: the output doesn't seem 100% correct... in fact output is shifted
769 * between by NT2K box and this... should check on the same drive...
770 * otherwise, I fear a 2352/2368 mismatch somewhere in one of the drivers
772 * Anyway, that's not critical at all. We're talking of 16/32 bytes, we're
773 * talking of 0.2 ms of sound
776 if (raw->DiskOffset.s.HighPart & ~2047) FIXME("Unsupported value\n");
777 cdra.addr.lba = ((raw->DiskOffset.s.LowPart >> 11) |
778 (raw->DiskOffset.s.HighPart << (32 - 11))) - 1;
779 FIXME("reading at %u\n", cdra.addr.lba);
780 cdra.addr_format = CDROM_LBA;
781 cdra.nframes = raw->SectorCount;
783 io = ioctl(dev, CDROMREADAUDIO, &cdra);
787 #elif defined(__FreeBSD__)
789 struct ioc_read_audio ira;
791 switch (raw->TrackMode)
794 FIXME("YellowMode2: NIY\n");
797 FIXME("XAForm2: NIY\n");
801 if (raw->DiskOffset.s.HighPart & ~2047) FIXME("Unsupported value\n");
802 ira.address.lba = ((raw->DiskOffset.s.LowPart >> 11) |
803 raw->DiskOffset.s.HighPart << (32 - 11)) - 1;
804 ira.address_format = CD_LBA_FORMAT;
805 ira.nframes = raw->SectorCount;
807 io = ioctl(dev, CDIOCREADAUDIO, &ira);
811 #elif defined(__NetBSD__)
813 switch (raw->TrackMode)
816 FIXME("YellowMode2: NIY\n");
819 FIXME("XAForm2: NIY\n");
822 FIXME("CDDA: NIY\n");
827 *sz = sectSize * raw->SectorCount;
828 ret = CDROM_GetStatusCode(io);
832 /******************************************************************
833 * CDROM_DeviceIoControl
837 BOOL CDROM_DeviceIoControl(DWORD clientID, HANDLE hDevice, DWORD dwIoControlCode,
838 LPVOID lpInBuffer, DWORD nInBufferSize,
839 LPVOID lpOutBuffer, DWORD nOutBufferSize,
840 LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped)
846 TRACE("%lx[%c] %lx %lx %ld %lx %ld %lx %lx\n",
847 (DWORD)hDevice, 'A' + LOWORD(clientID), dwIoControlCode, (DWORD)lpInBuffer, nInBufferSize,
848 (DWORD)lpOutBuffer, nOutBufferSize, (DWORD)lpBytesReturned, (DWORD)lpOverlapped);
850 if (lpBytesReturned) *lpBytesReturned = 0;
853 FIXME("Overlapped isn't implemented yet\n");
854 SetLastError(STATUS_NOT_SUPPORTED);
859 dev = CDROM_Open(hDevice, clientID);
862 CDROM_GetStatusCode(-1);
866 switch (dwIoControlCode)
868 case IOCTL_STORAGE_CHECK_VERIFY:
869 case IOCTL_CDROM_CHECK_VERIFY:
871 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
872 error = STATUS_INVALID_PARAMETER;
873 else error = CDROM_Verify(dev);
876 /* EPP case IOCTL_STORAGE_CHECK_VERIFY2: */
878 /* EPP case IOCTL_STORAGE_FIND_NEW_DEVICES: */
879 /* EPP case IOCTL_CDROM_FIND_NEW_DEVICES: */
881 case IOCTL_STORAGE_LOAD_MEDIA:
882 case IOCTL_CDROM_LOAD_MEDIA:
884 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
885 error = STATUS_INVALID_PARAMETER;
886 else error = CDROM_SetTray(dev, FALSE);
888 case IOCTL_STORAGE_EJECT_MEDIA:
890 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
891 error = STATUS_INVALID_PARAMETER;
892 else error = CDROM_SetTray(dev, TRUE);
895 case IOCTL_DISK_MEDIA_REMOVAL:
896 case IOCTL_STORAGE_MEDIA_REMOVAL:
897 case IOCTL_STORAGE_EJECTION_CONTROL:
898 /* FIXME the last ioctl:s is not the same as the two others...
899 * lockcount/owner should be handled */
901 if (lpOutBuffer != NULL || nOutBufferSize != 0) error = STATUS_INVALID_PARAMETER;
902 else if (nInBufferSize < sizeof(PREVENT_MEDIA_REMOVAL)) error = STATUS_BUFFER_TOO_SMALL;
903 else error = CDROM_ControlEjection(dev, (const PREVENT_MEDIA_REMOVAL*)lpInBuffer);
906 /* EPP case IOCTL_STORAGE_GET_MEDIA_TYPES: */
908 case IOCTL_STORAGE_GET_DEVICE_NUMBER:
909 sz = sizeof(STORAGE_DEVICE_NUMBER);
910 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
911 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
912 else error = CDROM_GetDeviceNumber(dev, (STORAGE_DEVICE_NUMBER*)lpOutBuffer);
915 case IOCTL_STORAGE_RESET_DEVICE:
917 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
918 error = STATUS_INVALID_PARAMETER;
919 else error = CDROM_ResetAudio(dev);
922 case IOCTL_CDROM_GET_CONTROL:
923 sz = sizeof(CDROM_AUDIO_CONTROL);
924 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
925 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
926 else error = CDROM_GetControl(dev, (CDROM_AUDIO_CONTROL*)lpOutBuffer);
929 case IOCTL_CDROM_GET_DRIVE_GEOMETRY:
930 sz = sizeof(DISK_GEOMETRY);
931 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
932 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
933 else error = CDROM_GetDriveGeometry(dev, (DISK_GEOMETRY*)lpOutBuffer);
936 case IOCTL_CDROM_DISK_TYPE:
937 sz = sizeof(CDROM_DISK_DATA);
938 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
939 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
940 else error = CDROM_GetDiskData(dev, (CDROM_DISK_DATA*)lpOutBuffer);
943 /* EPP case IOCTL_CDROM_GET_LAST_SESSION: */
945 case IOCTL_CDROM_READ_Q_CHANNEL:
946 sz = sizeof(SUB_Q_CHANNEL_DATA);
947 if (lpInBuffer == NULL || nInBufferSize < sizeof(CDROM_SUB_Q_DATA_FORMAT))
948 error = STATUS_INVALID_PARAMETER;
949 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
950 else error = CDROM_ReadQChannel(dev, (const CDROM_SUB_Q_DATA_FORMAT*)lpInBuffer,
951 (SUB_Q_CHANNEL_DATA*)lpOutBuffer);
954 case IOCTL_CDROM_READ_TOC:
955 sz = sizeof(CDROM_TOC);
956 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
957 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
958 else error = CDROM_ReadTOC(dev, (CDROM_TOC*)lpOutBuffer);
961 /* EPP case IOCTL_CDROM_READ_TOC_EX: */
963 case IOCTL_CDROM_PAUSE_AUDIO:
965 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
966 error = STATUS_INVALID_PARAMETER;
967 else error = CDROM_PauseAudio(dev);
969 case IOCTL_CDROM_PLAY_AUDIO_MSF:
971 if (lpOutBuffer != NULL || nOutBufferSize != 0) error = STATUS_INVALID_PARAMETER;
972 else if (nInBufferSize < sizeof(CDROM_PLAY_AUDIO_MSF)) error = STATUS_BUFFER_TOO_SMALL;
973 else error = CDROM_PlayAudioMSF(dev, (const CDROM_PLAY_AUDIO_MSF*)lpInBuffer);
975 case IOCTL_CDROM_RESUME_AUDIO:
977 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
978 error = STATUS_INVALID_PARAMETER;
979 else error = CDROM_ResumeAudio(dev);
981 case IOCTL_CDROM_SEEK_AUDIO_MSF:
983 if (lpOutBuffer != NULL || nOutBufferSize != 0) error = STATUS_INVALID_PARAMETER;
984 else if (nInBufferSize < sizeof(CDROM_SEEK_AUDIO_MSF)) error = STATUS_BUFFER_TOO_SMALL;
985 else error = CDROM_SeekAudioMSF(dev, (const CDROM_SEEK_AUDIO_MSF*)lpInBuffer);
987 case IOCTL_CDROM_STOP_AUDIO:
989 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
990 error = STATUS_INVALID_PARAMETER;
991 else error = CDROM_StopAudio(dev);
993 case IOCTL_CDROM_GET_VOLUME:
994 sz = sizeof(VOLUME_CONTROL);
995 if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
996 else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
997 else error = CDROM_GetVolume(dev, (VOLUME_CONTROL*)lpOutBuffer);
999 case IOCTL_CDROM_SET_VOLUME:
1001 if (lpInBuffer == NULL || nInBufferSize < sizeof(VOLUME_CONTROL) || lpOutBuffer != NULL)
1002 error = STATUS_INVALID_PARAMETER;
1003 else error = CDROM_SetVolume(dev, (const VOLUME_CONTROL*)lpInBuffer);
1005 case IOCTL_CDROM_RAW_READ:
1007 if (nInBufferSize < sizeof(RAW_READ_INFO)) error = STATUS_INVALID_PARAMETER;
1008 else if (lpOutBuffer == NULL) error = STATUS_BUFFER_TOO_SMALL;
1009 else error = CDROM_RawRead(dev, (const RAW_READ_INFO*)lpInBuffer,
1010 lpOutBuffer, nOutBufferSize, &sz);
1013 FIXME("Unsupported IOCTL %lx\n", dwIoControlCode);
1015 error = STATUS_INVALID_PARAMETER;
1019 if (lpBytesReturned) *lpBytesReturned = sz;
1022 SetLastError(error);
1025 CDROM_Close(clientID, dev);