1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /* Main file for CD-ROM support
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1999, 2001, 2003 Eric Pouech
6 * Copyright 2000 Andreas Mohr
7 * Copyright 2005 Ivan Leo Puoti
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/port.h"
38 #ifdef HAVE_SYS_STAT_H
39 # include <sys/stat.h>
41 #include <sys/types.h>
43 #ifdef HAVE_SYS_IOCTL_H
44 #include <sys/ioctl.h>
49 #ifdef HAVE_SCSI_SCSI_H
50 # include <scsi/scsi.h>
51 # undef REASSIGN_BLOCKS /* avoid conflict with winioctl.h */
53 #ifdef HAVE_SCSI_SCSI_IOCTL_H
54 # include <scsi/scsi_ioctl.h>
56 #ifdef HAVE_LINUX_MAJOR_H
57 # include <linux/major.h>
59 #ifdef HAVE_LINUX_HDREG_H
60 # include <linux/hdreg.h>
62 #ifdef HAVE_LINUX_PARAM_H
63 # include <linux/param.h>
65 #ifdef HAVE_LINUX_CDROM_H
66 # include <linux/cdrom.h>
68 #ifdef HAVE_LINUX_UCDROM_H
69 # include <linux/ucdrom.h>
71 #ifdef HAVE_SYS_CDIO_H
72 # include <sys/cdio.h>
74 #ifdef HAVE_SYS_SCSIIO_H
75 # include <sys/scsiio.h>
78 #define NONAMELESSUNION
79 #define NONAMELESSSTRUCT
89 #include "ntdll_misc.h"
90 #include "wine/server.h"
91 #include "wine/library.h"
92 #include "wine/debug.h"
94 /* Non-Linux systems do not have linux/cdrom.h and the like, and thus
95 lack the following constants. */
98 # define CD_SECS 60 /* seconds per minute */
101 # define CD_FRAMES 75 /* frames per second */
104 /* definitions taken from libdvdcss */
106 #define IOCTL_DVD_BASE FILE_DEVICE_DVD
108 #define IOCTL_DVD_START_SESSION CTL_CODE(IOCTL_DVD_BASE, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
109 #define IOCTL_DVD_READ_KEY CTL_CODE(IOCTL_DVD_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
110 #define IOCTL_DVD_SEND_KEY CTL_CODE(IOCTL_DVD_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
111 #define IOCTL_DVD_END_SESSION CTL_CODE(IOCTL_DVD_BASE, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
112 #define IOCTL_DVD_SET_READ_AHEAD CTL_CODE(IOCTL_DVD_BASE, 0x0404, METHOD_BUFFERED, FILE_READ_ACCESS)
113 #define IOCTL_DVD_GET_REGION CTL_CODE(IOCTL_DVD_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS)
114 #define IOCTL_DVD_SEND_KEY2 CTL_CODE(IOCTL_DVD_BASE, 0x0406, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
116 #define IOCTL_DVD_READ_STRUCTURE CTL_CODE(IOCTL_DVD_BASE, 0x0450, METHOD_BUFFERED, FILE_READ_ACCESS)
119 DvdChallengeKey = 0x01,
127 DvdInvalidateAGID = 0x3f
130 typedef ULONG DVD_SESSION_ID, *PDVD_SESSION_ID;
132 typedef struct _DVD_COPY_PROTECT_KEY {
134 DVD_SESSION_ID SessionId;
135 DVD_KEY_TYPE KeyType;
140 ULONG Reserved; /* used for NT alignment */
142 LARGE_INTEGER TitleOffset;
145 } DVD_COPY_PROTECT_KEY, *PDVD_COPY_PROTECT_KEY;
147 typedef struct _DVD_RPC_KEY {
148 UCHAR UserResetsAvailable:3;
149 UCHAR ManufacturerResetsAvailable:3;
154 } DVD_RPC_KEY, * PDVD_RPC_KEY;
156 typedef struct _DVD_ASF {
160 } DVD_ASF, * PDVD_ASF;
162 typedef struct _DVD_REGION
164 unsigned char copy_system;
165 unsigned char region_data; /* current media region (not playable when set) */
166 unsigned char system_region; /* current drive region (playable when set) */
167 unsigned char reset_count; /* number of resets available */
168 } DVD_REGION, * PDVD_REGION;
170 typedef struct _DVD_READ_STRUCTURE {
171 /* Contains an offset to the logical block address of the descriptor to be retrieved. */
172 LARGE_INTEGER block_byte_offset;
174 /* 0:Physical descriptor, 1:Copyright descriptor, 2:Disk key descriptor
175 3:BCA descriptor, 4:Manufacturer descriptor, 5:Max descriptor
179 /* Session ID, that is obtained by IOCTL_DVD_START_SESSION */
183 unsigned char layer_no;
184 }DVD_READ_STRUCTURE, * PDVD_READ_STRUCTURE;
186 typedef struct _DVD_LAYER_DESCRIPTOR
188 unsigned short length;
190 unsigned char book_version : 4;
192 /* 0:DVD-ROM, 1:DVD-RAM, 2:DVD-R, 3:DVD-RW, 9:DVD-RW */
193 unsigned char book_type : 4;
195 unsigned char minimum_rate : 4;
197 /* The physical size of the media. 0:120 mm, 1:80 mm. */
198 unsigned char disk_size : 4;
200 /* 1:Read-only layer, 2:Recordable layer, 4:Rewritable layer */
201 unsigned char layer_type : 4;
203 /* 0:parallel track path, 1:opposite track path */
204 unsigned char track_path : 1;
206 /* 0:one layers, 1:two layers, and so on */
207 unsigned char num_of_layers : 2;
209 unsigned char reserved1 : 1;
211 /* 0:0.74 µm/track, 1:0.80 µm/track, 2:0.615 µm/track */
212 unsigned char track_density : 4;
214 /* 0:0.267 µm/bit, 1:0.293 µm/bit, 2:0.409 to 0.435 µm/bit, 4:0.280 to 0.291 µm/bit, 8:0.353 µm/bit */
215 unsigned char linear_density : 4;
217 /* Must be either 0x30000:DVD-ROM or DVD-R/-RW or 0x31000:DVD-RAM or DVD+RW */
218 unsigned long starting_data_sector;
220 unsigned long end_data_sector;
221 unsigned long end_layer_zero_sector;
222 unsigned char reserved5 : 7;
224 /* 0 indicates no BCA data */
225 unsigned char BCA_flag : 1;
227 unsigned char reserved6;
228 }DVD_LAYER_DESCRIPTOR, * PDVD_LAYER_DESCRIPTOR;
230 typedef struct _DVD_COPYRIGHT_DESCRIPTOR
232 unsigned char protection;
233 unsigned char region;
234 unsigned short reserved;
235 }DVD_COPYRIGHT_DESCRIPTOR, * PDVD_COPYRIGHT_DESCRIPTOR;
237 typedef struct _DVD_MANUFACTURER_DESCRIPTOR
239 unsigned char manufacturing[2048];
240 }DVD_MANUFACTURER_DESCRIPTOR, * PDVD_MANUFACTURER_DESCRIPTOR;
242 #define DVD_CHALLENGE_KEY_LENGTH (12 + sizeof(DVD_COPY_PROTECT_KEY) - sizeof(UCHAR))
244 #define DVD_DISK_KEY_LENGTH (2048 + sizeof(DVD_COPY_PROTECT_KEY) - sizeof(UCHAR))
246 #define DVD_KEY_SIZE 5
247 #define DVD_CHALLENGE_SIZE 10
248 #define DVD_DISCKEY_SIZE 2048
249 #define DVD_SECTOR_PROTECTED 0x00000020
251 static const struct iocodexs
256 #define X(x) { x, #x },
257 X(IOCTL_CDROM_CHECK_VERIFY)
258 X(IOCTL_CDROM_CURRENT_POSITION)
259 X(IOCTL_CDROM_DISK_TYPE)
260 X(IOCTL_CDROM_GET_CONTROL)
261 X(IOCTL_CDROM_GET_DRIVE_GEOMETRY)
262 X(IOCTL_CDROM_GET_VOLUME)
263 X(IOCTL_CDROM_LOAD_MEDIA)
264 X(IOCTL_CDROM_MEDIA_CATALOG)
265 X(IOCTL_CDROM_MEDIA_REMOVAL)
266 X(IOCTL_CDROM_PAUSE_AUDIO)
267 X(IOCTL_CDROM_PLAY_AUDIO_MSF)
268 X(IOCTL_CDROM_RAW_READ)
269 X(IOCTL_CDROM_READ_Q_CHANNEL)
270 X(IOCTL_CDROM_READ_TOC)
271 X(IOCTL_CDROM_RESUME_AUDIO)
272 X(IOCTL_CDROM_SEEK_AUDIO_MSF)
273 X(IOCTL_CDROM_SET_VOLUME)
274 X(IOCTL_CDROM_STOP_AUDIO)
275 X(IOCTL_CDROM_TRACK_ISRC)
276 X(IOCTL_DISK_MEDIA_REMOVAL)
277 X(IOCTL_DVD_END_SESSION)
278 X(IOCTL_DVD_GET_REGION)
279 X(IOCTL_DVD_READ_KEY)
280 X(IOCTL_DVD_READ_STRUCTURE)
281 X(IOCTL_DVD_SEND_KEY)
282 X(IOCTL_DVD_START_SESSION)
283 X(IOCTL_SCSI_GET_ADDRESS)
284 X(IOCTL_SCSI_GET_CAPABILITIES)
285 X(IOCTL_SCSI_PASS_THROUGH)
286 X(IOCTL_SCSI_PASS_THROUGH_DIRECT)
287 X(IOCTL_STORAGE_CHECK_VERIFY)
288 X(IOCTL_STORAGE_EJECTION_CONTROL)
289 X(IOCTL_STORAGE_EJECT_MEDIA)
290 X(IOCTL_STORAGE_GET_DEVICE_NUMBER)
291 X(IOCTL_STORAGE_LOAD_MEDIA)
292 X(IOCTL_STORAGE_MEDIA_REMOVAL)
293 X(IOCTL_STORAGE_RESET_DEVICE)
296 static const char *iocodex(DWORD code)
299 static char buffer[25];
300 for(i=0; i<sizeof(iocodextable)/sizeof(struct iocodexs); i++)
301 if (code==iocodextable[i].code)
302 return iocodextable[i].codex;
303 sprintf(buffer, "IOCTL_CODE_%x", (int)code);
307 WINE_DEFAULT_DEBUG_CHANNEL(cdrom);
309 #define FRAME_OF_ADDR(a) (((int)(a)[1] * CD_SECS + (a)[2]) * CD_FRAMES + (a)[3])
310 #define FRAME_OF_MSF(a) (((int)(a).M * CD_SECS + (a).S) * CD_FRAMES + (a).F)
311 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
312 #define MSF_OF_FRAME(m,fr) {int f=(fr); ((UCHAR *)&(m))[2]=f%CD_FRAMES;f/=CD_FRAMES;((UCHAR *)&(m))[1]=f%CD_SECS;((UCHAR *)&(m))[0]=f/CD_SECS;}
314 static NTSTATUS CDROM_ReadTOC(int, int, CDROM_TOC*);
315 static NTSTATUS CDROM_GetStatusCode(int);
321 # define IDE6_MAJOR 88
324 # define IDE7_MAJOR 89
327 # ifdef CDROM_SEND_PACKET
328 /* structure for CDROM_PACKET_COMMAND ioctl */
329 /* not all Linux versions have all the fields, so we define the
330 * structure ourselves to make sure */
331 struct linux_cdrom_generic_command
333 unsigned char cmd[CDROM_PACKET_SIZE];
334 unsigned char *buffer;
337 struct request_sense *sense;
338 unsigned char data_direction;
343 # endif /* CDROM_SEND_PACKET */
347 /* FIXME: this is needed because we can't open simultaneously several times /dev/cdrom
348 * this should be removed when a proper device interface is implemented
350 * (WS) We need this to keep track of current position and to safely
351 * detect media changes. Besides this should provide a great speed up
357 char toc_good; /* if false, will reread TOC from disk */
359 SUB_Q_CURRENT_POSITION CurrentPosition;
361 /* who has more than 5 cdroms on his/her machine ?? */
362 /* FIXME: this should grow depending on the number of cdroms we install/configure
365 #define MAX_CACHE_ENTRIES 5
366 static struct cdrom_cache cdrom_cache[MAX_CACHE_ENTRIES];
368 static CRITICAL_SECTION cache_section;
369 static CRITICAL_SECTION_DEBUG critsect_debug =
371 0, 0, &cache_section,
372 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
373 0, 0, { 0, (DWORD)(__FILE__ ": cache_section") }
375 static CRITICAL_SECTION cache_section = { &critsect_debug, -1, 0, 0, 0, 0 };
377 /* Proposed media change function: not really needed at this time */
378 /* This is a 1 or 0 type of function */
380 static int CDROM_MediaChanged(int dev)
384 struct cdrom_tochdr hdr;
385 struct cdrom_tocentry entry;
387 if (dev < 0 || dev >= MAX_CACHE_ENTRIES)
389 if ( ioctl(cdrom_cache[dev].fd, CDROMREADTOCHDR, &hdr) == -1 )
392 if ( memcmp(&hdr, &cdrom_cache[dev].hdr, sizeof(struct cdrom_tochdr)) )
395 for (i=hdr.cdth_trk0; i<=hdr.cdth_trk1+1; i++)
397 if (i == hdr.cdth_trk1 + 1)
399 entry.cdte_track = CDROM_LEADOUT;
401 entry.cdte_track = i;
403 entry.cdte_format = CDROM_MSF;
404 if ( ioctl(cdrom_cache[dev].fd, CDROMREADTOCENTRY, &entry) == -1)
406 if ( memcmp(&entry, cdrom_cache[dev].entry+i-hdr.cdth_trk0,
407 sizeof(struct cdrom_tocentry)) )
414 /******************************************************************
415 * CDROM_SyncCache [internal]
417 * Read the TOC in and store it in the cdrom_cache structure.
418 * Further requests for the TOC will be copied from the cache
419 * unless certain events like disk ejection is detected, in which
420 * case the cache will be cleared, causing it to be resynced.
421 * The cache section must be held by caller.
423 static int CDROM_SyncCache(int dev, int fd)
427 struct cdrom_tochdr hdr;
428 struct cdrom_tocentry entry;
429 #elif defined(__FreeBSD__) || defined(__NetBSD__)
430 struct ioc_toc_header hdr;
431 struct ioc_read_toc_entry entry;
432 struct cd_toc_entry toc_buffer;
434 CDROM_TOC *toc = &cdrom_cache[dev].toc;
435 cdrom_cache[dev].toc_good = 0;
439 io = ioctl(fd, CDROMREADTOCHDR, &hdr);
442 WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
446 toc->FirstTrack = hdr.cdth_trk0;
447 toc->LastTrack = hdr.cdth_trk1;
448 tsz = sizeof(toc->FirstTrack) + sizeof(toc->LastTrack)
449 + sizeof(TRACK_DATA) * (toc->LastTrack-toc->FirstTrack+2);
450 toc->Length[0] = tsz >> 8;
451 toc->Length[1] = tsz;
453 TRACE("caching toc from=%d to=%d\n", toc->FirstTrack, toc->LastTrack );
455 for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
457 if (i == toc->LastTrack + 1)
458 entry.cdte_track = CDROM_LEADOUT;
460 entry.cdte_track = i;
461 entry.cdte_format = CDROM_MSF;
462 io = ioctl(fd, CDROMREADTOCENTRY, &entry);
464 WARN("error read entry (%s)\n", strerror(errno));
467 toc->TrackData[i - toc->FirstTrack].Control = entry.cdte_ctrl;
468 toc->TrackData[i - toc->FirstTrack].Adr = entry.cdte_adr;
469 /* marking last track with leadout value as index */
470 toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.cdte_track;
471 toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
472 toc->TrackData[i - toc->FirstTrack].Address[1] = entry.cdte_addr.msf.minute;
473 toc->TrackData[i - toc->FirstTrack].Address[2] = entry.cdte_addr.msf.second;
474 toc->TrackData[i - toc->FirstTrack].Address[3] = entry.cdte_addr.msf.frame;
476 cdrom_cache[dev].toc_good = 1;
478 #elif defined(__FreeBSD__) || defined(__NetBSD__)
480 io = ioctl(fd, CDIOREADTOCHEADER, &hdr);
483 WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
486 toc->FirstTrack = hdr.starting_track;
487 toc->LastTrack = hdr.ending_track;
488 tsz = sizeof(toc->FirstTrack) + sizeof(toc->LastTrack)
489 + sizeof(TRACK_DATA) * (toc->LastTrack-toc->FirstTrack+2);
490 toc->Length[0] = tsz >> 8;
491 toc->Length[1] = tsz;
493 TRACE("caching toc from=%d to=%d\n", toc->FirstTrack, toc->LastTrack );
495 for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
497 if (i == toc->LastTrack + 1)
500 entry.starting_track = LEADOUT;
502 entry.starting_track = i;
504 memset((char *)&toc_buffer, 0, sizeof(toc_buffer));
505 entry.address_format = CD_MSF_FORMAT;
506 entry.data_len = sizeof(toc_buffer);
507 entry.data = &toc_buffer;
508 io = ioctl(fd, CDIOREADTOCENTRYS, &entry);
510 WARN("error read entry (%s)\n", strerror(errno));
513 toc->TrackData[i - toc->FirstTrack].Control = toc_buffer.control;
514 toc->TrackData[i - toc->FirstTrack].Adr = toc_buffer.addr_type;
515 /* marking last track with leadout value as index */
516 toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.starting_track;
517 toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
518 toc->TrackData[i - toc->FirstTrack].Address[1] = toc_buffer.addr.msf.minute;
519 toc->TrackData[i - toc->FirstTrack].Address[2] = toc_buffer.addr.msf.second;
520 toc->TrackData[i - toc->FirstTrack].Address[3] = toc_buffer.addr.msf.frame;
522 cdrom_cache[dev].toc_good = 1;
525 return STATUS_NOT_SUPPORTED;
528 return CDROM_GetStatusCode(io);
531 static void CDROM_ClearCacheEntry(int dev)
533 RtlEnterCriticalSection( &cache_section );
534 cdrom_cache[dev].toc_good = 0;
535 RtlLeaveCriticalSection( &cache_section );
540 /******************************************************************
541 * CDROM_GetInterfaceInfo
543 * Determines the ide interface (the number after the ide), and the
544 * number of the device on that interface for ide cdroms (*port == 0).
545 * Determines the scsi information for scsi cdroms (*port >= 1).
546 * Returns false if the info cannot not be obtained.
548 static int CDROM_GetInterfaceInfo(int fd, int* port, int* iface, int* device,int* lun)
552 if ( fstat(fd, &st) == -1 || ! S_ISBLK(st.st_mode)) return 0;
557 switch (major(st.st_rdev)) {
558 case IDE0_MAJOR: *iface = 0; break;
559 case IDE1_MAJOR: *iface = 1; break;
560 case IDE2_MAJOR: *iface = 2; break;
561 case IDE3_MAJOR: *iface = 3; break;
562 case IDE4_MAJOR: *iface = 4; break;
563 case IDE5_MAJOR: *iface = 5; break;
564 case IDE6_MAJOR: *iface = 6; break;
565 case IDE7_MAJOR: *iface = 7; break;
566 default: *port = 1; break;
570 *device = (minor(st.st_rdev) >> 6);
573 #ifdef SCSI_IOCTL_GET_IDLUN
575 if (ioctl(fd, SCSI_IOCTL_GET_IDLUN, &idlun) != -1)
577 *port = ((idlun[0] >> 24) & 0xff) + 1;
578 *iface = (idlun[0] >> 16) & 0xff;
579 *device = idlun[0] & 0xff;
580 *lun = (idlun[0] >> 8) & 0xff;
585 WARN("CD-ROM device (%d, %d) not supported\n", major(st.st_rdev), minor(st.st_rdev));
590 #elif defined(__NetBSD__)
591 struct scsi_addr addr;
592 if (ioctl(fd, SCIOCIDENTIFY, &addr) != -1)
596 case TYPE_SCSI: *port = 1;
597 *iface = addr.addr.scsi.scbus;
598 *device = addr.addr.scsi.target;
599 *lun = addr.addr.scsi.lun;
601 case TYPE_ATAPI: *port = 0;
602 *iface = addr.addr.atapi.atbus;
603 *device = addr.addr.atapi.drive;
610 #elif defined(__FreeBSD__)
611 FIXME("not implemented for BSD\n");
614 FIXME("not implemented for nonlinux\n");
620 /******************************************************************
624 static NTSTATUS CDROM_Open(int fd, int* dev)
627 NTSTATUS ret = STATUS_SUCCESS;
632 RtlEnterCriticalSection( &cache_section );
633 for (*dev = 0; *dev < MAX_CACHE_ENTRIES; (*dev)++)
636 cdrom_cache[*dev].device == 0 &&
637 cdrom_cache[*dev].inode == 0)
639 else if (cdrom_cache[*dev].device == st.st_dev &&
640 cdrom_cache[*dev].inode == st.st_ino)
643 if (*dev == MAX_CACHE_ENTRIES)
645 if (empty == -1) ret = STATUS_NOT_IMPLEMENTED;
649 cdrom_cache[*dev].device = st.st_dev;
650 cdrom_cache[*dev].inode = st.st_ino;
653 RtlLeaveCriticalSection( &cache_section );
655 TRACE("%d, %d\n", *dev, fd);
659 /******************************************************************
660 * CDROM_GetStatusCode
664 static NTSTATUS CDROM_GetStatusCode(int io)
666 if (io == 0) return STATUS_SUCCESS;
667 return FILE_GetNtStatus();
670 /******************************************************************
674 static NTSTATUS CDROM_GetControl(int dev, CDROM_AUDIO_CONTROL* cac)
676 cac->LbaFormat = 0; /* FIXME */
677 cac->LogicalBlocksPerSecond = 1; /* FIXME */
678 return STATUS_NOT_SUPPORTED;
681 /******************************************************************
682 * CDROM_GetDeviceNumber
685 static NTSTATUS CDROM_GetDeviceNumber(int dev, STORAGE_DEVICE_NUMBER* devnum)
687 return STATUS_NOT_SUPPORTED;
690 /******************************************************************
691 * CDROM_GetDriveGeometry
694 static NTSTATUS CDROM_GetDriveGeometry(int dev, int fd, DISK_GEOMETRY* dg)
700 if ((ret = CDROM_ReadTOC(dev, fd, &toc)) != 0) return ret;
702 fsize = FRAME_OF_TOC(toc, toc.LastTrack+1)
703 - FRAME_OF_TOC(toc, 1); /* Total size in frames */
705 dg->Cylinders.u.LowPart = fsize / (64 * 32);
706 dg->Cylinders.u.HighPart = 0;
707 dg->MediaType = RemovableMedia;
708 dg->TracksPerCylinder = 64;
709 dg->SectorsPerTrack = 32;
710 dg->BytesPerSector= 2048;
714 /**************************************************************************
715 * CDROM_Reset [internal]
717 static NTSTATUS CDROM_ResetAudio(int fd)
720 return CDROM_GetStatusCode(ioctl(fd, CDROMRESET));
721 #elif defined(__FreeBSD__) || defined(__NetBSD__)
722 return CDROM_GetStatusCode(ioctl(fd, CDIOCRESET, NULL));
724 return STATUS_NOT_SUPPORTED;
728 /******************************************************************
733 static NTSTATUS CDROM_SetTray(int fd, BOOL doEject)
736 return CDROM_GetStatusCode(ioctl(fd, doEject ? CDROMEJECT : CDROMCLOSETRAY));
737 #elif defined(__FreeBSD__) || defined(__NetBSD__)
738 return CDROM_GetStatusCode((ioctl(fd, CDIOCALLOW, NULL)) ||
739 (ioctl(fd, doEject ? CDIOCEJECT : CDIOCCLOSE, NULL)) ||
740 (ioctl(fd, CDIOCPREVENT, NULL)));
742 return STATUS_NOT_SUPPORTED;
746 /******************************************************************
747 * CDROM_ControlEjection
751 static NTSTATUS CDROM_ControlEjection(int fd, const PREVENT_MEDIA_REMOVAL* rmv)
754 return CDROM_GetStatusCode(ioctl(fd, CDROM_LOCKDOOR, rmv->PreventMediaRemoval));
755 #elif defined(__FreeBSD__) || defined(__NetBSD__)
756 return CDROM_GetStatusCode(ioctl(fd, (rmv->PreventMediaRemoval) ? CDIOCPREVENT : CDIOCALLOW, NULL));
758 return STATUS_NOT_SUPPORTED;
762 /******************************************************************
767 static NTSTATUS CDROM_ReadTOC(int dev, int fd, CDROM_TOC* toc)
769 NTSTATUS ret = STATUS_NOT_SUPPORTED;
771 if (dev < 0 || dev >= MAX_CACHE_ENTRIES)
772 return STATUS_INVALID_PARAMETER;
774 RtlEnterCriticalSection( &cache_section );
775 if (cdrom_cache[dev].toc_good || !(ret = CDROM_SyncCache(dev, fd)))
777 *toc = cdrom_cache[dev].toc;
778 ret = STATUS_SUCCESS;
780 RtlLeaveCriticalSection( &cache_section );
784 /******************************************************************
789 static NTSTATUS CDROM_GetDiskData(int dev, int fd, CDROM_DISK_DATA* data)
795 if ((ret = CDROM_ReadTOC(dev, fd, &toc)) != 0) return ret;
797 for (i = toc.FirstTrack; i <= toc.LastTrack; i++) {
798 if (toc.TrackData[i-toc.FirstTrack].Control & 0x04)
799 data->DiskData |= CDROM_DISK_DATA_TRACK;
801 data->DiskData |= CDROM_DISK_AUDIO_TRACK;
803 return STATUS_SUCCESS;
806 /******************************************************************
811 static NTSTATUS CDROM_ReadQChannel(int dev, int fd, const CDROM_SUB_Q_DATA_FORMAT* fmt,
812 SUB_Q_CHANNEL_DATA* data)
814 NTSTATUS ret = STATUS_NOT_SUPPORTED;
817 SUB_Q_HEADER* hdr = (SUB_Q_HEADER*)data;
819 struct cdrom_subchnl sc;
820 sc.cdsc_format = CDROM_MSF;
822 io = ioctl(fd, CDROMSUBCHNL, &sc);
825 TRACE("opened or no_media (%s)!\n", strerror(errno));
826 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
827 CDROM_ClearCacheEntry(dev);
831 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
833 switch (sc.cdsc_audiostatus) {
834 case CDROM_AUDIO_INVALID:
835 CDROM_ClearCacheEntry(dev);
836 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
838 case CDROM_AUDIO_NO_STATUS:
839 CDROM_ClearCacheEntry(dev);
840 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
842 case CDROM_AUDIO_PLAY:
843 hdr->AudioStatus = AUDIO_STATUS_IN_PROGRESS;
845 case CDROM_AUDIO_PAUSED:
846 hdr->AudioStatus = AUDIO_STATUS_PAUSED;
848 case CDROM_AUDIO_COMPLETED:
849 hdr->AudioStatus = AUDIO_STATUS_PLAY_COMPLETE;
851 case CDROM_AUDIO_ERROR:
852 hdr->AudioStatus = AUDIO_STATUS_PLAY_ERROR;
855 TRACE("status=%02X !\n", sc.cdsc_audiostatus);
860 case IOCTL_CDROM_CURRENT_POSITION:
861 size = sizeof(SUB_Q_CURRENT_POSITION);
862 RtlEnterCriticalSection( &cache_section );
863 if (hdr->AudioStatus==AUDIO_STATUS_IN_PROGRESS) {
864 data->CurrentPosition.FormatCode = IOCTL_CDROM_CURRENT_POSITION;
865 data->CurrentPosition.Control = sc.cdsc_ctrl;
866 data->CurrentPosition.ADR = sc.cdsc_adr;
867 data->CurrentPosition.TrackNumber = sc.cdsc_trk;
868 data->CurrentPosition.IndexNumber = sc.cdsc_ind;
870 data->CurrentPosition.AbsoluteAddress[0] = 0;
871 data->CurrentPosition.AbsoluteAddress[1] = sc.cdsc_absaddr.msf.minute;
872 data->CurrentPosition.AbsoluteAddress[2] = sc.cdsc_absaddr.msf.second;
873 data->CurrentPosition.AbsoluteAddress[3] = sc.cdsc_absaddr.msf.frame;
875 data->CurrentPosition.TrackRelativeAddress[0] = 0;
876 data->CurrentPosition.TrackRelativeAddress[1] = sc.cdsc_reladdr.msf.minute;
877 data->CurrentPosition.TrackRelativeAddress[2] = sc.cdsc_reladdr.msf.second;
878 data->CurrentPosition.TrackRelativeAddress[3] = sc.cdsc_reladdr.msf.frame;
880 cdrom_cache[dev].CurrentPosition = data->CurrentPosition;
882 else /* not playing */
884 cdrom_cache[dev].CurrentPosition.Header = *hdr; /* Preserve header info */
885 data->CurrentPosition = cdrom_cache[dev].CurrentPosition;
887 RtlLeaveCriticalSection( &cache_section );
889 case IOCTL_CDROM_MEDIA_CATALOG:
890 size = sizeof(SUB_Q_MEDIA_CATALOG_NUMBER);
891 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
893 struct cdrom_mcn mcn;
894 if ((io = ioctl(fd, CDROM_GET_MCN, &mcn)) == -1) goto end;
896 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
897 data->MediaCatalog.Mcval = 0; /* FIXME */
898 memcpy(data->MediaCatalog.MediaCatalog, mcn.medium_catalog_number, 14);
899 data->MediaCatalog.MediaCatalog[14] = 0;
902 case IOCTL_CDROM_TRACK_ISRC:
903 size = sizeof(SUB_Q_CURRENT_POSITION);
904 FIXME("TrackIsrc: NIY on linux\n");
905 data->TrackIsrc.FormatCode = IOCTL_CDROM_TRACK_ISRC;
906 data->TrackIsrc.Tcval = 0;
912 ret = CDROM_GetStatusCode(io);
913 #elif defined(__FreeBSD__) || defined(__NetBSD__)
915 SUB_Q_HEADER* hdr = (SUB_Q_HEADER*)data;
917 struct ioc_read_subchannel read_sc;
918 struct cd_sub_channel_info sc;
920 read_sc.address_format = CD_MSF_FORMAT;
922 read_sc.data_len = sizeof(sc);
926 case IOCTL_CDROM_CURRENT_POSITION:
927 read_sc.data_format = CD_CURRENT_POSITION;
929 case IOCTL_CDROM_MEDIA_CATALOG:
930 read_sc.data_format = CD_MEDIA_CATALOG;
932 case IOCTL_CDROM_TRACK_ISRC:
933 read_sc.data_format = CD_TRACK_INFO;
934 sc.what.track_info.track_number = data->TrackIsrc.Track;
937 io = ioctl(fd, CDIOCREADSUBCHANNEL, &read_sc);
940 TRACE("opened or no_media (%s)!\n", strerror(errno));
941 CDROM_ClearCacheEntry(dev);
942 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
946 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
948 switch (sc.header.audio_status) {
949 case CD_AS_AUDIO_INVALID:
950 CDROM_ClearCacheEntry(dev);
951 hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
953 case CD_AS_NO_STATUS:
954 CDROM_ClearCacheEntry(dev);
955 hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
957 case CD_AS_PLAY_IN_PROGRESS:
958 hdr->AudioStatus = AUDIO_STATUS_IN_PROGRESS;
960 case CD_AS_PLAY_PAUSED:
961 hdr->AudioStatus = AUDIO_STATUS_PAUSED;
963 case CD_AS_PLAY_COMPLETED:
964 hdr->AudioStatus = AUDIO_STATUS_PLAY_COMPLETE;
966 case CD_AS_PLAY_ERROR:
967 hdr->AudioStatus = AUDIO_STATUS_PLAY_ERROR;
970 TRACE("status=%02X !\n", sc.header.audio_status);
974 case IOCTL_CDROM_CURRENT_POSITION:
975 size = sizeof(SUB_Q_CURRENT_POSITION);
976 RtlEnterCriticalSection( &cache_section );
977 if (hdr->AudioStatus==AUDIO_STATUS_IN_PROGRESS) {
978 data->CurrentPosition.FormatCode = IOCTL_CDROM_CURRENT_POSITION;
979 data->CurrentPosition.Control = sc.what.position.control;
980 data->CurrentPosition.ADR = sc.what.position.addr_type;
981 data->CurrentPosition.TrackNumber = sc.what.position.track_number;
982 data->CurrentPosition.IndexNumber = sc.what.position.index_number;
984 data->CurrentPosition.AbsoluteAddress[0] = 0;
985 data->CurrentPosition.AbsoluteAddress[1] = sc.what.position.absaddr.msf.minute;
986 data->CurrentPosition.AbsoluteAddress[2] = sc.what.position.absaddr.msf.second;
987 data->CurrentPosition.AbsoluteAddress[3] = sc.what.position.absaddr.msf.frame;
988 data->CurrentPosition.TrackRelativeAddress[0] = 0;
989 data->CurrentPosition.TrackRelativeAddress[1] = sc.what.position.reladdr.msf.minute;
990 data->CurrentPosition.TrackRelativeAddress[2] = sc.what.position.reladdr.msf.second;
991 data->CurrentPosition.TrackRelativeAddress[3] = sc.what.position.reladdr.msf.frame;
992 cdrom_cache[dev].CurrentPosition = data->CurrentPosition;
994 else { /* not playing */
995 cdrom_cache[dev].CurrentPosition.Header = *hdr; /* Preserve header info */
996 data->CurrentPosition = cdrom_cache[dev].CurrentPosition;
998 RtlLeaveCriticalSection( &cache_section );
1000 case IOCTL_CDROM_MEDIA_CATALOG:
1001 size = sizeof(SUB_Q_MEDIA_CATALOG_NUMBER);
1002 data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
1003 data->MediaCatalog.Mcval = sc.what.media_catalog.mc_valid;
1004 memcpy(data->MediaCatalog.MediaCatalog, sc.what.media_catalog.mc_number, 15);
1006 case IOCTL_CDROM_TRACK_ISRC:
1007 size = sizeof(SUB_Q_CURRENT_POSITION);
1008 data->TrackIsrc.FormatCode = IOCTL_CDROM_TRACK_ISRC;
1009 data->TrackIsrc.Tcval = sc.what.track_info.ti_valid;
1010 memcpy(data->TrackIsrc.TrackIsrc, sc.what.track_info.ti_number, 15);
1015 ret = CDROM_GetStatusCode(io);
1020 /******************************************************************
1025 static NTSTATUS CDROM_Verify(int dev, int fd)
1027 /* quick implementation */
1028 CDROM_SUB_Q_DATA_FORMAT fmt;
1029 SUB_Q_CHANNEL_DATA data;
1031 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
1032 return CDROM_ReadQChannel(dev, fd, &fmt, &data) ? 1 : 0;
1035 /******************************************************************
1036 * CDROM_PlayAudioMSF
1040 static NTSTATUS CDROM_PlayAudioMSF(int fd, const CDROM_PLAY_AUDIO_MSF* audio_msf)
1042 NTSTATUS ret = STATUS_NOT_SUPPORTED;
1044 struct cdrom_msf msf;
1047 msf.cdmsf_min0 = audio_msf->StartingM;
1048 msf.cdmsf_sec0 = audio_msf->StartingS;
1049 msf.cdmsf_frame0 = audio_msf->StartingF;
1050 msf.cdmsf_min1 = audio_msf->EndingM;
1051 msf.cdmsf_sec1 = audio_msf->EndingS;
1052 msf.cdmsf_frame1 = audio_msf->EndingF;
1054 io = ioctl(fd, CDROMSTART);
1057 WARN("motor doesn't start !\n");
1060 io = ioctl(fd, CDROMPLAYMSF, &msf);
1063 WARN("device doesn't play !\n");
1066 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1067 msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0,
1068 msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1);
1070 ret = CDROM_GetStatusCode(io);
1071 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1072 struct ioc_play_msf msf;
1075 msf.start_m = audio_msf->StartingM;
1076 msf.start_s = audio_msf->StartingS;
1077 msf.start_f = audio_msf->StartingF;
1078 msf.end_m = audio_msf->EndingM;
1079 msf.end_s = audio_msf->EndingS;
1080 msf.end_f = audio_msf->EndingF;
1082 io = ioctl(fd, CDIOCSTART, NULL);
1085 WARN("motor doesn't start !\n");
1088 io = ioctl(fd, CDIOCPLAYMSF, &msf);
1091 WARN("device doesn't play !\n");
1094 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1095 msf.start_m, msf.start_s, msf.start_f,
1096 msf.end_m, msf.end_s, msf.end_f);
1098 ret = CDROM_GetStatusCode(io);
1103 /******************************************************************
1104 * CDROM_SeekAudioMSF
1108 static NTSTATUS CDROM_SeekAudioMSF(int dev, int fd, const CDROM_SEEK_AUDIO_MSF* audio_msf)
1112 SUB_Q_CURRENT_POSITION *cp;
1114 struct cdrom_msf0 msf;
1115 struct cdrom_subchnl sc;
1116 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1117 struct ioc_play_msf msf;
1118 struct ioc_read_subchannel read_sc;
1119 struct cd_sub_channel_info sc;
1123 /* Use the information on the TOC to compute the new current
1124 * position, which is shadowed on the cache. [Portable]. */
1125 frame = FRAME_OF_MSF(*audio_msf);
1127 if ((io = CDROM_ReadTOC(dev, fd, &toc)) != 0) return io;
1129 for(i=toc.FirstTrack;i<=toc.LastTrack+1;i++)
1130 if (FRAME_OF_TOC(toc,i)>frame) break;
1131 if (i <= toc.FirstTrack || i > toc.LastTrack+1)
1132 return STATUS_INVALID_PARAMETER;
1134 RtlEnterCriticalSection( &cache_section );
1135 cp = &cdrom_cache[dev].CurrentPosition;
1136 cp->FormatCode = IOCTL_CDROM_CURRENT_POSITION;
1137 cp->Control = toc.TrackData[i-toc.FirstTrack].Control;
1138 cp->ADR = toc.TrackData[i-toc.FirstTrack].Adr;
1139 cp->TrackNumber = toc.TrackData[i-toc.FirstTrack].TrackNumber;
1140 cp->IndexNumber = 0; /* FIXME: where do they keep these? */
1141 cp->AbsoluteAddress[0] = 0;
1142 cp->AbsoluteAddress[1] = toc.TrackData[i-toc.FirstTrack].Address[1];
1143 cp->AbsoluteAddress[2] = toc.TrackData[i-toc.FirstTrack].Address[2];
1144 cp->AbsoluteAddress[3] = toc.TrackData[i-toc.FirstTrack].Address[3];
1145 frame -= FRAME_OF_TOC(toc,i);
1146 cp->TrackRelativeAddress[0] = 0;
1147 MSF_OF_FRAME(cp->TrackRelativeAddress[1], frame);
1148 RtlLeaveCriticalSection( &cache_section );
1150 /* If playing, then issue a seek command, otherwise do nothing */
1152 sc.cdsc_format = CDROM_MSF;
1154 io = ioctl(fd, CDROMSUBCHNL, &sc);
1157 TRACE("opened or no_media (%s)!\n", strerror(errno));
1158 CDROM_ClearCacheEntry(dev);
1159 return CDROM_GetStatusCode(io);
1161 if (sc.cdsc_audiostatus==CDROM_AUDIO_PLAY)
1163 msf.minute = audio_msf->M;
1164 msf.second = audio_msf->S;
1165 msf.frame = audio_msf->F;
1166 return CDROM_GetStatusCode(ioctl(fd, CDROMSEEK, &msf));
1168 return STATUS_SUCCESS;
1169 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1170 read_sc.address_format = CD_MSF_FORMAT;
1172 read_sc.data_len = sizeof(sc);
1174 read_sc.data_format = CD_CURRENT_POSITION;
1176 io = ioctl(fd, CDIOCREADSUBCHANNEL, &read_sc);
1179 TRACE("opened or no_media (%s)!\n", strerror(errno));
1180 CDROM_ClearCacheEntry(dev);
1181 return CDROM_GetStatusCode(io);
1183 if (sc.header.audio_status==CD_AS_PLAY_IN_PROGRESS)
1186 msf.start_m = audio_msf->M;
1187 msf.start_s = audio_msf->S;
1188 msf.start_f = audio_msf->F;
1189 final_frame = FRAME_OF_TOC(toc,toc.LastTrack+1)-1;
1190 MSF_OF_FRAME(msf.end_m, final_frame);
1192 return CDROM_GetStatusCode(ioctl(fd, CDIOCPLAYMSF, &msf));
1194 return STATUS_SUCCESS;
1196 return STATUS_NOT_SUPPORTED;
1200 /******************************************************************
1205 static NTSTATUS CDROM_PauseAudio(int fd)
1208 return CDROM_GetStatusCode(ioctl(fd, CDROMPAUSE));
1209 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1210 return CDROM_GetStatusCode(ioctl(fd, CDIOCPAUSE, NULL));
1212 return STATUS_NOT_SUPPORTED;
1216 /******************************************************************
1221 static NTSTATUS CDROM_ResumeAudio(int fd)
1224 return CDROM_GetStatusCode(ioctl(fd, CDROMRESUME));
1225 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1226 return CDROM_GetStatusCode(ioctl(fd, CDIOCRESUME, NULL));
1228 return STATUS_NOT_SUPPORTED;
1232 /******************************************************************
1237 static NTSTATUS CDROM_StopAudio(int fd)
1240 return CDROM_GetStatusCode(ioctl(fd, CDROMSTOP));
1241 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1242 return CDROM_GetStatusCode(ioctl(fd, CDIOCSTOP, NULL));
1244 return STATUS_NOT_SUPPORTED;
1248 /******************************************************************
1253 static NTSTATUS CDROM_GetVolume(int fd, VOLUME_CONTROL* vc)
1256 struct cdrom_volctrl volc;
1259 io = ioctl(fd, CDROMVOLREAD, &volc);
1262 vc->PortVolume[0] = volc.channel0;
1263 vc->PortVolume[1] = volc.channel1;
1264 vc->PortVolume[2] = volc.channel2;
1265 vc->PortVolume[3] = volc.channel3;
1267 return CDROM_GetStatusCode(io);
1268 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1269 struct ioc_vol volc;
1272 io = ioctl(fd, CDIOCGETVOL, &volc);
1275 vc->PortVolume[0] = volc.vol[0];
1276 vc->PortVolume[1] = volc.vol[1];
1277 vc->PortVolume[2] = volc.vol[2];
1278 vc->PortVolume[3] = volc.vol[3];
1280 return CDROM_GetStatusCode(io);
1282 return STATUS_NOT_SUPPORTED;
1286 /******************************************************************
1291 static NTSTATUS CDROM_SetVolume(int fd, const VOLUME_CONTROL* vc)
1294 struct cdrom_volctrl volc;
1296 volc.channel0 = vc->PortVolume[0];
1297 volc.channel1 = vc->PortVolume[1];
1298 volc.channel2 = vc->PortVolume[2];
1299 volc.channel3 = vc->PortVolume[3];
1301 return CDROM_GetStatusCode(ioctl(fd, CDROMVOLCTRL, &volc));
1302 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1303 struct ioc_vol volc;
1305 volc.vol[0] = vc->PortVolume[0];
1306 volc.vol[1] = vc->PortVolume[1];
1307 volc.vol[2] = vc->PortVolume[2];
1308 volc.vol[3] = vc->PortVolume[3];
1310 return CDROM_GetStatusCode(ioctl(fd, CDIOCSETVOL, &volc));
1312 return STATUS_NOT_SUPPORTED;
1316 /******************************************************************
1321 static NTSTATUS CDROM_RawRead(int fd, const RAW_READ_INFO* raw, void* buffer, DWORD len, DWORD* sz)
1323 int ret = STATUS_NOT_SUPPORTED;
1327 switch (raw->TrackMode)
1329 case YellowMode2: sectSize = 2336; break;
1330 case XAForm2: sectSize = 2328; break;
1331 case CDDA: sectSize = 2352; break;
1332 default: return STATUS_INVALID_PARAMETER;
1334 if (len < raw->SectorCount * sectSize) return STATUS_BUFFER_TOO_SMALL;
1335 /* strangely enough, it seems that sector offsets are always indicated with a size of 2048,
1336 * even if a larger size if read...
1340 struct cdrom_read cdr;
1341 struct cdrom_read_audio cdra;
1343 switch (raw->TrackMode)
1346 if (raw->DiskOffset.u.HighPart) FIXME("Unsupported value\n");
1347 cdr.cdread_lba = raw->DiskOffset.u.LowPart; /* FIXME ? */
1348 cdr.cdread_bufaddr = buffer;
1349 cdr.cdread_buflen = raw->SectorCount * sectSize;
1350 io = ioctl(fd, CDROMREADMODE2, &cdr);
1353 FIXME("XAForm2: NIY\n");
1356 /* FIXME: the output doesn't seem 100% correct... in fact output is shifted
1357 * between by NT2K box and this... should check on the same drive...
1358 * otherwise, I fear a 2352/2368 mismatch somewhere in one of the drivers
1360 * Anyway, that's not critical at all. We're talking of 16/32 bytes, we're
1361 * talking of 0.2 ms of sound
1363 /* 2048 = 2 ** 11 */
1364 if (raw->DiskOffset.u.HighPart & ~2047) FIXME("Unsupported value\n");
1365 cdra.addr.lba = ((raw->DiskOffset.u.LowPart >> 11) |
1366 (raw->DiskOffset.u.HighPart << (32 - 11))) - 1;
1367 FIXME("reading at %u\n", cdra.addr.lba);
1368 cdra.addr_format = CDROM_LBA;
1369 cdra.nframes = raw->SectorCount;
1371 io = ioctl(fd, CDROMREADAUDIO, &cdra);
1374 FIXME("NIY: %d\n", raw->TrackMode);
1380 switch (raw->TrackMode)
1383 FIXME("YellowMode2: NIY\n");
1386 FIXME("XAForm2: NIY\n");
1389 FIXME("CDDA: NIY\n");
1395 *sz = sectSize * raw->SectorCount;
1396 ret = CDROM_GetStatusCode(io);
1400 /******************************************************************
1401 * CDROM_ScsiPassThroughDirect
1402 * Implements IOCTL_SCSI_PASS_THROUGH_DIRECT
1405 static NTSTATUS CDROM_ScsiPassThroughDirect(int fd, PSCSI_PASS_THROUGH_DIRECT pPacket)
1407 int ret = STATUS_NOT_SUPPORTED;
1413 if (pPacket->Length < sizeof(SCSI_PASS_THROUGH_DIRECT))
1414 return STATUS_BUFFER_TOO_SMALL;
1416 if (pPacket->CdbLength > 16)
1417 return STATUS_INVALID_PARAMETER;
1419 if (pPacket->SenseInfoLength > sizeof(struct request_sense))
1420 return STATUS_INVALID_PARAMETER;
1422 if (pPacket->DataTransferLength > 0 && !pPacket->DataBuffer)
1423 return STATUS_INVALID_PARAMETER;
1425 RtlZeroMemory(&cmd, sizeof(cmd));
1427 cmd.interface_id = 'S';
1428 cmd.cmd_len = pPacket->CdbLength;
1429 cmd.mx_sb_len = pPacket->SenseInfoLength;
1430 cmd.dxfer_len = pPacket->DataTransferLength;
1431 cmd.dxferp = pPacket->DataBuffer;
1432 cmd.cmdp = pPacket->Cdb;
1433 cmd.sbp = (char*)pPacket + pPacket->SenseInfoOffset;
1434 cmd.timeout = pPacket->TimeOutValue*1000;
1436 switch (pPacket->DataIn)
1438 case SCSI_IOCTL_DATA_IN:
1439 cmd.dxfer_direction = SG_DXFER_TO_DEV;
1441 case SCSI_IOCTL_DATA_OUT:
1442 cmd.dxfer_direction = SG_DXFER_FROM_DEV;
1444 case SCSI_IOCTL_DATA_UNSPECIFIED:
1445 cmd.dxfer_direction = SG_DXFER_NONE;
1448 return STATUS_INVALID_PARAMETER;
1451 io = ioctl(fd, SG_IO, &cmd);
1453 pPacket->ScsiStatus = cmd.status;
1454 pPacket->DataTransferLength = cmd.resid;
1455 pPacket->SenseInfoLength = cmd.sb_len_wr;
1457 ret = CDROM_GetStatusCode(io);
1459 #elif defined(__NetBSD__)
1463 if (pPacket->Length < sizeof(SCSI_PASS_THROUGH_DIRECT))
1464 return STATUS_BUFFER_TOO_SMALL;
1466 if (pPacket->CdbLength > 12)
1467 return STATUS_INVALID_PARAMETER;
1469 if (pPacket->SenseInfoLength > SENSEBUFLEN)
1470 return STATUS_INVALID_PARAMETER;
1472 memset(&cmd, 0, sizeof(cmd));
1473 memcpy(&(cmd.cmd), &(pPacket->Cdb), pPacket->CdbLength);
1475 cmd.cmdlen = pPacket->CdbLength;
1476 cmd.databuf = pPacket->DataBuffer;
1477 cmd.datalen = pPacket->DataTransferLength;
1478 cmd.senselen = pPacket->SenseInfoLength;
1479 cmd.timeout = pPacket->TimeOutValue*1000; /* in milliseconds */
1481 switch (pPacket->DataIn)
1483 case SCSI_IOCTL_DATA_OUT:
1484 cmd.flags |= SCCMD_WRITE;
1486 case SCSI_IOCTL_DATA_IN:
1487 cmd.flags |= SCCMD_READ;
1489 case SCSI_IOCTL_DATA_UNSPECIFIED:
1493 return STATUS_INVALID_PARAMETER;
1496 io = ioctl(fd, SCIOCCOMMAND, &cmd);
1500 case SCCMD_OK: break;
1501 case SCCMD_TIMEOUT: return STATUS_TIMEOUT;
1503 case SCCMD_BUSY: return STATUS_DEVICE_BUSY;
1505 case SCCMD_SENSE: break;
1506 case SCCMD_UNKNOWN: return STATUS_UNSUCCESSFUL;
1510 if (pPacket->SenseInfoLength != 0)
1512 memcpy((char*)pPacket + pPacket->SenseInfoOffset,
1513 cmd.sense, pPacket->SenseInfoLength);
1516 pPacket->ScsiStatus = cmd.status;
1518 ret = CDROM_GetStatusCode(io);
1523 /******************************************************************
1524 * CDROM_ScsiPassThrough
1525 * Implements IOCTL_SCSI_PASS_THROUGH
1528 static NTSTATUS CDROM_ScsiPassThrough(int fd, PSCSI_PASS_THROUGH pPacket)
1530 int ret = STATUS_NOT_SUPPORTED;
1535 if (pPacket->Length < sizeof(SCSI_PASS_THROUGH))
1536 return STATUS_BUFFER_TOO_SMALL;
1538 if (pPacket->CdbLength > 16)
1539 return STATUS_INVALID_PARAMETER;
1541 if (pPacket->SenseInfoLength > sizeof(struct request_sense))
1542 return STATUS_INVALID_PARAMETER;
1544 if (pPacket->DataTransferLength > 0 && pPacket->DataBufferOffset < sizeof(SCSI_PASS_THROUGH))
1545 return STATUS_INVALID_PARAMETER;
1547 RtlZeroMemory(&cmd, sizeof(cmd));
1549 cmd.interface_id = 'S';
1550 cmd.dxfer_len = pPacket->DataTransferLength;
1551 cmd.dxferp = (char*)pPacket + pPacket->DataBufferOffset;
1552 cmd.cmd_len = pPacket->CdbLength;
1553 cmd.cmdp = pPacket->Cdb;
1554 cmd.mx_sb_len = pPacket->SenseInfoLength;
1555 cmd.timeout = pPacket->TimeOutValue*1000;
1557 if(cmd.mx_sb_len > 0)
1558 cmd.sbp = (char*)pPacket + pPacket->SenseInfoOffset;
1560 switch (pPacket->DataIn)
1562 case SCSI_IOCTL_DATA_IN:
1563 cmd.dxfer_direction = SG_DXFER_TO_DEV;
1565 case SCSI_IOCTL_DATA_OUT:
1566 cmd.dxfer_direction = SG_DXFER_FROM_DEV;
1568 case SCSI_IOCTL_DATA_UNSPECIFIED:
1569 cmd.dxfer_direction = SG_DXFER_NONE;
1572 return STATUS_INVALID_PARAMETER;
1575 io = ioctl(fd, SG_IO, &cmd);
1577 pPacket->ScsiStatus = cmd.status;
1578 pPacket->DataTransferLength = cmd.resid;
1579 pPacket->SenseInfoLength = cmd.sb_len_wr;
1581 ret = CDROM_GetStatusCode(io);
1583 #elif defined(__NetBSD__)
1587 if (pPacket->Length < sizeof(SCSI_PASS_THROUGH))
1588 return STATUS_BUFFER_TOO_SMALL;
1590 if (pPacket->CdbLength > 12)
1591 return STATUS_INVALID_PARAMETER;
1593 if (pPacket->SenseInfoLength > SENSEBUFLEN)
1594 return STATUS_INVALID_PARAMETER;
1596 memset(&cmd, 0, sizeof(cmd));
1597 memcpy(&(cmd.cmd), &(pPacket->Cdb), pPacket->CdbLength);
1599 if ( pPacket->DataBufferOffset > 0x1000 )
1601 cmd.databuf = (void*)pPacket->DataBufferOffset;
1605 cmd.databuf = (char*)pPacket + pPacket->DataBufferOffset;
1608 cmd.cmdlen = pPacket->CdbLength;
1609 cmd.datalen = pPacket->DataTransferLength;
1610 cmd.senselen = pPacket->SenseInfoLength;
1611 cmd.timeout = pPacket->TimeOutValue*1000; /* in milliseconds */
1613 switch (pPacket->DataIn)
1615 case SCSI_IOCTL_DATA_OUT:
1616 cmd.flags |= SCCMD_WRITE;
1618 case SCSI_IOCTL_DATA_IN:
1619 cmd.flags |= SCCMD_READ;
1621 case SCSI_IOCTL_DATA_UNSPECIFIED:
1625 return STATUS_INVALID_PARAMETER;
1628 io = ioctl(fd, SCIOCCOMMAND, &cmd);
1632 case SCCMD_OK: break;
1633 case SCCMD_TIMEOUT: return STATUS_TIMEOUT;
1635 case SCCMD_BUSY: return STATUS_DEVICE_BUSY;
1637 case SCCMD_SENSE: break;
1638 case SCCMD_UNKNOWN: return STATUS_UNSUCCESSFUL;
1642 if (pPacket->SenseInfoLength != 0)
1644 memcpy((char*)pPacket + pPacket->SenseInfoOffset,
1645 cmd.sense, pPacket->SenseInfoLength);
1648 pPacket->ScsiStatus = cmd.status;
1650 ret = CDROM_GetStatusCode(io);
1655 /******************************************************************
1660 static NTSTATUS CDROM_ScsiGetCaps(PIO_SCSI_CAPABILITIES caps)
1662 NTSTATUS ret = STATUS_NOT_IMPLEMENTED;
1664 caps->Length = sizeof(*caps);
1666 caps->MaximumTransferLength = SG_SCATTER_SZ; /* FIXME */
1667 caps->MaximumPhysicalPages = SG_SCATTER_SZ / getpagesize();
1668 caps->SupportedAsynchronousEvents = TRUE;
1669 caps->AlignmentMask = getpagesize();
1670 caps->TaggedQueuing = FALSE; /* we could check that it works and answer TRUE */
1671 caps->AdapterScansDown = FALSE; /* FIXME ? */
1672 caps->AdapterUsesPio = FALSE; /* FIXME ? */
1673 ret = STATUS_SUCCESS;
1675 FIXME("Unimplemented\n");
1680 /******************************************************************
1683 * implements IOCTL_SCSI_GET_ADDRESS
1685 static NTSTATUS CDROM_GetAddress(int fd, SCSI_ADDRESS* address)
1687 int portnum, busid, targetid, lun;
1689 address->Length = sizeof(SCSI_ADDRESS);
1690 if ( ! CDROM_GetInterfaceInfo(fd, &portnum, &busid, &targetid, &lun))
1691 return STATUS_NOT_SUPPORTED;
1693 address->PortNumber = portnum;
1694 address->PathId = busid; /* bus number */
1695 address->TargetId = targetid;
1697 return STATUS_SUCCESS;
1700 /******************************************************************
1705 static NTSTATUS DVD_StartSession(int fd, PDVD_SESSION_ID sid_in, PDVD_SESSION_ID sid_out)
1708 NTSTATUS ret = STATUS_NOT_SUPPORTED;
1709 dvd_authinfo auth_info;
1711 memset( &auth_info, 0, sizeof( auth_info ) );
1712 auth_info.type = DVD_LU_SEND_AGID;
1713 if (sid_in) auth_info.lsa.agid = *(int*)sid_in; /* ?*/
1715 TRACE("fd 0x%08x\n",fd);
1716 ret =CDROM_GetStatusCode(ioctl(fd, DVD_AUTH, &auth_info));
1717 *sid_out = auth_info.lsa.agid;
1719 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1720 return STATUS_NOT_SUPPORTED;
1722 return STATUS_NOT_SUPPORTED;
1726 /******************************************************************
1731 static NTSTATUS DVD_EndSession(int fd, PDVD_SESSION_ID sid)
1734 dvd_authinfo auth_info;
1736 memset( &auth_info, 0, sizeof( auth_info ) );
1737 auth_info.type = DVD_INVALIDATE_AGID;
1738 auth_info.lsa.agid = *(int*)sid;
1741 return CDROM_GetStatusCode(ioctl(fd, DVD_AUTH, &auth_info));
1742 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1743 return STATUS_NOT_SUPPORTED;
1745 return STATUS_NOT_SUPPORTED;
1749 /******************************************************************
1754 static NTSTATUS DVD_SendKey(int fd, PDVD_COPY_PROTECT_KEY key)
1757 NTSTATUS ret = STATUS_NOT_SUPPORTED;
1758 dvd_authinfo auth_info;
1760 memset( &auth_info, 0, sizeof( auth_info ) );
1761 switch (key->KeyType)
1763 case DvdChallengeKey:
1764 auth_info.type = DVD_HOST_SEND_CHALLENGE;
1765 auth_info.hsc.agid = (int)key->SessionId;
1766 TRACE("DvdChallengeKey ioc 0x%x\n", DVD_AUTH );
1767 memcpy( auth_info.hsc.chal, key->KeyData, DVD_CHALLENGE_SIZE );
1768 ret = CDROM_GetStatusCode(ioctl( fd, DVD_AUTH, &auth_info ));
1771 auth_info.type = DVD_HOST_SEND_KEY2;
1772 auth_info.hsk.agid = (int)key->SessionId;
1774 memcpy( auth_info.hsk.key, key->KeyData, DVD_KEY_SIZE );
1776 TRACE("DvdBusKey2\n");
1777 ret = CDROM_GetStatusCode(ioctl( fd, DVD_AUTH, &auth_info ));
1781 FIXME("Unknown Keytype 0x%x\n",key->KeyType);
1784 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1786 return STATUS_NOT_SUPPORTED;
1789 return STATUS_NOT_SUPPORTED;
1791 TRACE("not reached\n");
1794 /******************************************************************
1799 static NTSTATUS DVD_ReadKey(int fd, PDVD_COPY_PROTECT_KEY key)
1802 NTSTATUS ret = STATUS_NOT_SUPPORTED;
1804 dvd_authinfo auth_info;
1806 memset( &dvd, 0, sizeof( dvd_struct ) );
1807 memset( &auth_info, 0, sizeof( auth_info ) );
1808 switch (key->KeyType)
1812 dvd.type = DVD_STRUCT_DISCKEY;
1813 dvd.disckey.agid = (int)key->SessionId;
1814 memset( dvd.disckey.value, 0, DVD_DISCKEY_SIZE );
1816 TRACE("DvdDiskKey\n");
1817 ret = CDROM_GetStatusCode(ioctl( fd, DVD_READ_STRUCT, &dvd ));
1818 if (ret == STATUS_SUCCESS)
1819 memcpy(key->KeyData,dvd.disckey.value,DVD_DISCKEY_SIZE);
1822 auth_info.type = DVD_LU_SEND_TITLE_KEY;
1823 auth_info.lstk.agid = (int)key->SessionId;
1824 auth_info.lstk.lba = (int)(key->Parameters.TitleOffset.QuadPart>>11);
1825 TRACE("DvdTitleKey session %d Quadpart 0x%08lx offset 0x%08x\n",
1826 (int)key->SessionId, (long)key->Parameters.TitleOffset.QuadPart,
1827 auth_info.lstk.lba);
1828 ret = CDROM_GetStatusCode(ioctl( fd, DVD_AUTH, &auth_info ));
1829 if (ret == STATUS_SUCCESS)
1830 memcpy(key->KeyData, auth_info.lstk.title_key, DVD_KEY_SIZE );
1832 case DvdChallengeKey:
1834 auth_info.type = DVD_LU_SEND_CHALLENGE;
1835 auth_info.lsc.agid = (int)key->SessionId;
1837 TRACE("DvdChallengeKey\n");
1838 ret = CDROM_GetStatusCode(ioctl( fd, DVD_AUTH, &auth_info ));
1839 if (ret == STATUS_SUCCESS)
1840 memcpy( key->KeyData, auth_info.lsc.chal, DVD_CHALLENGE_SIZE );
1843 auth_info.type = DVD_LU_SEND_ASF;
1845 auth_info.lsasf.asf=((PDVD_ASF)key->KeyData)->SuccessFlag;
1846 ret = CDROM_GetStatusCode(ioctl( fd, DVD_AUTH, &auth_info ));
1847 ((PDVD_ASF)key->KeyData)->SuccessFlag = auth_info.lsasf.asf;
1850 auth_info.type = DVD_LU_SEND_KEY1;
1851 auth_info.lsk.agid = (int)key->SessionId;
1853 TRACE("DvdBusKey1\n");
1854 ret = CDROM_GetStatusCode(ioctl( fd, DVD_AUTH, &auth_info ));
1856 if (ret == STATUS_SUCCESS)
1857 memcpy( key->KeyData, auth_info.lsk.key, DVD_KEY_SIZE );
1860 auth_info.type = DVD_LU_SEND_RPC_STATE;
1862 TRACE("DvdGetRpcKey\n");
1863 ret = CDROM_GetStatusCode(ioctl( fd, DVD_AUTH, &auth_info ));
1865 if (ret == STATUS_SUCCESS)
1867 ((PDVD_RPC_KEY)key->KeyData)->TypeCode = auth_info.lrpcs.type;
1868 ((PDVD_RPC_KEY)key->KeyData)->RegionMask = auth_info.lrpcs.region_mask;
1869 ((PDVD_RPC_KEY)key->KeyData)->RpcScheme = auth_info.lrpcs.rpc_scheme;
1873 FIXME("Unknown keytype 0x%x\n",key->KeyType);
1876 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1878 return STATUS_NOT_SUPPORTED;
1881 return STATUS_NOT_SUPPORTED;
1883 TRACE("not reached\n");
1886 /******************************************************************
1891 static NTSTATUS DVD_GetRegion(int dev, PDVD_REGION region)
1894 return STATUS_SUCCESS;
1898 /******************************************************************
1903 static NTSTATUS DVD_ReadStructure(int dev, PDVD_READ_STRUCTURE structure, PDVD_LAYER_DESCRIPTOR layer)
1906 return STATUS_SUCCESS;
1909 /******************************************************************
1910 * CDROM_DeviceIoControl
1914 NTSTATUS CDROM_DeviceIoControl(HANDLE hDevice,
1915 HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
1916 PVOID UserApcContext,
1917 PIO_STATUS_BLOCK piosb,
1918 ULONG dwIoControlCode,
1919 LPVOID lpInBuffer, DWORD nInBufferSize,
1920 LPVOID lpOutBuffer, DWORD nOutBufferSize)
1923 NTSTATUS status = STATUS_SUCCESS;
1926 TRACE("%lx %s %lx %ld %lx %ld %p\n",
1927 (DWORD)hDevice, iocodex(dwIoControlCode), (DWORD)lpInBuffer, nInBufferSize,
1928 (DWORD)lpOutBuffer, nOutBufferSize, piosb);
1930 piosb->Information = 0;
1932 if ((status = wine_server_handle_to_fd( hDevice, 0, &fd, NULL ))) goto error;
1933 if ((status = CDROM_Open(fd, &dev)))
1935 wine_server_release_fd( hDevice, fd );
1939 switch (dwIoControlCode)
1941 case IOCTL_STORAGE_CHECK_VERIFY:
1942 case IOCTL_CDROM_CHECK_VERIFY:
1944 CDROM_ClearCacheEntry(dev);
1945 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
1946 status = STATUS_INVALID_PARAMETER;
1947 else status = CDROM_Verify(dev, fd);
1950 /* EPP case IOCTL_STORAGE_CHECK_VERIFY2: */
1952 /* EPP case IOCTL_STORAGE_FIND_NEW_DEVICES: */
1953 /* EPP case IOCTL_CDROM_FIND_NEW_DEVICES: */
1955 case IOCTL_STORAGE_LOAD_MEDIA:
1956 case IOCTL_CDROM_LOAD_MEDIA:
1958 CDROM_ClearCacheEntry(dev);
1959 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
1960 status = STATUS_INVALID_PARAMETER;
1961 else status = CDROM_SetTray(fd, FALSE);
1963 case IOCTL_STORAGE_EJECT_MEDIA:
1965 CDROM_ClearCacheEntry(dev);
1966 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
1967 status = STATUS_INVALID_PARAMETER;
1968 else status = CDROM_SetTray(fd, TRUE);
1971 case IOCTL_CDROM_MEDIA_REMOVAL:
1972 case IOCTL_DISK_MEDIA_REMOVAL:
1973 case IOCTL_STORAGE_MEDIA_REMOVAL:
1974 case IOCTL_STORAGE_EJECTION_CONTROL:
1975 /* FIXME the last ioctl:s is not the same as the two others...
1976 * lockcount/owner should be handled */
1978 CDROM_ClearCacheEntry(dev);
1979 if (lpOutBuffer != NULL || nOutBufferSize != 0) status = STATUS_INVALID_PARAMETER;
1980 else if (nInBufferSize < sizeof(PREVENT_MEDIA_REMOVAL)) status = STATUS_BUFFER_TOO_SMALL;
1981 else status = CDROM_ControlEjection(fd, (const PREVENT_MEDIA_REMOVAL*)lpInBuffer);
1984 /* EPP case IOCTL_STORAGE_GET_MEDIA_TYPES: */
1986 case IOCTL_STORAGE_GET_DEVICE_NUMBER:
1987 sz = sizeof(STORAGE_DEVICE_NUMBER);
1988 if (lpInBuffer != NULL || nInBufferSize != 0) status = STATUS_INVALID_PARAMETER;
1989 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
1990 else status = CDROM_GetDeviceNumber(dev, (STORAGE_DEVICE_NUMBER*)lpOutBuffer);
1993 case IOCTL_STORAGE_RESET_DEVICE:
1995 CDROM_ClearCacheEntry(dev);
1996 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
1997 status = STATUS_INVALID_PARAMETER;
1998 else status = CDROM_ResetAudio(fd);
2001 case IOCTL_CDROM_GET_CONTROL:
2002 sz = sizeof(CDROM_AUDIO_CONTROL);
2003 if (lpInBuffer != NULL || nInBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2004 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2005 else status = CDROM_GetControl(dev, (CDROM_AUDIO_CONTROL*)lpOutBuffer);
2008 case IOCTL_CDROM_GET_DRIVE_GEOMETRY:
2009 sz = sizeof(DISK_GEOMETRY);
2010 if (lpInBuffer != NULL || nInBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2011 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2012 else status = CDROM_GetDriveGeometry(dev, fd, (DISK_GEOMETRY*)lpOutBuffer);
2015 case IOCTL_CDROM_DISK_TYPE:
2016 sz = sizeof(CDROM_DISK_DATA);
2017 /* CDROM_ClearCacheEntry(dev); */
2018 if (lpInBuffer != NULL || nInBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2019 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2020 else status = CDROM_GetDiskData(dev, fd, (CDROM_DISK_DATA*)lpOutBuffer);
2023 /* EPP case IOCTL_CDROM_GET_LAST_SESSION: */
2025 case IOCTL_CDROM_READ_Q_CHANNEL:
2026 sz = sizeof(SUB_Q_CHANNEL_DATA);
2027 if (lpInBuffer == NULL || nInBufferSize < sizeof(CDROM_SUB_Q_DATA_FORMAT))
2028 status = STATUS_INVALID_PARAMETER;
2029 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2030 else status = CDROM_ReadQChannel(dev, fd, (const CDROM_SUB_Q_DATA_FORMAT*)lpInBuffer,
2031 (SUB_Q_CHANNEL_DATA*)lpOutBuffer);
2034 case IOCTL_CDROM_READ_TOC:
2035 sz = sizeof(CDROM_TOC);
2036 if (lpInBuffer != NULL || nInBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2037 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2038 else status = CDROM_ReadTOC(dev, fd, (CDROM_TOC*)lpOutBuffer);
2041 /* EPP case IOCTL_CDROM_READ_TOC_EX: */
2043 case IOCTL_CDROM_PAUSE_AUDIO:
2045 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
2046 status = STATUS_INVALID_PARAMETER;
2047 else status = CDROM_PauseAudio(fd);
2049 case IOCTL_CDROM_PLAY_AUDIO_MSF:
2051 if (lpOutBuffer != NULL || nOutBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2052 else if (nInBufferSize < sizeof(CDROM_PLAY_AUDIO_MSF)) status = STATUS_BUFFER_TOO_SMALL;
2053 else status = CDROM_PlayAudioMSF(fd, (const CDROM_PLAY_AUDIO_MSF*)lpInBuffer);
2055 case IOCTL_CDROM_RESUME_AUDIO:
2057 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
2058 status = STATUS_INVALID_PARAMETER;
2059 else status = CDROM_ResumeAudio(fd);
2061 case IOCTL_CDROM_SEEK_AUDIO_MSF:
2063 if (lpOutBuffer != NULL || nOutBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2064 else if (nInBufferSize < sizeof(CDROM_SEEK_AUDIO_MSF)) status = STATUS_BUFFER_TOO_SMALL;
2065 else status = CDROM_SeekAudioMSF(dev, fd, (const CDROM_SEEK_AUDIO_MSF*)lpInBuffer);
2067 case IOCTL_CDROM_STOP_AUDIO:
2069 CDROM_ClearCacheEntry(dev); /* Maybe intention is to change media */
2070 if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
2071 status = STATUS_INVALID_PARAMETER;
2072 else status = CDROM_StopAudio(fd);
2074 case IOCTL_CDROM_GET_VOLUME:
2075 sz = sizeof(VOLUME_CONTROL);
2076 if (lpInBuffer != NULL || nInBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2077 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2078 else status = CDROM_GetVolume(fd, (VOLUME_CONTROL*)lpOutBuffer);
2080 case IOCTL_CDROM_SET_VOLUME:
2082 CDROM_ClearCacheEntry(dev);
2083 if (lpInBuffer == NULL || nInBufferSize < sizeof(VOLUME_CONTROL) || lpOutBuffer != NULL)
2084 status = STATUS_INVALID_PARAMETER;
2085 else status = CDROM_SetVolume(fd, (const VOLUME_CONTROL*)lpInBuffer);
2087 case IOCTL_CDROM_RAW_READ:
2089 if (nInBufferSize < sizeof(RAW_READ_INFO)) status = STATUS_INVALID_PARAMETER;
2090 else if (lpOutBuffer == NULL) status = STATUS_BUFFER_TOO_SMALL;
2091 else status = CDROM_RawRead(fd, (const RAW_READ_INFO*)lpInBuffer,
2092 lpOutBuffer, nOutBufferSize, &sz);
2094 case IOCTL_SCSI_GET_ADDRESS:
2095 sz = sizeof(SCSI_ADDRESS);
2096 if (lpInBuffer != NULL || nInBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2097 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2098 else status = CDROM_GetAddress(fd, (SCSI_ADDRESS*)lpOutBuffer);
2100 case IOCTL_SCSI_PASS_THROUGH_DIRECT:
2101 sz = sizeof(SCSI_PASS_THROUGH_DIRECT);
2102 if (lpOutBuffer == NULL) status = STATUS_INVALID_PARAMETER;
2103 else if (nOutBufferSize < sizeof(SCSI_PASS_THROUGH_DIRECT)) status = STATUS_BUFFER_TOO_SMALL;
2104 else status = CDROM_ScsiPassThroughDirect(fd, (PSCSI_PASS_THROUGH_DIRECT)lpOutBuffer);
2106 case IOCTL_SCSI_PASS_THROUGH:
2107 sz = sizeof(SCSI_PASS_THROUGH);
2108 if (lpOutBuffer == NULL) status = STATUS_INVALID_PARAMETER;
2109 else if (nOutBufferSize < sizeof(SCSI_PASS_THROUGH)) status = STATUS_BUFFER_TOO_SMALL;
2110 else status = CDROM_ScsiPassThrough(fd, (PSCSI_PASS_THROUGH)lpOutBuffer);
2112 case IOCTL_SCSI_GET_CAPABILITIES:
2113 sz = sizeof(IO_SCSI_CAPABILITIES);
2114 if (lpOutBuffer == NULL) status = STATUS_INVALID_PARAMETER;
2115 else if (nOutBufferSize < sizeof(IO_SCSI_CAPABILITIES)) status = STATUS_BUFFER_TOO_SMALL;
2116 else status = CDROM_ScsiGetCaps((PIO_SCSI_CAPABILITIES)lpOutBuffer);
2118 case IOCTL_DVD_START_SESSION:
2119 sz = sizeof(DVD_SESSION_ID);
2120 if (lpOutBuffer == NULL) status = STATUS_INVALID_PARAMETER;
2121 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2124 TRACE("before in 0x%08lx out 0x%08lx\n",(lpInBuffer)?*(PDVD_SESSION_ID)lpInBuffer:0,
2125 *(PDVD_SESSION_ID)lpOutBuffer);
2126 status = DVD_StartSession(fd, (PDVD_SESSION_ID)lpInBuffer, (PDVD_SESSION_ID)lpOutBuffer);
2127 TRACE("before in 0x%08lx out 0x%08lx\n",(lpInBuffer)?*(PDVD_SESSION_ID)lpInBuffer:0,
2128 *(PDVD_SESSION_ID)lpOutBuffer);
2131 case IOCTL_DVD_END_SESSION:
2132 sz = sizeof(DVD_SESSION_ID);
2133 if ((lpInBuffer == NULL) || (nInBufferSize < sz))status = STATUS_INVALID_PARAMETER;
2134 else status = DVD_EndSession(fd, (PDVD_SESSION_ID)lpInBuffer);
2136 case IOCTL_DVD_SEND_KEY:
2139 (((PDVD_COPY_PROTECT_KEY)lpInBuffer)->KeyLength != nInBufferSize))
2140 status = STATUS_INVALID_PARAMETER;
2143 TRACE("doing DVD_SendKey\n");
2144 status = DVD_SendKey(fd, (PDVD_COPY_PROTECT_KEY)lpInBuffer);
2147 case IOCTL_DVD_READ_KEY:
2149 (((PDVD_COPY_PROTECT_KEY)lpInBuffer)->KeyLength != nInBufferSize))
2150 status = STATUS_INVALID_PARAMETER;
2151 else if (lpInBuffer !=lpOutBuffer) status = STATUS_BUFFER_TOO_SMALL;
2154 TRACE("doing DVD_READ_KEY\n");
2155 sz = ((PDVD_COPY_PROTECT_KEY)lpInBuffer)->KeyLength;
2156 status = DVD_ReadKey(fd, (PDVD_COPY_PROTECT_KEY)lpInBuffer);
2159 case IOCTL_DVD_GET_REGION:
2160 sz = sizeof(DVD_REGION);
2161 if (lpInBuffer != NULL || nInBufferSize != 0) status = STATUS_INVALID_PARAMETER;
2162 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2163 TRACE("doing DVD_Get_REGION\n");
2164 status = DVD_GetRegion(fd, (PDVD_REGION)lpOutBuffer);
2166 case IOCTL_DVD_READ_STRUCTURE:
2167 sz = sizeof(DVD_LAYER_DESCRIPTOR);
2168 if (lpInBuffer == NULL || nInBufferSize != sizeof(DVD_READ_STRUCTURE)) status = STATUS_INVALID_PARAMETER;
2169 else if (nOutBufferSize < sz) status = STATUS_BUFFER_TOO_SMALL;
2170 TRACE("doing DVD_READ_STRUCTURE\n");
2171 status = DVD_ReadStructure(fd, (PDVD_READ_STRUCTURE)lpInBuffer, (PDVD_LAYER_DESCRIPTOR)lpOutBuffer);
2175 FIXME("Unsupported IOCTL %lx (type=%lx access=%lx func=%lx meth=%lx)\n",
2176 dwIoControlCode, dwIoControlCode >> 16, (dwIoControlCode >> 14) & 3,
2177 (dwIoControlCode >> 2) & 0xFFF, dwIoControlCode & 3);
2179 status = STATUS_INVALID_PARAMETER;
2182 wine_server_release_fd( hDevice, fd );
2184 piosb->u.Status = status;
2185 piosb->Information = sz;
2186 if (hEvent) NtSetEvent(hEvent, NULL);