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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/port.h"
38 #ifdef HAVE_SYS_STAT_H
39 # include <sys/stat.h>
42 # include <sys/mkdev.h>
43 #elif defined(MAJOR_IN_SYSMACROS)
44 # include <sys/sysmacros.h>
46 #include <sys/types.h>
48 #ifdef HAVE_SYS_IOCTL_H
49 #include <sys/ioctl.h>
54 #ifdef HAVE_SCSI_SCSI_H
55 # include <scsi/scsi.h>
56 # undef REASSIGN_BLOCKS /* avoid conflict with winioctl.h */
57 # undef FAILED /* avoid conflict with winerror.h */
59 #ifdef HAVE_SCSI_SCSI_IOCTL_H
60 # include <scsi/scsi_ioctl.h>
62 #ifdef HAVE_LINUX_MAJOR_H
63 # include <linux/major.h>
65 #ifdef HAVE_LINUX_HDREG_H
66 # include <linux/hdreg.h>
68 #ifdef HAVE_LINUX_PARAM_H
69 # include <linux/param.h>
71 #ifdef HAVE_LINUX_CDROM_H
72 # include <linux/cdrom.h>
74 #ifdef HAVE_LINUX_UCDROM_H
75 # include <linux/ucdrom.h>
77 #ifdef HAVE_SYS_CDIO_H
78 # include <sys/cdio.h>
80 #ifdef HAVE_SYS_SCSIIO_H
81 # include <sys/scsiio.h>
84 #ifdef HAVE_IOKIT_IOKITLIB_H
85 # include <libkern/OSByteOrder.h>
86 # include <sys/disk.h>
87 # include <IOKit/IOKitLib.h>
88 # include <IOKit/storage/IOMedia.h>
89 # include <IOKit/storage/IOCDMediaBSDClient.h>
90 # include <IOKit/storage/IODVDMediaBSDClient.h>
91 # include <IOKit/scsi/SCSITask.h>
92 # include <IOKit/scsi/SCSICmds_REQUEST_SENSE_Defs.h>
93 # define SENSEBUFLEN kSenseDefaultSize
103 uint8_t reserved0144
[2];
117 } dk_scsi_identify_t
;
119 #define DKIOCSCSICOMMAND _IOWR('d', 253, dk_scsi_command_t)
120 #define DKIOCSCSIIDENTIFY _IOR('d', 254, dk_scsi_identify_t)
124 #include "ntstatus.h"
125 #define WIN32_NO_STATUS
126 #define NONAMELESSUNION
128 #include "winternl.h"
129 #include "winioctl.h"
130 #include "ntddstor.h"
131 #include "ntddcdrm.h"
132 #include "ddk/ntddcdvd.h"
133 #include "ntddscsi.h"
134 #include "ntdll_misc.h"
135 #include "wine/server.h"
136 #include "wine/library.h"
137 #include "wine/debug.h"
139 WINE_DEFAULT_DEBUG_CHANNEL(cdrom
);
141 /* Non-Linux systems do not have linux/cdrom.h and the like, and thus
142 lack the following constants. */
145 # define CD_SECS 60 /* seconds per minute */
148 # define CD_FRAMES 75 /* frames per second */
151 #ifdef WORDS_BIGENDIAN
152 #define GET_BE_DWORD(x) (x)
154 #define GET_BE_DWORD(x) RtlUlongByteSwap(x)
157 static const struct iocodexs
162 #define X(x) { x, #x },
163 X(IOCTL_CDROM_CHECK_VERIFY
)
164 X(IOCTL_CDROM_CURRENT_POSITION
)
165 X(IOCTL_CDROM_DISK_TYPE
)
166 X(IOCTL_CDROM_GET_CONTROL
)
167 X(IOCTL_CDROM_GET_DRIVE_GEOMETRY
)
168 X(IOCTL_CDROM_GET_VOLUME
)
169 X(IOCTL_CDROM_LOAD_MEDIA
)
170 X(IOCTL_CDROM_MEDIA_CATALOG
)
171 X(IOCTL_CDROM_MEDIA_REMOVAL
)
172 X(IOCTL_CDROM_PAUSE_AUDIO
)
173 X(IOCTL_CDROM_PLAY_AUDIO_MSF
)
174 X(IOCTL_CDROM_RAW_READ
)
175 X(IOCTL_CDROM_READ_Q_CHANNEL
)
176 X(IOCTL_CDROM_READ_TOC
)
177 X(IOCTL_CDROM_RESUME_AUDIO
)
178 X(IOCTL_CDROM_SEEK_AUDIO_MSF
)
179 X(IOCTL_CDROM_SET_VOLUME
)
180 X(IOCTL_CDROM_STOP_AUDIO
)
181 X(IOCTL_CDROM_TRACK_ISRC
)
182 X(IOCTL_DISK_GET_MEDIA_TYPES
)
183 X(IOCTL_DISK_MEDIA_REMOVAL
)
184 X(IOCTL_DVD_END_SESSION
)
185 X(IOCTL_DVD_GET_REGION
)
186 X(IOCTL_DVD_READ_KEY
)
187 X(IOCTL_DVD_READ_STRUCTURE
)
188 X(IOCTL_DVD_SEND_KEY
)
189 X(IOCTL_DVD_START_SESSION
)
190 X(IOCTL_SCSI_GET_ADDRESS
)
191 X(IOCTL_SCSI_GET_CAPABILITIES
)
192 X(IOCTL_SCSI_GET_INQUIRY_DATA
)
193 X(IOCTL_SCSI_PASS_THROUGH
)
194 X(IOCTL_SCSI_PASS_THROUGH_DIRECT
)
195 X(IOCTL_STORAGE_CHECK_VERIFY
)
196 X(IOCTL_STORAGE_CHECK_VERIFY2
)
197 X(IOCTL_STORAGE_EJECTION_CONTROL
)
198 X(IOCTL_STORAGE_EJECT_MEDIA
)
199 X(IOCTL_STORAGE_GET_DEVICE_NUMBER
)
200 X(IOCTL_STORAGE_GET_MEDIA_TYPES
)
201 X(IOCTL_STORAGE_GET_MEDIA_TYPES_EX
)
202 X(IOCTL_STORAGE_LOAD_MEDIA
)
203 X(IOCTL_STORAGE_MEDIA_REMOVAL
)
204 X(IOCTL_STORAGE_RESET_DEVICE
)
207 static const char *iocodex(DWORD code
)
210 static char buffer
[25];
211 for(i
=0; i
<sizeof(iocodextable
)/sizeof(struct iocodexs
); i
++)
212 if (code
==iocodextable
[i
].code
)
213 return iocodextable
[i
].codex
;
214 sprintf(buffer
, "IOCTL_CODE_%x", (int)code
);
218 #define INQ_REPLY_LEN 36
219 #define INQ_CMD_LEN 6
221 #define FRAME_OF_ADDR(a) (((int)(a)[1] * CD_SECS + (a)[2]) * CD_FRAMES + (a)[3])
222 #define FRAME_OF_MSF(a) (((int)(a).M * CD_SECS + (a).S) * CD_FRAMES + (a).F)
223 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
224 #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;}
226 /* The documented format of DVD_LAYER_DESCRIPTOR is wrong. Even the format in the
227 * DDK's header is wrong. There are four bytes at the start defined by
228 * MMC-5. The first two are the size of the structure in big-endian order as
229 * defined by MMC-5. The other two are reserved.
233 DVD_DESCRIPTOR_HEADER Header
;
234 DVD_LAYER_DESCRIPTOR Descriptor
;
236 } internal_dvd_layer_descriptor
;
237 C_ASSERT(sizeof(internal_dvd_layer_descriptor
) == 22);
241 DVD_DESCRIPTOR_HEADER Header
;
242 DVD_MANUFACTURER_DESCRIPTOR Descriptor
;
244 } internal_dvd_manufacturer_descriptor
;
245 C_ASSERT(sizeof(internal_dvd_manufacturer_descriptor
) == 2053);
247 static NTSTATUS
CDROM_ReadTOC(int, int, CDROM_TOC
*);
248 static NTSTATUS
CDROM_GetStatusCode(int);
254 # define IDE6_MAJOR 88
257 # define IDE7_MAJOR 89
260 # ifdef CDROM_SEND_PACKET
261 /* structure for CDROM_PACKET_COMMAND ioctl */
262 /* not all Linux versions have all the fields, so we define the
263 * structure ourselves to make sure */
264 struct linux_cdrom_generic_command
266 unsigned char cmd
[CDROM_PACKET_SIZE
];
267 unsigned char *buffer
;
270 struct request_sense
*sense
;
271 unsigned char data_direction
;
276 # endif /* CDROM_SEND_PACKET */
280 /* FIXME: this is needed because we can't open simultaneously several times /dev/cdrom
281 * this should be removed when a proper device interface is implemented
283 * (WS) We need this to keep track of current position and to safely
284 * detect media changes. Besides this should provide a great speed up
290 char toc_good
; /* if false, will reread TOC from disk */
292 SUB_Q_CURRENT_POSITION CurrentPosition
;
294 /* who has more than 5 cdroms on his/her machine ?? */
295 /* FIXME: this should grow depending on the number of cdroms we install/configure
298 #define MAX_CACHE_ENTRIES 5
299 static struct cdrom_cache cdrom_cache
[MAX_CACHE_ENTRIES
];
301 static RTL_CRITICAL_SECTION cache_section
;
302 static RTL_CRITICAL_SECTION_DEBUG critsect_debug
=
304 0, 0, &cache_section
,
305 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
306 0, 0, { (DWORD_PTR
)(__FILE__
": cache_section") }
308 static RTL_CRITICAL_SECTION cache_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
310 /* Proposed media change function: not really needed at this time */
311 /* This is a 1 or 0 type of function */
313 static int CDROM_MediaChanged(int dev
)
317 struct cdrom_tochdr hdr
;
318 struct cdrom_tocentry entry
;
320 if (dev
< 0 || dev
>= MAX_CACHE_ENTRIES
)
322 if ( ioctl(cdrom_cache
[dev
].fd
, CDROMREADTOCHDR
, &hdr
) == -1 )
325 if ( memcmp(&hdr
, &cdrom_cache
[dev
].hdr
, sizeof(struct cdrom_tochdr
)) )
328 for (i
=hdr
.cdth_trk0
; i
<=hdr
.cdth_trk1
+1; i
++)
330 if (i
== hdr
.cdth_trk1
+ 1)
332 entry
.cdte_track
= CDROM_LEADOUT
;
334 entry
.cdte_track
= i
;
336 entry
.cdte_format
= CDROM_MSF
;
337 if ( ioctl(cdrom_cache
[dev
].fd
, CDROMREADTOCENTRY
, &entry
) == -1)
339 if ( memcmp(&entry
, cdrom_cache
[dev
].entry
+i
-hdr
.cdth_trk0
,
340 sizeof(struct cdrom_tocentry
)) )
348 /******************************************************************
351 * On Mac OS, get the device for the whole disk from a fd that points to a partition.
352 * This is ugly and inefficient, but we have no choice since the partition fd doesn't
353 * support the eject ioctl.
356 static NTSTATUS
get_parent_device( int fd
, char *name
, size_t len
)
358 NTSTATUS status
= STATUS_NO_SUCH_FILE
;
361 io_service_t service
;
362 CFMutableDictionaryRef dict
;
365 if (fstat( fd
, &st
) == -1) return FILE_GetNtStatus();
366 if (!S_ISCHR( st
.st_mode
)) return STATUS_OBJECT_TYPE_MISMATCH
;
368 /* create a dictionary with the right major/minor numbers */
370 if (!(dict
= IOServiceMatching( kIOMediaClass
))) return STATUS_NO_MEMORY
;
372 i
= major( st
.st_rdev
);
373 val
= CFNumberCreate( NULL
, kCFNumberIntType
, &i
);
374 CFDictionaryAddValue( dict
, CFSTR( "BSD Major" ), val
);
377 i
= minor( st
.st_rdev
);
378 val
= CFNumberCreate( NULL
, kCFNumberIntType
, &i
);
379 CFDictionaryAddValue( dict
, CFSTR( "BSD Minor" ), val
);
382 CFDictionaryAddValue( dict
, CFSTR("Removable"), kCFBooleanTrue
);
384 service
= IOServiceGetMatchingService( kIOMasterPortDefault
, dict
);
386 /* now look for the parent that has the "Whole" attribute set to TRUE */
390 io_service_t parent
= 0;
395 if (!IOObjectConformsTo( service
, kIOMediaClass
))
397 if (!(whole
= IORegistryEntryCreateCFProperty( service
, CFSTR("Whole"), NULL
, 0 )))
399 ok
= (whole
== kCFBooleanTrue
);
403 if ((str
= IORegistryEntryCreateCFProperty( service
, CFSTR("BSD Name"), NULL
, 0 )))
405 strcpy( name
, "/dev/r" );
406 CFStringGetCString( str
, name
+ 6, len
- 6, kCFStringEncodingUTF8
);
408 status
= STATUS_SUCCESS
;
410 IOObjectRelease( service
);
414 IORegistryEntryGetParentEntry( service
, kIOServicePlane
, &parent
);
415 IOObjectRelease( service
);
423 /******************************************************************
424 * CDROM_SyncCache [internal]
426 * Read the TOC in and store it in the cdrom_cache structure.
427 * Further requests for the TOC will be copied from the cache
428 * unless certain events like disk ejection is detected, in which
429 * case the cache will be cleared, causing it to be resynced.
430 * The cache section must be held by caller.
432 static NTSTATUS
CDROM_SyncCache(int dev
, int fd
)
436 struct cdrom_tochdr hdr
;
437 struct cdrom_tocentry entry
;
439 CDROM_TOC
*toc
= &cdrom_cache
[dev
].toc
;
440 cdrom_cache
[dev
].toc_good
= 0;
442 if (ioctl(fd
, CDROMREADTOCHDR
, &hdr
) == -1)
444 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
445 return FILE_GetNtStatus();
448 toc
->FirstTrack
= hdr
.cdth_trk0
;
449 toc
->LastTrack
= hdr
.cdth_trk1
;
450 tsz
= sizeof(toc
->FirstTrack
) + sizeof(toc
->LastTrack
)
451 + sizeof(TRACK_DATA
) * (toc
->LastTrack
-toc
->FirstTrack
+2);
452 toc
->Length
[0] = tsz
>> 8;
453 toc
->Length
[1] = tsz
;
455 TRACE("caching toc from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
457 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
459 if (i
== toc
->LastTrack
+ 1)
460 entry
.cdte_track
= CDROM_LEADOUT
;
462 entry
.cdte_track
= i
;
463 entry
.cdte_format
= CDROM_MSF
;
464 if (ioctl(fd
, CDROMREADTOCENTRY
, &entry
) == -1)
466 WARN("error read entry (%s)\n", strerror(errno
));
467 return FILE_GetNtStatus();
469 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= entry
.cdte_ctrl
;
470 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= entry
.cdte_adr
;
471 /* marking last track with leadout value as index */
472 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.cdte_track
;
473 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
474 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = entry
.cdte_addr
.msf
.minute
;
475 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = entry
.cdte_addr
.msf
.second
;
476 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = entry
.cdte_addr
.msf
.frame
;
478 cdrom_cache
[dev
].toc_good
= 1;
479 return STATUS_SUCCESS
;
481 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
484 struct ioc_toc_header hdr
;
485 struct ioc_read_toc_entry entry
;
486 struct cd_toc_entry toc_buffer
;
488 CDROM_TOC
*toc
= &cdrom_cache
[dev
].toc
;
489 cdrom_cache
[dev
].toc_good
= 0;
491 if (ioctl(fd
, CDIOREADTOCHEADER
, &hdr
) == -1)
493 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
494 return FILE_GetNtStatus();
496 toc
->FirstTrack
= hdr
.starting_track
;
497 toc
->LastTrack
= hdr
.ending_track
;
498 tsz
= sizeof(toc
->FirstTrack
) + sizeof(toc
->LastTrack
)
499 + sizeof(TRACK_DATA
) * (toc
->LastTrack
-toc
->FirstTrack
+2);
500 toc
->Length
[0] = tsz
>> 8;
501 toc
->Length
[1] = tsz
;
503 TRACE("caching toc from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
505 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
507 if (i
== toc
->LastTrack
+ 1)
510 entry
.starting_track
= LEADOUT
;
512 entry
.starting_track
= i
;
514 memset(&toc_buffer
, 0, sizeof(toc_buffer
));
515 entry
.address_format
= CD_MSF_FORMAT
;
516 entry
.data_len
= sizeof(toc_buffer
);
517 entry
.data
= &toc_buffer
;
518 if (ioctl(fd
, CDIOREADTOCENTRYS
, &entry
) == -1)
520 WARN("error read entry (%s)\n", strerror(errno
));
521 return FILE_GetNtStatus();
523 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= toc_buffer
.control
;
524 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= toc_buffer
.addr_type
;
525 /* marking last track with leadout value as index */
526 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.starting_track
;
527 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
528 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = toc_buffer
.addr
.msf
.minute
;
529 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = toc_buffer
.addr
.msf
.second
;
530 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = toc_buffer
.addr
.msf
.frame
;
532 cdrom_cache
[dev
].toc_good
= 1;
533 return STATUS_SUCCESS
;
535 #elif defined(__APPLE__)
537 dk_cd_read_toc_t hdr
;
538 CDROM_TOC
*toc
= &cdrom_cache
[dev
].toc
;
539 cdrom_cache
[dev
].toc_good
= 0;
541 memset( &hdr
, 0, sizeof(hdr
) );
543 hdr
.bufferLength
= sizeof(*toc
);
544 if (ioctl(fd
, DKIOCCDREADTOC
, &hdr
) == -1)
546 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
547 return FILE_GetNtStatus();
549 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
551 /* convert address format */
552 TRACK_DATA
*data
= &toc
->TrackData
[i
- toc
->FirstTrack
];
553 DWORD frame
= (((DWORD
)data
->Address
[0] << 24) | ((DWORD
)data
->Address
[1] << 16) |
554 ((DWORD
)data
->Address
[2] << 8) | data
->Address
[3]);
555 MSF_OF_FRAME( data
->Address
[1], frame
);
556 data
->Address
[0] = 0;
559 cdrom_cache
[dev
].toc_good
= 1;
560 return STATUS_SUCCESS
;
562 FIXME("not supported on this O/S\n");
563 return STATUS_NOT_SUPPORTED
;
567 static void CDROM_ClearCacheEntry(int dev
)
569 RtlEnterCriticalSection( &cache_section
);
570 cdrom_cache
[dev
].toc_good
= 0;
571 RtlLeaveCriticalSection( &cache_section
);
576 /******************************************************************
577 * CDROM_GetInterfaceInfo
579 * Determines the ide interface (the number after the ide), and the
580 * number of the device on that interface for ide cdroms (*iface <= 1).
581 * Determines the scsi information for scsi cdroms (*iface >= 2).
582 * Returns FALSE if the info cannot not be obtained.
584 static BOOL
CDROM_GetInterfaceInfo(int fd
, UCHAR
* iface
, UCHAR
* port
, UCHAR
* device
, UCHAR
* lun
)
588 if ( fstat(fd
, &st
) == -1 || ! S_ISBLK(st
.st_mode
)) return FALSE
;
593 switch (major(st
.st_rdev
)) {
594 case IDE0_MAJOR
: *iface
= 0; break;
595 case IDE1_MAJOR
: *iface
= 1; break;
596 case IDE2_MAJOR
: *iface
= 2; break;
597 case IDE3_MAJOR
: *iface
= 3; break;
598 case IDE4_MAJOR
: *iface
= 4; break;
599 case IDE5_MAJOR
: *iface
= 5; break;
600 case IDE6_MAJOR
: *iface
= 6; break;
601 case IDE7_MAJOR
: *iface
= 7; break;
602 default: *port
= 1; break;
606 *device
= (minor(st
.st_rdev
) >> 6);
609 #ifdef SCSI_IOCTL_GET_IDLUN
611 if (ioctl(fd
, SCSI_IOCTL_GET_IDLUN
, idlun
) != -1)
613 *port
= (idlun
[0] >> 24) & 0xff;
614 *iface
= ((idlun
[0] >> 16) & 0xff) + 2;
615 *device
= idlun
[0] & 0xff;
616 *lun
= (idlun
[0] >> 8) & 0xff;
621 WARN("CD-ROM device (%d, %d) not supported\n", major(st
.st_rdev
), minor(st
.st_rdev
));
626 #elif defined(__NetBSD__)
627 struct scsi_addr addr
;
628 if (ioctl(fd
, SCIOCIDENTIFY
, &addr
) != -1)
634 *iface
= addr
.addr
.scsi
.scbus
;
635 *device
= addr
.addr
.scsi
.target
;
636 *lun
= addr
.addr
.scsi
.lun
;
640 *iface
= addr
.addr
.atapi
.atbus
;
641 *device
= addr
.addr
.atapi
.drive
;
647 #elif defined(__APPLE__)
648 dk_scsi_identify_t addr
;
649 if (ioctl(fd
, DKIOCSCSIIDENTIFY
, &addr
) != -1)
653 *device
= addr
.target
;
659 FIXME("not implemented on this O/S\n");
665 /******************************************************************
669 static NTSTATUS
CDROM_Open(int fd
, int* dev
)
672 NTSTATUS ret
= STATUS_SUCCESS
;
675 if (fstat(fd
, &st
) == -1) return FILE_GetNtStatus();
677 RtlEnterCriticalSection( &cache_section
);
678 for (*dev
= 0; *dev
< MAX_CACHE_ENTRIES
; (*dev
)++)
681 cdrom_cache
[*dev
].device
== 0 &&
682 cdrom_cache
[*dev
].inode
== 0)
684 else if (cdrom_cache
[*dev
].device
== st
.st_dev
&&
685 cdrom_cache
[*dev
].inode
== st
.st_ino
)
688 if (*dev
== MAX_CACHE_ENTRIES
)
690 if (empty
== -1) ret
= STATUS_NOT_IMPLEMENTED
;
694 cdrom_cache
[*dev
].device
= st
.st_dev
;
695 cdrom_cache
[*dev
].inode
= st
.st_ino
;
698 RtlLeaveCriticalSection( &cache_section
);
700 TRACE("%d, %d\n", *dev
, fd
);
704 /******************************************************************
705 * CDROM_GetStatusCode
709 static NTSTATUS
CDROM_GetStatusCode(int io
)
711 if (io
== 0) return STATUS_SUCCESS
;
712 return FILE_GetNtStatus();
715 /******************************************************************
719 static NTSTATUS
CDROM_GetControl(int dev
, int fd
, CDROM_AUDIO_CONTROL
* cac
)
723 int io
= ioctl( fd
, DKIOCCDGETSPEED
, &speed
);
724 if (io
!= 0) return CDROM_GetStatusCode( io
);
725 /* DKIOCCDGETSPEED returns the speed in kilobytes per second,
726 * so convert to logical blocks (assumed to be ~2 KB).
728 cac
->LogicalBlocksPerSecond
= speed
/2;
730 cac
->LogicalBlocksPerSecond
= 1; /* FIXME */
732 cac
->LbaFormat
= 0; /* FIXME */
733 return STATUS_NOT_SUPPORTED
;
736 /******************************************************************
737 * CDROM_GetDeviceNumber
740 static NTSTATUS
CDROM_GetDeviceNumber(int dev
, STORAGE_DEVICE_NUMBER
* devnum
)
743 devnum
->DeviceType
= FILE_DEVICE_DISK
;
744 devnum
->DeviceNumber
= 1;
745 devnum
->PartitionNumber
= 1;
746 return STATUS_SUCCESS
;
749 /******************************************************************
750 * CDROM_GetDriveGeometry
753 static NTSTATUS
CDROM_GetDriveGeometry(int dev
, int fd
, DISK_GEOMETRY
* dg
)
759 if ((ret
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return ret
;
761 fsize
= FRAME_OF_TOC(toc
, toc
.LastTrack
+1)
762 - FRAME_OF_TOC(toc
, 1); /* Total size in frames */
764 dg
->Cylinders
.QuadPart
= fsize
/ (64 * 32);
765 dg
->MediaType
= RemovableMedia
;
766 dg
->TracksPerCylinder
= 64;
767 dg
->SectorsPerTrack
= 32;
768 dg
->BytesPerSector
= 2048;
772 /******************************************************************
776 static NTSTATUS
CDROM_GetMediaType(int dev
, GET_MEDIA_TYPES
* medtype
)
778 FIXME(": faking success\n");
779 medtype
->DeviceType
= FILE_DEVICE_CD_ROM
;
780 medtype
->MediaInfoCount
= 0;
781 return STATUS_SUCCESS
;
784 /**************************************************************************
785 * CDROM_Reset [internal]
787 static NTSTATUS
CDROM_ResetAudio(int fd
)
790 return CDROM_GetStatusCode(ioctl(fd
, CDROMRESET
));
791 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
792 return CDROM_GetStatusCode(ioctl(fd
, CDIOCRESET
, NULL
));
794 FIXME("not supported on this O/S\n");
795 return STATUS_NOT_SUPPORTED
;
799 /******************************************************************
804 static NTSTATUS
CDROM_SetTray(int fd
, BOOL doEject
)
807 return CDROM_GetStatusCode(ioctl(fd
, doEject
? CDROMEJECT
: CDROMCLOSETRAY
));
808 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
809 return CDROM_GetStatusCode((ioctl(fd
, CDIOCALLOW
, NULL
)) ||
810 (ioctl(fd
, doEject
? CDIOCEJECT
: CDIOCCLOSE
, NULL
)) ||
811 (ioctl(fd
, CDIOCPREVENT
, NULL
)));
812 #elif defined(__APPLE__)
813 if (doEject
) return CDROM_GetStatusCode( ioctl( fd
, DKIOCEJECT
, NULL
) );
814 else return STATUS_NOT_SUPPORTED
;
816 FIXME("not supported on this O/S\n");
817 return STATUS_NOT_SUPPORTED
;
821 /******************************************************************
822 * CDROM_ControlEjection
826 static NTSTATUS
CDROM_ControlEjection(int fd
, const PREVENT_MEDIA_REMOVAL
* rmv
)
829 return CDROM_GetStatusCode(ioctl(fd
, CDROM_LOCKDOOR
, rmv
->PreventMediaRemoval
));
830 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
831 return CDROM_GetStatusCode(ioctl(fd
, (rmv
->PreventMediaRemoval
) ? CDIOCPREVENT
: CDIOCALLOW
, NULL
));
833 FIXME("not supported on this O/S\n");
834 return STATUS_NOT_SUPPORTED
;
838 /******************************************************************
843 static NTSTATUS
CDROM_ReadTOC(int dev
, int fd
, CDROM_TOC
* toc
)
845 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
847 if (dev
< 0 || dev
>= MAX_CACHE_ENTRIES
)
848 return STATUS_INVALID_PARAMETER
;
850 RtlEnterCriticalSection( &cache_section
);
851 if (cdrom_cache
[dev
].toc_good
|| !(ret
= CDROM_SyncCache(dev
, fd
)))
853 *toc
= cdrom_cache
[dev
].toc
;
854 ret
= STATUS_SUCCESS
;
856 RtlLeaveCriticalSection( &cache_section
);
860 /******************************************************************
865 static NTSTATUS
CDROM_GetDiskData(int dev
, int fd
, CDROM_DISK_DATA
* data
)
871 if ((ret
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return ret
;
873 for (i
= toc
.FirstTrack
; i
<= toc
.LastTrack
; i
++) {
874 if (toc
.TrackData
[i
-toc
.FirstTrack
].Control
& 0x04)
875 data
->DiskData
|= CDROM_DISK_DATA_TRACK
;
877 data
->DiskData
|= CDROM_DISK_AUDIO_TRACK
;
879 return STATUS_SUCCESS
;
882 /******************************************************************
887 static NTSTATUS
CDROM_ReadQChannel(int dev
, int fd
, const CDROM_SUB_Q_DATA_FORMAT
* fmt
,
888 SUB_Q_CHANNEL_DATA
* data
)
890 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
892 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
894 struct cdrom_subchnl sc
;
895 sc
.cdsc_format
= CDROM_MSF
;
897 io
= ioctl(fd
, CDROMSUBCHNL
, &sc
);
900 TRACE("opened or no_media (%s)!\n", strerror(errno
));
901 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
902 CDROM_ClearCacheEntry(dev
);
906 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
908 switch (sc
.cdsc_audiostatus
) {
909 case CDROM_AUDIO_INVALID
:
910 CDROM_ClearCacheEntry(dev
);
911 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
913 case CDROM_AUDIO_NO_STATUS
:
914 CDROM_ClearCacheEntry(dev
);
915 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
917 case CDROM_AUDIO_PLAY
:
918 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
920 case CDROM_AUDIO_PAUSED
:
921 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
923 case CDROM_AUDIO_COMPLETED
:
924 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
926 case CDROM_AUDIO_ERROR
:
927 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
930 TRACE("status=%02X !\n", sc
.cdsc_audiostatus
);
931 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
935 case IOCTL_CDROM_CURRENT_POSITION
:
936 RtlEnterCriticalSection( &cache_section
);
937 if (hdr
->AudioStatus
==AUDIO_STATUS_IN_PROGRESS
) {
938 data
->CurrentPosition
.FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
939 data
->CurrentPosition
.Control
= sc
.cdsc_ctrl
;
940 data
->CurrentPosition
.ADR
= sc
.cdsc_adr
;
941 data
->CurrentPosition
.TrackNumber
= sc
.cdsc_trk
;
942 data
->CurrentPosition
.IndexNumber
= sc
.cdsc_ind
;
944 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
945 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.cdsc_absaddr
.msf
.minute
;
946 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.cdsc_absaddr
.msf
.second
;
947 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.cdsc_absaddr
.msf
.frame
;
949 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
950 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.cdsc_reladdr
.msf
.minute
;
951 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.cdsc_reladdr
.msf
.second
;
952 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.cdsc_reladdr
.msf
.frame
;
954 cdrom_cache
[dev
].CurrentPosition
= data
->CurrentPosition
;
956 else /* not playing */
958 cdrom_cache
[dev
].CurrentPosition
.Header
= *hdr
; /* Preserve header info */
959 data
->CurrentPosition
= cdrom_cache
[dev
].CurrentPosition
;
961 RtlLeaveCriticalSection( &cache_section
);
963 case IOCTL_CDROM_MEDIA_CATALOG
:
964 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
966 struct cdrom_mcn mcn
;
967 if ((io
= ioctl(fd
, CDROM_GET_MCN
, &mcn
)) == -1) goto end
;
969 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
970 data
->MediaCatalog
.Mcval
= 0; /* FIXME */
971 memcpy(data
->MediaCatalog
.MediaCatalog
, mcn
.medium_catalog_number
, 14);
972 data
->MediaCatalog
.MediaCatalog
[14] = 0;
975 case IOCTL_CDROM_TRACK_ISRC
:
976 FIXME("TrackIsrc: NIY on linux\n");
977 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
978 data
->TrackIsrc
.Tcval
= 0;
984 ret
= CDROM_GetStatusCode(io
);
985 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
986 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
988 struct ioc_read_subchannel read_sc
;
989 struct cd_sub_channel_info sc
;
991 read_sc
.address_format
= CD_MSF_FORMAT
;
993 read_sc
.data_len
= sizeof(sc
);
997 case IOCTL_CDROM_CURRENT_POSITION
:
998 read_sc
.data_format
= CD_CURRENT_POSITION
;
1000 case IOCTL_CDROM_MEDIA_CATALOG
:
1001 read_sc
.data_format
= CD_MEDIA_CATALOG
;
1003 case IOCTL_CDROM_TRACK_ISRC
:
1004 read_sc
.data_format
= CD_TRACK_INFO
;
1005 sc
.what
.track_info
.track_number
= data
->TrackIsrc
.Track
;
1008 io
= ioctl(fd
, CDIOCREADSUBCHANNEL
, &read_sc
);
1011 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1012 CDROM_ClearCacheEntry(dev
);
1013 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
1017 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
1019 switch (sc
.header
.audio_status
) {
1020 case CD_AS_AUDIO_INVALID
:
1021 CDROM_ClearCacheEntry(dev
);
1022 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
1024 case CD_AS_NO_STATUS
:
1025 CDROM_ClearCacheEntry(dev
);
1026 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
1028 case CD_AS_PLAY_IN_PROGRESS
:
1029 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
1031 case CD_AS_PLAY_PAUSED
:
1032 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
1034 case CD_AS_PLAY_COMPLETED
:
1035 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
1037 case CD_AS_PLAY_ERROR
:
1038 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
1041 TRACE("status=%02X !\n", sc
.header
.audio_status
);
1042 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
1044 switch (fmt
->Format
)
1046 case IOCTL_CDROM_CURRENT_POSITION
:
1047 RtlEnterCriticalSection( &cache_section
);
1048 if (hdr
->AudioStatus
==AUDIO_STATUS_IN_PROGRESS
) {
1049 data
->CurrentPosition
.FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
1050 data
->CurrentPosition
.Control
= sc
.what
.position
.control
;
1051 data
->CurrentPosition
.ADR
= sc
.what
.position
.addr_type
;
1052 data
->CurrentPosition
.TrackNumber
= sc
.what
.position
.track_number
;
1053 data
->CurrentPosition
.IndexNumber
= sc
.what
.position
.index_number
;
1055 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
1056 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.what
.position
.absaddr
.msf
.minute
;
1057 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.what
.position
.absaddr
.msf
.second
;
1058 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.what
.position
.absaddr
.msf
.frame
;
1059 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
1060 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.what
.position
.reladdr
.msf
.minute
;
1061 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.what
.position
.reladdr
.msf
.second
;
1062 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.what
.position
.reladdr
.msf
.frame
;
1063 cdrom_cache
[dev
].CurrentPosition
= data
->CurrentPosition
;
1065 else { /* not playing */
1066 cdrom_cache
[dev
].CurrentPosition
.Header
= *hdr
; /* Preserve header info */
1067 data
->CurrentPosition
= cdrom_cache
[dev
].CurrentPosition
;
1069 RtlLeaveCriticalSection( &cache_section
);
1071 case IOCTL_CDROM_MEDIA_CATALOG
:
1072 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
1073 data
->MediaCatalog
.Mcval
= sc
.what
.media_catalog
.mc_valid
;
1074 memcpy(data
->MediaCatalog
.MediaCatalog
, sc
.what
.media_catalog
.mc_number
, 15);
1076 case IOCTL_CDROM_TRACK_ISRC
:
1077 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
1078 data
->TrackIsrc
.Tcval
= sc
.what
.track_info
.ti_valid
;
1079 memcpy(data
->TrackIsrc
.TrackIsrc
, sc
.what
.track_info
.ti_number
, 15);
1084 ret
= CDROM_GetStatusCode(io
);
1085 #elif defined(__APPLE__)
1086 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
1090 dk_cd_read_mcn_t mcn
;
1091 dk_cd_read_isrc_t isrc
;
1093 /* We need IOCDAudioControl for IOCTL_CDROM_CURRENT_POSITION */
1094 if (fmt
->Format
== IOCTL_CDROM_CURRENT_POSITION
)
1097 return STATUS_NOT_SUPPORTED
;
1099 /* No IOCDAudioControl support; just set the audio status to none */
1100 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
1103 case IOCTL_CDROM_MEDIA_CATALOG
:
1104 if ((io
= ioctl(fd
, DKIOCCDREADMCN
, &ioc
.mcn
)) == -1) break;
1105 memcpy(data
->MediaCatalog
.MediaCatalog
, ioc
.mcn
.mcn
, kCDMCNMaxLength
);
1106 data
->MediaCatalog
.Mcval
= 1;
1108 case IOCTL_CDROM_TRACK_ISRC
:
1109 ioc
.isrc
.track
= fmt
->Track
;
1110 if ((io
= ioctl(fd
, DKIOCCDREADISRC
, &ioc
.isrc
)) == -1) break;
1111 memcpy(data
->TrackIsrc
.TrackIsrc
, ioc
.isrc
.isrc
, kCDISRCMaxLength
);
1112 data
->TrackIsrc
.Tcval
= 1;
1113 data
->TrackIsrc
.Track
= ioc
.isrc
.track
;
1115 ret
= CDROM_GetStatusCode(io
);
1120 /******************************************************************
1122 * Implements: IOCTL_STORAGE_CHECK_VERIFY
1123 * IOCTL_CDROM_CHECK_VERIFY
1124 * IOCTL_DISK_CHECK_VERIFY
1127 static NTSTATUS
CDROM_Verify(int dev
, int fd
)
1132 ret
= ioctl(fd
, CDROM_DRIVE_STATUS
, NULL
);
1134 TRACE("ioctl CDROM_DRIVE_STATUS failed(%s)!\n", strerror(errno
));
1135 return CDROM_GetStatusCode(ret
);
1138 if(ret
== CDS_DISC_OK
)
1139 return STATUS_SUCCESS
;
1141 return STATUS_NO_MEDIA_IN_DEVICE
;
1142 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1144 ret
= ioctl(fd
, CDIOCSTART
, NULL
);
1146 return STATUS_SUCCESS
;
1148 return STATUS_NO_MEDIA_IN_DEVICE
;
1149 #elif defined(__APPLE__)
1150 /* At this point, we know that we have media, because in Mac OS X, the
1151 * device file is only created when media is present. */
1152 return STATUS_SUCCESS
;
1154 FIXME("not supported on this O/S\n");
1155 return STATUS_NOT_SUPPORTED
;
1159 /******************************************************************
1160 * CDROM_PlayAudioMSF
1164 static NTSTATUS
CDROM_PlayAudioMSF(int fd
, const CDROM_PLAY_AUDIO_MSF
* audio_msf
)
1166 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1168 struct cdrom_msf msf
;
1171 msf
.cdmsf_min0
= audio_msf
->StartingM
;
1172 msf
.cdmsf_sec0
= audio_msf
->StartingS
;
1173 msf
.cdmsf_frame0
= audio_msf
->StartingF
;
1174 msf
.cdmsf_min1
= audio_msf
->EndingM
;
1175 msf
.cdmsf_sec1
= audio_msf
->EndingS
;
1176 msf
.cdmsf_frame1
= audio_msf
->EndingF
;
1178 io
= ioctl(fd
, CDROMSTART
);
1181 WARN("motor doesn't start !\n");
1184 io
= ioctl(fd
, CDROMPLAYMSF
, &msf
);
1187 WARN("device doesn't play !\n");
1190 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1191 msf
.cdmsf_min0
, msf
.cdmsf_sec0
, msf
.cdmsf_frame0
,
1192 msf
.cdmsf_min1
, msf
.cdmsf_sec1
, msf
.cdmsf_frame1
);
1194 ret
= CDROM_GetStatusCode(io
);
1195 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1196 struct ioc_play_msf msf
;
1199 msf
.start_m
= audio_msf
->StartingM
;
1200 msf
.start_s
= audio_msf
->StartingS
;
1201 msf
.start_f
= audio_msf
->StartingF
;
1202 msf
.end_m
= audio_msf
->EndingM
;
1203 msf
.end_s
= audio_msf
->EndingS
;
1204 msf
.end_f
= audio_msf
->EndingF
;
1206 io
= ioctl(fd
, CDIOCSTART
, NULL
);
1209 WARN("motor doesn't start !\n");
1212 io
= ioctl(fd
, CDIOCPLAYMSF
, &msf
);
1215 WARN("device doesn't play !\n");
1218 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1219 msf
.start_m
, msf
.start_s
, msf
.start_f
,
1220 msf
.end_m
, msf
.end_s
, msf
.end_f
);
1222 ret
= CDROM_GetStatusCode(io
);
1227 /******************************************************************
1228 * CDROM_SeekAudioMSF
1232 static NTSTATUS
CDROM_SeekAudioMSF(int dev
, int fd
, const CDROM_SEEK_AUDIO_MSF
* audio_msf
)
1236 SUB_Q_CURRENT_POSITION
*cp
;
1238 struct cdrom_msf0 msf
;
1239 struct cdrom_subchnl sc
;
1240 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1241 struct ioc_play_msf msf
;
1242 struct ioc_read_subchannel read_sc
;
1243 struct cd_sub_channel_info sc
;
1247 /* Use the information on the TOC to compute the new current
1248 * position, which is shadowed on the cache. [Portable]. */
1249 frame
= FRAME_OF_MSF(*audio_msf
);
1251 if ((io
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return io
;
1253 for(i
=toc
.FirstTrack
;i
<=toc
.LastTrack
+1;i
++)
1254 if (FRAME_OF_TOC(toc
,i
)>frame
) break;
1255 if (i
<= toc
.FirstTrack
|| i
> toc
.LastTrack
+1)
1256 return STATUS_INVALID_PARAMETER
;
1258 RtlEnterCriticalSection( &cache_section
);
1259 cp
= &cdrom_cache
[dev
].CurrentPosition
;
1260 cp
->FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
1261 cp
->Control
= toc
.TrackData
[i
-toc
.FirstTrack
].Control
;
1262 cp
->ADR
= toc
.TrackData
[i
-toc
.FirstTrack
].Adr
;
1263 cp
->TrackNumber
= toc
.TrackData
[i
-toc
.FirstTrack
].TrackNumber
;
1264 cp
->IndexNumber
= 0; /* FIXME: where do they keep these? */
1265 cp
->AbsoluteAddress
[0] = 0;
1266 cp
->AbsoluteAddress
[1] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[1];
1267 cp
->AbsoluteAddress
[2] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[2];
1268 cp
->AbsoluteAddress
[3] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[3];
1269 frame
-= FRAME_OF_TOC(toc
,i
);
1270 cp
->TrackRelativeAddress
[0] = 0;
1271 MSF_OF_FRAME(cp
->TrackRelativeAddress
[1], frame
);
1272 RtlLeaveCriticalSection( &cache_section
);
1274 /* If playing, then issue a seek command, otherwise do nothing */
1276 sc
.cdsc_format
= CDROM_MSF
;
1278 io
= ioctl(fd
, CDROMSUBCHNL
, &sc
);
1281 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1282 CDROM_ClearCacheEntry(dev
);
1283 return CDROM_GetStatusCode(io
);
1285 if (sc
.cdsc_audiostatus
==CDROM_AUDIO_PLAY
)
1287 msf
.minute
= audio_msf
->M
;
1288 msf
.second
= audio_msf
->S
;
1289 msf
.frame
= audio_msf
->F
;
1290 return CDROM_GetStatusCode(ioctl(fd
, CDROMSEEK
, &msf
));
1292 return STATUS_SUCCESS
;
1293 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1294 read_sc
.address_format
= CD_MSF_FORMAT
;
1296 read_sc
.data_len
= sizeof(sc
);
1298 read_sc
.data_format
= CD_CURRENT_POSITION
;
1300 io
= ioctl(fd
, CDIOCREADSUBCHANNEL
, &read_sc
);
1303 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1304 CDROM_ClearCacheEntry(dev
);
1305 return CDROM_GetStatusCode(io
);
1307 if (sc
.header
.audio_status
==CD_AS_PLAY_IN_PROGRESS
)
1310 msf
.start_m
= audio_msf
->M
;
1311 msf
.start_s
= audio_msf
->S
;
1312 msf
.start_f
= audio_msf
->F
;
1313 final_frame
= FRAME_OF_TOC(toc
,toc
.LastTrack
+1)-1;
1314 MSF_OF_FRAME(msf
.end_m
, final_frame
);
1316 return CDROM_GetStatusCode(ioctl(fd
, CDIOCPLAYMSF
, &msf
));
1318 return STATUS_SUCCESS
;
1320 FIXME("not supported on this O/S\n");
1321 return STATUS_NOT_SUPPORTED
;
1325 /******************************************************************
1330 static NTSTATUS
CDROM_PauseAudio(int fd
)
1333 return CDROM_GetStatusCode(ioctl(fd
, CDROMPAUSE
));
1334 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1335 return CDROM_GetStatusCode(ioctl(fd
, CDIOCPAUSE
, NULL
));
1337 FIXME(": not supported on this O/S\n");
1338 return STATUS_NOT_SUPPORTED
;
1342 /******************************************************************
1347 static NTSTATUS
CDROM_ResumeAudio(int fd
)
1350 return CDROM_GetStatusCode(ioctl(fd
, CDROMRESUME
));
1351 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1352 return CDROM_GetStatusCode(ioctl(fd
, CDIOCRESUME
, NULL
));
1354 FIXME("not supported on this O/S\n");
1355 return STATUS_NOT_SUPPORTED
;
1359 /******************************************************************
1364 static NTSTATUS
CDROM_StopAudio(int fd
)
1367 return CDROM_GetStatusCode(ioctl(fd
, CDROMSTOP
));
1368 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1369 return CDROM_GetStatusCode(ioctl(fd
, CDIOCSTOP
, NULL
));
1371 FIXME("not supported on this O/S\n");
1372 return STATUS_NOT_SUPPORTED
;
1376 /******************************************************************
1381 static NTSTATUS
CDROM_GetVolume(int fd
, VOLUME_CONTROL
* vc
)
1384 struct cdrom_volctrl volc
;
1387 io
= ioctl(fd
, CDROMVOLREAD
, &volc
);
1390 vc
->PortVolume
[0] = volc
.channel0
;
1391 vc
->PortVolume
[1] = volc
.channel1
;
1392 vc
->PortVolume
[2] = volc
.channel2
;
1393 vc
->PortVolume
[3] = volc
.channel3
;
1395 return CDROM_GetStatusCode(io
);
1396 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1397 struct ioc_vol volc
;
1400 io
= ioctl(fd
, CDIOCGETVOL
, &volc
);
1403 vc
->PortVolume
[0] = volc
.vol
[0];
1404 vc
->PortVolume
[1] = volc
.vol
[1];
1405 vc
->PortVolume
[2] = volc
.vol
[2];
1406 vc
->PortVolume
[3] = volc
.vol
[3];
1408 return CDROM_GetStatusCode(io
);
1410 FIXME("not supported on this O/S\n");
1411 return STATUS_NOT_SUPPORTED
;
1415 /******************************************************************
1420 static NTSTATUS
CDROM_SetVolume(int fd
, const VOLUME_CONTROL
* vc
)
1423 struct cdrom_volctrl volc
;
1425 volc
.channel0
= vc
->PortVolume
[0];
1426 volc
.channel1
= vc
->PortVolume
[1];
1427 volc
.channel2
= vc
->PortVolume
[2];
1428 volc
.channel3
= vc
->PortVolume
[3];
1430 return CDROM_GetStatusCode(ioctl(fd
, CDROMVOLCTRL
, &volc
));
1431 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__)
1432 struct ioc_vol volc
;
1434 volc
.vol
[0] = vc
->PortVolume
[0];
1435 volc
.vol
[1] = vc
->PortVolume
[1];
1436 volc
.vol
[2] = vc
->PortVolume
[2];
1437 volc
.vol
[3] = vc
->PortVolume
[3];
1439 return CDROM_GetStatusCode(ioctl(fd
, CDIOCSETVOL
, &volc
));
1441 FIXME(": not supported on this O/S\n");
1442 return STATUS_NOT_SUPPORTED
;
1446 /******************************************************************
1449 * Some features of this IOCTL are rather poorly documented and
1450 * not really intuitive either:
1452 * 1. Although the DiskOffset parameter is meant to be a
1453 * byte offset into the disk, it is in fact the sector
1454 * number multiplied by 2048 regardless of the actual
1457 * 2. The least significant 11 bits of DiskOffset are ignored.
1459 * 3. The TrackMode parameter has no effect on the sector
1460 * size. The entire raw sector (i.e. 2352 bytes of data)
1461 * is always returned. IMO the TrackMode is only used
1462 * to check the correct sector type.
1465 static NTSTATUS
CDROM_RawRead(int fd
, const RAW_READ_INFO
* raw
, void* buffer
, DWORD len
, DWORD
* sz
)
1467 int ret
= STATUS_NOT_SUPPORTED
;
1473 TRACE("RAW_READ_INFO: DiskOffset=%i,%i SectorCount=%i TrackMode=%i\n buffer=%p len=%i sz=%p\n",
1474 raw
->DiskOffset
.u
.HighPart
, raw
->DiskOffset
.u
.LowPart
, raw
->SectorCount
, raw
->TrackMode
, buffer
, len
, sz
);
1476 if (len
< raw
->SectorCount
* 2352) return STATUS_BUFFER_TOO_SMALL
;
1479 if (raw
->DiskOffset
.u
.HighPart
& ~2047) {
1480 WARN("DiskOffset points to a sector >= 2**32\n");
1484 switch (raw
->TrackMode
)
1489 DWORD lba
= raw
->DiskOffset
.QuadPart
>> 11;
1490 struct cdrom_msf
* msf
;
1491 PBYTE
*bp
; /* current buffer pointer */
1494 if ((lba
+ raw
->SectorCount
) >
1495 ((1 << 8*sizeof(msf
->cdmsf_min0
)) * CD_SECS
* CD_FRAMES
1497 WARN("DiskOffset not accessible with MSF\n");
1501 /* Linux reads only one sector at a time.
1502 * ioctl CDROMREADRAW takes struct cdrom_msf as an argument
1503 * on the contrary to what header comments state.
1505 lba
+= CD_MSF_OFFSET
;
1506 for (i
= 0, bp
= buffer
; i
< raw
->SectorCount
;
1507 i
++, lba
++, bp
+= 2352)
1509 msf
= (struct cdrom_msf
*)bp
;
1510 msf
->cdmsf_min0
= lba
/ CD_FRAMES
/ CD_SECS
;
1511 msf
->cdmsf_sec0
= lba
/ CD_FRAMES
% CD_SECS
;
1512 msf
->cdmsf_frame0
= lba
% CD_FRAMES
;
1513 io
= ioctl(fd
, CDROMREADRAW
, msf
);
1517 return CDROM_GetStatusCode(io
);
1525 struct cdrom_read_audio cdra
;
1527 cdra
.addr
.lba
= raw
->DiskOffset
.QuadPart
>> 11;
1528 TRACE("reading at %u\n", cdra
.addr
.lba
);
1529 cdra
.addr_format
= CDROM_LBA
;
1530 cdra
.nframes
= raw
->SectorCount
;
1532 io
= ioctl(fd
, CDROMREADAUDIO
, &cdra
);
1537 FIXME("NIY: %d\n", raw
->TrackMode
);
1538 return STATUS_INVALID_PARAMETER
;
1540 #elif defined(__APPLE__)
1541 /* Mac OS lets us read multiple parts of the sector at a time.
1542 * We can read all the sectors in at once, unlike Linux.
1544 memset(&cdrd
, 0, sizeof(cdrd
));
1545 cdrd
.offset
= (raw
->DiskOffset
.QuadPart
>> 11) * kCDSectorSizeWhole
;
1546 cdrd
.buffer
= buffer
;
1547 cdrd
.bufferLength
= raw
->SectorCount
* kCDSectorSizeWhole
;
1548 switch (raw
->TrackMode
)
1551 cdrd
.sectorType
= kCDSectorTypeMode2
;
1552 cdrd
.sectorArea
= kCDSectorAreaSync
| kCDSectorAreaHeader
| kCDSectorAreaUser
;
1556 cdrd
.sectorType
= kCDSectorTypeMode2Form2
;
1557 cdrd
.sectorArea
= kCDSectorAreaSync
| kCDSectorAreaHeader
| kCDSectorAreaSubHeader
| kCDSectorAreaUser
;
1561 cdrd
.sectorType
= kCDSectorTypeCDDA
;
1562 cdrd
.sectorArea
= kCDSectorAreaUser
;
1566 FIXME("NIY: %d\n", raw
->TrackMode
);
1567 return STATUS_INVALID_PARAMETER
;
1569 io
= ioctl(fd
, DKIOCCDREAD
, &cdrd
);
1572 *sz
= cdrd
.bufferLength
;
1573 return CDROM_GetStatusCode(io
);
1576 switch (raw
->TrackMode
)
1579 FIXME("YellowMode2: NIY\n");
1582 FIXME("XAForm2: NIY\n");
1585 FIXME("CDDA: NIY\n");
1588 FIXME("NIY: %d\n", raw
->TrackMode
);
1589 return STATUS_INVALID_PARAMETER
;
1593 *sz
= 2352 * raw
->SectorCount
;
1594 ret
= CDROM_GetStatusCode(io
);
1598 /******************************************************************
1599 * CDROM_ScsiPassThroughDirect
1600 * Implements IOCTL_SCSI_PASS_THROUGH_DIRECT
1603 static NTSTATUS
CDROM_ScsiPassThroughDirect(int fd
, PSCSI_PASS_THROUGH_DIRECT pPacket
)
1605 int ret
= STATUS_NOT_SUPPORTED
;
1606 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1609 #elif defined HAVE_SCSIREQ_T_CMD
1612 #elif defined __APPLE__
1613 dk_scsi_command_t cmd
;
1617 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH_DIRECT
))
1618 return STATUS_BUFFER_TOO_SMALL
;
1620 if (pPacket
->CdbLength
> 16)
1621 return STATUS_INVALID_PARAMETER
;
1624 if (pPacket
->SenseInfoLength
> SENSEBUFLEN
)
1625 return STATUS_INVALID_PARAMETER
;
1626 #elif defined HAVE_REQUEST_SENSE
1627 if (pPacket
->SenseInfoLength
> sizeof(struct request_sense
))
1628 return STATUS_INVALID_PARAMETER
;
1631 if (pPacket
->DataTransferLength
> 0 && !pPacket
->DataBuffer
)
1632 return STATUS_INVALID_PARAMETER
;
1634 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1635 RtlZeroMemory(&cmd
, sizeof(cmd
));
1637 cmd
.interface_id
= 'S';
1638 cmd
.cmd_len
= pPacket
->CdbLength
;
1639 cmd
.mx_sb_len
= pPacket
->SenseInfoLength
;
1640 cmd
.dxfer_len
= pPacket
->DataTransferLength
;
1641 cmd
.dxferp
= pPacket
->DataBuffer
;
1642 cmd
.cmdp
= pPacket
->Cdb
;
1643 cmd
.sbp
= (unsigned char*)pPacket
+ pPacket
->SenseInfoOffset
;
1644 cmd
.timeout
= pPacket
->TimeOutValue
*1000;
1646 switch (pPacket
->DataIn
)
1648 case SCSI_IOCTL_DATA_IN
:
1649 cmd
.dxfer_direction
= SG_DXFER_FROM_DEV
;
1651 case SCSI_IOCTL_DATA_OUT
:
1652 cmd
.dxfer_direction
= SG_DXFER_TO_DEV
;
1654 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1655 cmd
.dxfer_direction
= SG_DXFER_NONE
;
1658 return STATUS_INVALID_PARAMETER
;
1661 io
= ioctl(fd
, SG_IO
, &cmd
);
1663 pPacket
->ScsiStatus
= cmd
.status
;
1664 pPacket
->DataTransferLength
= cmd
.resid
;
1665 pPacket
->SenseInfoLength
= cmd
.sb_len_wr
;
1667 ret
= CDROM_GetStatusCode(io
);
1669 #elif defined HAVE_SCSIREQ_T_CMD
1671 memset(&cmd
, 0, sizeof(cmd
));
1672 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1674 cmd
.cmdlen
= pPacket
->CdbLength
;
1675 cmd
.databuf
= pPacket
->DataBuffer
;
1676 cmd
.datalen
= pPacket
->DataTransferLength
;
1677 cmd
.senselen
= pPacket
->SenseInfoLength
;
1678 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1680 switch (pPacket
->DataIn
)
1682 case SCSI_IOCTL_DATA_OUT
:
1683 cmd
.flags
|= SCCMD_WRITE
;
1685 case SCSI_IOCTL_DATA_IN
:
1686 cmd
.flags
|= SCCMD_READ
;
1688 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1692 return STATUS_INVALID_PARAMETER
;
1695 io
= ioctl(fd
, SCIOCCOMMAND
, &cmd
);
1699 case SCCMD_OK
: break;
1700 case SCCMD_TIMEOUT
: return STATUS_TIMEOUT
;
1702 case SCCMD_BUSY
: return STATUS_DEVICE_BUSY
;
1704 case SCCMD_SENSE
: break;
1705 case SCCMD_UNKNOWN
: return STATUS_UNSUCCESSFUL
;
1709 if (pPacket
->SenseInfoLength
!= 0)
1711 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1712 cmd
.sense
, pPacket
->SenseInfoLength
);
1715 pPacket
->ScsiStatus
= cmd
.status
;
1717 ret
= CDROM_GetStatusCode(io
);
1719 #elif defined(__APPLE__)
1721 memset(&cmd
, 0, sizeof(cmd
));
1722 memcpy(cmd
.cdb
, pPacket
->Cdb
, pPacket
->CdbLength
);
1724 cmd
.cdbSize
= pPacket
->CdbLength
;
1725 cmd
.buffer
= pPacket
->DataBuffer
;
1726 cmd
.bufferSize
= pPacket
->DataTransferLength
;
1727 cmd
.sense
= (char*)pPacket
+ pPacket
->SenseInfoOffset
;
1728 cmd
.senseLen
= pPacket
->SenseInfoLength
;
1729 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1731 switch (pPacket
->DataIn
)
1733 case SCSI_IOCTL_DATA_OUT
:
1734 cmd
.direction
= kSCSIDataTransfer_FromInitiatorToTarget
;
1736 case SCSI_IOCTL_DATA_IN
:
1737 cmd
.direction
= kSCSIDataTransfer_FromTargetToInitiator
;
1739 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1740 cmd
.direction
= kSCSIDataTransfer_NoDataTransfer
;
1743 return STATUS_INVALID_PARAMETER
;
1746 io
= ioctl(fd
, DKIOCSCSICOMMAND
, &cmd
);
1748 if (cmd
.response
== kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE
)
1750 /* Command failed */
1753 case kSCSITaskStatus_TaskTimeoutOccurred
: return STATUS_TIMEOUT
;
1755 case kSCSITaskStatus_ProtocolTimeoutOccurred
: return STATUS_IO_TIMEOUT
;
1757 case kSCSITaskStatus_DeviceNotResponding
: return STATUS_DEVICE_BUSY
;
1759 case kSCSITaskStatus_DeviceNotPresent
:
1760 return STATUS_NO_SUCH_DEVICE
;
1762 case kSCSITaskStatus_DeliveryFailure
:
1763 return STATUS_DEVICE_PROTOCOL_ERROR
;
1765 case kSCSITaskStatus_No_Status
:
1767 return STATUS_UNSUCCESSFUL
;
1772 if (cmd
.status
!= kSCSITaskStatus_No_Status
)
1773 pPacket
->ScsiStatus
= cmd
.status
;
1775 ret
= CDROM_GetStatusCode(io
);
1780 /******************************************************************
1781 * CDROM_ScsiPassThrough
1782 * Implements IOCTL_SCSI_PASS_THROUGH
1785 static NTSTATUS
CDROM_ScsiPassThrough(int fd
, PSCSI_PASS_THROUGH pPacket
)
1787 int ret
= STATUS_NOT_SUPPORTED
;
1788 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1791 #elif defined HAVE_SCSIREQ_T_CMD
1794 #elif defined __APPLE__
1795 dk_scsi_command_t cmd
;
1799 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH
))
1800 return STATUS_BUFFER_TOO_SMALL
;
1802 if (pPacket
->CdbLength
> 16)
1803 return STATUS_INVALID_PARAMETER
;
1806 if (pPacket
->SenseInfoLength
> SENSEBUFLEN
)
1807 return STATUS_INVALID_PARAMETER
;
1808 #elif defined HAVE_REQUEST_SENSE
1809 if (pPacket
->SenseInfoLength
> sizeof(struct request_sense
))
1810 return STATUS_INVALID_PARAMETER
;
1813 if (pPacket
->DataTransferLength
> 0 && pPacket
->DataBufferOffset
< sizeof(SCSI_PASS_THROUGH
))
1814 return STATUS_INVALID_PARAMETER
;
1816 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1817 RtlZeroMemory(&cmd
, sizeof(cmd
));
1819 cmd
.interface_id
= 'S';
1820 cmd
.dxfer_len
= pPacket
->DataTransferLength
;
1821 cmd
.dxferp
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1822 cmd
.cmd_len
= pPacket
->CdbLength
;
1823 cmd
.cmdp
= pPacket
->Cdb
;
1824 cmd
.mx_sb_len
= pPacket
->SenseInfoLength
;
1825 cmd
.timeout
= pPacket
->TimeOutValue
*1000;
1827 if(cmd
.mx_sb_len
> 0)
1828 cmd
.sbp
= (unsigned char*)pPacket
+ pPacket
->SenseInfoOffset
;
1830 switch (pPacket
->DataIn
)
1832 case SCSI_IOCTL_DATA_IN
:
1833 cmd
.dxfer_direction
= SG_DXFER_FROM_DEV
;
1835 case SCSI_IOCTL_DATA_OUT
:
1836 cmd
.dxfer_direction
= SG_DXFER_TO_DEV
;
1838 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1839 cmd
.dxfer_direction
= SG_DXFER_NONE
;
1842 return STATUS_INVALID_PARAMETER
;
1845 io
= ioctl(fd
, SG_IO
, &cmd
);
1847 pPacket
->ScsiStatus
= cmd
.status
;
1848 pPacket
->DataTransferLength
= cmd
.resid
;
1849 pPacket
->SenseInfoLength
= cmd
.sb_len_wr
;
1851 ret
= CDROM_GetStatusCode(io
);
1853 #elif defined HAVE_SCSIREQ_T_CMD
1855 memset(&cmd
, 0, sizeof(cmd
));
1856 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1858 if ( pPacket
->DataBufferOffset
> 0x1000 )
1860 cmd
.databuf
= (void*)pPacket
->DataBufferOffset
;
1864 cmd
.databuf
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1867 cmd
.cmdlen
= pPacket
->CdbLength
;
1868 cmd
.datalen
= pPacket
->DataTransferLength
;
1869 cmd
.senselen
= pPacket
->SenseInfoLength
;
1870 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1872 switch (pPacket
->DataIn
)
1874 case SCSI_IOCTL_DATA_OUT
:
1875 cmd
.flags
|= SCCMD_WRITE
;
1877 case SCSI_IOCTL_DATA_IN
:
1878 cmd
.flags
|= SCCMD_READ
;
1880 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1884 return STATUS_INVALID_PARAMETER
;
1887 io
= ioctl(fd
, SCIOCCOMMAND
, &cmd
);
1891 case SCCMD_OK
: break;
1892 case SCCMD_TIMEOUT
: return STATUS_TIMEOUT
;
1894 case SCCMD_BUSY
: return STATUS_DEVICE_BUSY
;
1896 case SCCMD_SENSE
: break;
1897 case SCCMD_UNKNOWN
: return STATUS_UNSUCCESSFUL
;
1901 if (pPacket
->SenseInfoLength
!= 0)
1903 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1904 cmd
.sense
, pPacket
->SenseInfoLength
);
1907 pPacket
->ScsiStatus
= cmd
.status
;
1909 ret
= CDROM_GetStatusCode(io
);
1911 #elif defined(__APPLE__)
1913 memset(&cmd
, 0, sizeof(cmd
));
1914 memcpy(cmd
.cdb
, pPacket
->Cdb
, pPacket
->CdbLength
);
1916 cmd
.cdbSize
= pPacket
->CdbLength
;
1917 cmd
.buffer
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1918 cmd
.bufferSize
= pPacket
->DataTransferLength
;
1919 cmd
.sense
= (char*)pPacket
+ pPacket
->SenseInfoOffset
;
1920 cmd
.senseLen
= pPacket
->SenseInfoLength
;
1921 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1923 switch (pPacket
->DataIn
)
1925 case SCSI_IOCTL_DATA_OUT
:
1926 cmd
.direction
= kSCSIDataTransfer_FromInitiatorToTarget
;
1928 case SCSI_IOCTL_DATA_IN
:
1929 cmd
.direction
= kSCSIDataTransfer_FromTargetToInitiator
;
1931 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1932 cmd
.direction
= kSCSIDataTransfer_NoDataTransfer
;
1935 return STATUS_INVALID_PARAMETER
;
1938 io
= ioctl(fd
, DKIOCSCSICOMMAND
, &cmd
);
1940 if (cmd
.response
== kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE
)
1942 /* Command failed */
1945 case kSCSITaskStatus_TaskTimeoutOccurred
:
1946 return STATUS_TIMEOUT
;
1948 case kSCSITaskStatus_ProtocolTimeoutOccurred
:
1949 return STATUS_IO_TIMEOUT
;
1951 case kSCSITaskStatus_DeviceNotResponding
:
1952 return STATUS_DEVICE_BUSY
;
1954 case kSCSITaskStatus_DeviceNotPresent
:
1955 return STATUS_NO_SUCH_DEVICE
;
1957 case kSCSITaskStatus_DeliveryFailure
:
1958 return STATUS_DEVICE_PROTOCOL_ERROR
;
1960 case kSCSITaskStatus_No_Status
:
1962 return STATUS_UNSUCCESSFUL
;
1967 if (cmd
.status
!= kSCSITaskStatus_No_Status
)
1968 pPacket
->ScsiStatus
= cmd
.status
;
1970 ret
= CDROM_GetStatusCode(io
);
1975 /******************************************************************
1980 static NTSTATUS
CDROM_ScsiGetCaps(int fd
, PIO_SCSI_CAPABILITIES caps
)
1982 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
1984 #ifdef SG_SCATTER_SZ
1985 caps
->Length
= sizeof(*caps
);
1986 caps
->MaximumTransferLength
= SG_SCATTER_SZ
; /* FIXME */
1987 caps
->MaximumPhysicalPages
= SG_SCATTER_SZ
/ page_size
;
1988 caps
->SupportedAsynchronousEvents
= TRUE
;
1989 caps
->AlignmentMask
= page_size
;
1990 caps
->TaggedQueuing
= FALSE
; /* we could check that it works and answer TRUE */
1991 caps
->AdapterScansDown
= FALSE
; /* FIXME ? */
1992 caps
->AdapterUsesPio
= FALSE
; /* FIXME ? */
1993 ret
= STATUS_SUCCESS
;
1994 #elif defined __APPLE__
1995 uint64_t bytesr
, bytesw
, align
;
1996 int io
= ioctl(fd
, DKIOCGETMAXBYTECOUNTREAD
, &bytesr
);
1997 if (io
!= 0) return CDROM_GetStatusCode(io
);
1998 io
= ioctl(fd
, DKIOCGETMAXBYTECOUNTWRITE
, &bytesw
);
1999 if (io
!= 0) return CDROM_GetStatusCode(io
);
2000 io
= ioctl(fd
, DKIOCGETMINSEGMENTALIGNMENTBYTECOUNT
, &align
);
2001 if (io
!= 0) return CDROM_GetStatusCode(io
);
2002 caps
->Length
= sizeof(*caps
);
2003 caps
->MaximumTransferLength
= bytesr
< bytesw
? bytesr
: bytesw
;
2004 caps
->MaximumPhysicalPages
= caps
->MaximumTransferLength
/ page_size
;
2005 caps
->SupportedAsynchronousEvents
= TRUE
;
2006 caps
->AlignmentMask
= align
-1;
2007 caps
->TaggedQueuing
= FALSE
; /* we could check that it works and answer TRUE */
2008 caps
->AdapterScansDown
= FALSE
; /* FIXME ? */
2009 caps
->AdapterUsesPio
= FALSE
; /* FIXME ? */
2010 ret
= STATUS_SUCCESS
;
2012 FIXME("Unimplemented\n");
2017 /******************************************************************
2020 * implements IOCTL_SCSI_GET_ADDRESS
2022 static NTSTATUS
CDROM_GetAddress(int fd
, SCSI_ADDRESS
* address
)
2024 UCHAR portnum
, busid
, targetid
, lun
;
2026 address
->Length
= sizeof(SCSI_ADDRESS
);
2027 if ( ! CDROM_GetInterfaceInfo(fd
, &portnum
, &busid
, &targetid
, &lun
))
2028 return STATUS_NOT_SUPPORTED
;
2030 address
->PortNumber
= portnum
; /* primary=0 secondary=1 for ide */
2031 address
->PathId
= busid
; /* always 0 for ide */
2032 address
->TargetId
= targetid
; /* master=0 slave=1 for ide */
2034 return STATUS_SUCCESS
;
2037 /******************************************************************
2042 static NTSTATUS
DVD_StartSession(int fd
, const DVD_SESSION_ID
*sid_in
, PDVD_SESSION_ID sid_out
)
2045 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
2046 dvd_authinfo auth_info
;
2048 memset( &auth_info
, 0, sizeof( auth_info
) );
2049 auth_info
.type
= DVD_LU_SEND_AGID
;
2050 if (sid_in
) auth_info
.lsa
.agid
= *(const int*)sid_in
; /* ?*/
2052 TRACE("fd 0x%08x\n",fd
);
2053 ret
=CDROM_GetStatusCode(ioctl(fd
, DVD_AUTH
, &auth_info
));
2054 *sid_out
= auth_info
.lsa
.agid
;
2056 #elif defined(__APPLE__)
2057 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
2058 dk_dvd_report_key_t dvdrk
;
2059 DVDAuthenticationGrantIDInfo agid_info
;
2061 dvdrk
.format
= kDVDKeyFormatAGID_CSS
;
2062 dvdrk
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2063 if(sid_in
) dvdrk
.grantID
= *(uint8_t*)sid_in
; /* ? */
2064 dvdrk
.bufferLength
= sizeof(DVDAuthenticationGrantIDInfo
);
2065 dvdrk
.buffer
= &agid_info
;
2067 ret
= CDROM_GetStatusCode(ioctl(fd
, DKIOCDVDREPORTKEY
, &dvdrk
));
2068 *sid_out
= agid_info
.grantID
;
2071 FIXME("not supported on this O/S\n");
2072 return STATUS_NOT_SUPPORTED
;
2076 /******************************************************************
2081 static NTSTATUS
DVD_EndSession(int fd
, const DVD_SESSION_ID
*sid
)
2084 dvd_authinfo auth_info
;
2086 memset( &auth_info
, 0, sizeof( auth_info
) );
2087 auth_info
.type
= DVD_INVALIDATE_AGID
;
2088 auth_info
.lsa
.agid
= *(const int*)sid
;
2091 return CDROM_GetStatusCode(ioctl(fd
, DVD_AUTH
, &auth_info
));
2092 #elif defined(__APPLE__)
2093 dk_dvd_send_key_t dvdsk
;
2095 dvdsk
.format
= kDVDKeyFormatAGID_Invalidate
;
2096 dvdsk
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2097 dvdsk
.grantID
= (uint8_t)*sid
;
2099 return CDROM_GetStatusCode(ioctl(fd
, DKIOCDVDSENDKEY
, &dvdsk
));
2101 FIXME("not supported on this O/S\n");
2102 return STATUS_NOT_SUPPORTED
;
2106 /******************************************************************
2111 static NTSTATUS
DVD_SendKey(int fd
, const DVD_COPY_PROTECT_KEY
*key
)
2114 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
2115 dvd_authinfo auth_info
;
2117 memset( &auth_info
, 0, sizeof( auth_info
) );
2118 switch (key
->KeyType
)
2120 case DvdChallengeKey
:
2121 auth_info
.type
= DVD_HOST_SEND_CHALLENGE
;
2122 auth_info
.hsc
.agid
= (int)key
->SessionId
;
2123 TRACE("DvdChallengeKey ioc 0x%x\n", DVD_AUTH
);
2124 memcpy( auth_info
.hsc
.chal
, key
->KeyData
, DVD_CHALLENGE_SIZE
);
2125 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
2128 auth_info
.type
= DVD_HOST_SEND_KEY2
;
2129 auth_info
.hsk
.agid
= (int)key
->SessionId
;
2131 memcpy( auth_info
.hsk
.key
, key
->KeyData
, DVD_KEY_SIZE
);
2133 TRACE("DvdBusKey2\n");
2134 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
2138 FIXME("Unknown Keytype 0x%x\n",key
->KeyType
);
2141 #elif defined(__APPLE__)
2142 dk_dvd_send_key_t dvdsk
;
2145 DVDChallengeKeyInfo chal
;
2149 switch(key
->KeyType
)
2151 case DvdChallengeKey
:
2152 dvdsk
.format
= kDVDKeyFormatChallengeKey
;
2153 dvdsk
.bufferLength
= sizeof(key_desc
.chal
);
2154 dvdsk
.buffer
= &key_desc
.chal
;
2155 OSWriteBigInt16(key_desc
.chal
.dataLength
, 0, key
->KeyLength
);
2156 memcpy(key_desc
.chal
.challengeKeyValue
, key
->KeyData
, key
->KeyLength
);
2159 dvdsk
.format
= kDVDKeyFormatKey2
;
2160 dvdsk
.bufferLength
= sizeof(key_desc
.key2
);
2161 dvdsk
.buffer
= &key_desc
.key2
;
2162 OSWriteBigInt16(key_desc
.key2
.dataLength
, 0, key
->KeyLength
);
2163 memcpy(key_desc
.key2
.key2Value
, key
->KeyData
, key
->KeyLength
);
2165 case DvdInvalidateAGID
:
2166 dvdsk
.format
= kDVDKeyFormatAGID_Invalidate
;
2173 ERR("attempted to write read-only key type 0x%x\n", key
->KeyType
);
2174 return STATUS_NOT_SUPPORTED
;
2176 FIXME("DvdSetRpcKey NIY\n");
2177 return STATUS_NOT_SUPPORTED
;
2179 FIXME("got unknown key type 0x%x\n", key
->KeyType
);
2180 return STATUS_NOT_SUPPORTED
;
2182 dvdsk
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2183 dvdsk
.grantID
= (uint8_t)key
->SessionId
;
2185 return CDROM_GetStatusCode(ioctl(fd
, DKIOCDVDSENDKEY
, &dvdsk
));
2187 FIXME("not supported on this O/S\n");
2188 return STATUS_NOT_SUPPORTED
;
2192 /******************************************************************
2197 static NTSTATUS
DVD_ReadKey(int fd
, PDVD_COPY_PROTECT_KEY key
)
2200 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
2202 dvd_authinfo auth_info
;
2204 memset( &dvd
, 0, sizeof( dvd_struct
) );
2205 memset( &auth_info
, 0, sizeof( auth_info
) );
2206 switch (key
->KeyType
)
2210 dvd
.type
= DVD_STRUCT_DISCKEY
;
2211 dvd
.disckey
.agid
= (int)key
->SessionId
;
2212 memset( dvd
.disckey
.value
, 0, DVD_DISCKEY_SIZE
);
2214 TRACE("DvdDiskKey\n");
2215 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_READ_STRUCT
, &dvd
));
2216 if (ret
== STATUS_SUCCESS
)
2217 memcpy(key
->KeyData
,dvd
.disckey
.value
,DVD_DISCKEY_SIZE
);
2220 auth_info
.type
= DVD_LU_SEND_TITLE_KEY
;
2221 auth_info
.lstk
.agid
= (int)key
->SessionId
;
2222 auth_info
.lstk
.lba
= (int)(key
->Parameters
.TitleOffset
.QuadPart
>>11);
2223 TRACE("DvdTitleKey session %d Quadpart 0x%08lx offset 0x%08x\n",
2224 (int)key
->SessionId
, (long)key
->Parameters
.TitleOffset
.QuadPart
,
2225 auth_info
.lstk
.lba
);
2226 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
2227 if (ret
== STATUS_SUCCESS
)
2228 memcpy(key
->KeyData
, auth_info
.lstk
.title_key
, DVD_KEY_SIZE
);
2230 case DvdChallengeKey
:
2232 auth_info
.type
= DVD_LU_SEND_CHALLENGE
;
2233 auth_info
.lsc
.agid
= (int)key
->SessionId
;
2235 TRACE("DvdChallengeKey\n");
2236 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
2237 if (ret
== STATUS_SUCCESS
)
2238 memcpy( key
->KeyData
, auth_info
.lsc
.chal
, DVD_CHALLENGE_SIZE
);
2241 auth_info
.type
= DVD_LU_SEND_ASF
;
2243 auth_info
.lsasf
.asf
=((PDVD_ASF
)key
->KeyData
)->SuccessFlag
;
2244 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
2245 ((PDVD_ASF
)key
->KeyData
)->SuccessFlag
= auth_info
.lsasf
.asf
;
2248 auth_info
.type
= DVD_LU_SEND_KEY1
;
2249 auth_info
.lsk
.agid
= (int)key
->SessionId
;
2251 TRACE("DvdBusKey1\n");
2252 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
2254 if (ret
== STATUS_SUCCESS
)
2255 memcpy( key
->KeyData
, auth_info
.lsk
.key
, DVD_KEY_SIZE
);
2258 auth_info
.type
= DVD_LU_SEND_RPC_STATE
;
2260 TRACE("DvdGetRpcKey\n");
2261 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
2263 if (ret
== STATUS_SUCCESS
)
2265 ((PDVD_RPC_KEY
)key
->KeyData
)->TypeCode
= auth_info
.lrpcs
.type
;
2266 ((PDVD_RPC_KEY
)key
->KeyData
)->RegionMask
= auth_info
.lrpcs
.region_mask
;
2267 ((PDVD_RPC_KEY
)key
->KeyData
)->RpcScheme
= auth_info
.lrpcs
.rpc_scheme
;
2268 ((PDVD_RPC_KEY
)key
->KeyData
)->UserResetsAvailable
= auth_info
.lrpcs
.ucca
;
2269 ((PDVD_RPC_KEY
)key
->KeyData
)->ManufacturerResetsAvailable
= auth_info
.lrpcs
.vra
;
2273 FIXME("Unknown keytype 0x%x\n",key
->KeyType
);
2276 #elif defined(__APPLE__)
2279 dk_dvd_report_key_t key
;
2280 dk_dvd_read_structure_t disk_key
;
2284 DVDDiscKeyInfo disk_key
;
2285 DVDChallengeKeyInfo chal
;
2287 DVDTitleKeyInfo title
;
2288 DVDAuthenticationSuccessFlagInfo asf
;
2289 DVDRegionPlaybackControlInfo rpc
;
2291 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
2293 switch(key
->KeyType
)
2295 case DvdChallengeKey
:
2296 ioc
.key
.format
= kDVDKeyFormatChallengeKey
;
2297 ioc
.key
.grantID
= (uint8_t)key
->SessionId
;
2298 ioc
.key
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2299 ioc
.key
.bufferLength
= sizeof(desc
.chal
);
2300 ioc
.key
.buffer
= &desc
.chal
;
2301 OSWriteBigInt16(desc
.chal
.dataLength
, 0, key
->KeyLength
);
2304 ioc
.key
.format
= kDVDKeyFormatKey1
;
2305 ioc
.key
.grantID
= (uint8_t)key
->SessionId
;
2306 ioc
.key
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2307 ioc
.key
.bufferLength
= sizeof(desc
.key1
);
2308 ioc
.key
.buffer
= &desc
.key1
;
2309 OSWriteBigInt16(desc
.key1
.dataLength
, 0, key
->KeyLength
);
2312 ioc
.key
.format
= kDVDKeyFormatTitleKey
;
2313 ioc
.key
.grantID
= (uint8_t)key
->SessionId
;
2314 ioc
.key
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2315 ioc
.key
.bufferLength
= sizeof(desc
.title
);
2316 ioc
.key
.buffer
= &desc
.title
;
2317 ioc
.key
.address
= (uint32_t)(key
->Parameters
.TitleOffset
.QuadPart
>>11);
2318 OSWriteBigInt16(desc
.title
.dataLength
, 0, key
->KeyLength
);
2321 ioc
.key
.format
= kDVDKeyFormatASF
;
2322 ioc
.key
.grantID
= (uint8_t)key
->SessionId
;
2323 ioc
.key
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2324 ioc
.key
.bufferLength
= sizeof(desc
.asf
);
2325 ioc
.key
.buffer
= &desc
.asf
;
2326 OSWriteBigInt16(desc
.asf
.dataLength
, 0, key
->KeyLength
);
2329 ioc
.key
.format
= kDVDKeyFormatRegionState
;
2330 ioc
.key
.grantID
= (uint8_t)key
->SessionId
;
2331 ioc
.key
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2332 ioc
.key
.bufferLength
= sizeof(desc
.rpc
);
2333 ioc
.key
.buffer
= &desc
.rpc
;
2334 OSWriteBigInt16(desc
.rpc
.dataLength
, 0, key
->KeyLength
);
2337 ioc
.disk_key
.format
= kDVDStructureFormatDiscKeyInfo
;
2338 ioc
.disk_key
.grantID
= (uint8_t)key
->SessionId
;
2339 ioc
.disk_key
.bufferLength
= sizeof(desc
.disk_key
);
2340 ioc
.disk_key
.buffer
= &desc
.disk_key
;
2342 case DvdInvalidateAGID
:
2343 ioc
.key
.format
= kDVDKeyFormatAGID_Invalidate
;
2344 ioc
.key
.grantID
= (uint8_t)key
->SessionId
;
2345 ioc
.key
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2349 ERR("attempted to read write-only key type 0x%x\n", key
->KeyType
);
2350 return STATUS_NOT_SUPPORTED
;
2352 FIXME("got unknown key type 0x%x\n", key
->KeyType
);
2353 return STATUS_NOT_SUPPORTED
;
2356 ret
= CDROM_GetStatusCode(ioctl(fd
, (key
->KeyType
== DvdDiskKey
? DKIOCDVDREADSTRUCTURE
: DKIOCDVDREPORTKEY
), &ioc
));
2358 if (ret
== STATUS_SUCCESS
)
2360 switch(key
->KeyType
)
2362 case DvdChallengeKey
:
2363 key
->KeyLength
= OSReadBigInt16(desc
.chal
.dataLength
, 0);
2364 memcpy(key
->KeyData
, desc
.chal
.challengeKeyValue
, key
->KeyLength
);
2367 key
->KeyLength
= OSReadBigInt16(desc
.key1
.dataLength
, 0);
2368 memcpy(key
->KeyData
, desc
.key1
.key1Value
, key
->KeyLength
);
2371 key
->KeyLength
= OSReadBigInt16(desc
.title
.dataLength
, 0);
2372 memcpy(key
->KeyData
, desc
.title
.titleKeyValue
, key
->KeyLength
);
2376 /*key->KeyFlags |= DVD_COPYRIGHTED;*/
2377 if (desc
.title
.CP_SEC
) key
->KeyFlags
|= DVD_SECTOR_PROTECTED
;
2378 /*else key->KeyFlags |= DVD_SECTOR_NOT_PROTECTED;*/
2380 switch (desc
.title
.CGMS
)
2383 key
->KeyFlags
|= DVD_CGMS_COPY_PERMITTED
;
2386 key
->KeyFlags
|= DVD_CGMS_COPY_ONCE
;
2389 key
->KeyFlags
|= DVD_CGMS_NO_COPY
;
2393 } /*else key->KeyFlags |= DVD_NOT_COPYRIGHTED;*/
2396 key
->KeyLength
= OSReadBigInt16(desc
.title
.dataLength
, 0);
2397 ((PDVD_ASF
)key
->KeyData
)->SuccessFlag
= desc
.asf
.successFlag
;
2400 key
->KeyLength
= OSReadBigInt16(desc
.rpc
.dataLength
, 0);
2401 ((PDVD_RPC_KEY
)key
->KeyData
)->UserResetsAvailable
=
2402 desc
.rpc
.numberUserResets
;
2403 ((PDVD_RPC_KEY
)key
->KeyData
)->ManufacturerResetsAvailable
=
2404 desc
.rpc
.numberVendorResets
;
2405 ((PDVD_RPC_KEY
)key
->KeyData
)->TypeCode
=
2407 ((PDVD_RPC_KEY
)key
->KeyData
)->RegionMask
=
2408 desc
.rpc
.driveRegion
;
2409 ((PDVD_RPC_KEY
)key
->KeyData
)->RpcScheme
=
2412 key
->KeyLength
= OSReadBigInt16(desc
.disk_key
.dataLength
, 0);
2413 memcpy(key
->KeyData
, desc
.disk_key
.discKeyStructures
, key
->KeyLength
);
2417 case DvdInvalidateAGID
:
2419 /* Silence warning */
2425 FIXME("not supported on this O/S\n");
2426 return STATUS_NOT_SUPPORTED
;
2430 /******************************************************************
2433 * This IOCTL combines information from both IOCTL_DVD_READ_KEY
2434 * with key type DvdGetRpcKey and IOCTL_DVD_READ_STRUCTURE with
2435 * structure type DvdCopyrightInformation into one structure.
2437 static NTSTATUS
DVD_GetRegion(int fd
, PDVD_REGION region
)
2442 dvd_authinfo auth_info
;
2444 dvd
.type
= DVD_STRUCT_COPYRIGHT
;
2445 dvd
.copyright
.layer_num
= 0;
2446 auth_info
.type
= DVD_LU_SEND_RPC_STATE
;
2448 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
2450 if (ret
== STATUS_SUCCESS
)
2452 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_READ_STRUCT
, &dvd
));
2454 if (ret
== STATUS_SUCCESS
)
2456 region
->CopySystem
= dvd
.copyright
.cpst
;
2457 region
->RegionData
= dvd
.copyright
.rmi
;
2458 region
->SystemRegion
= auth_info
.lrpcs
.region_mask
;
2459 region
->ResetCount
= auth_info
.lrpcs
.ucca
;
2463 #elif defined(__APPLE__)
2464 dk_dvd_report_key_t key
;
2465 dk_dvd_read_structure_t dvd
;
2466 DVDRegionPlaybackControlInfo rpc
;
2467 DVDCopyrightInfo copy
;
2470 key
.format
= kDVDKeyFormatRegionState
;
2471 key
.keyClass
= kDVDKeyClassCSS_CPPM_CPRM
;
2472 key
.bufferLength
= sizeof(rpc
);
2474 dvd
.format
= kDVDStructureFormatCopyrightInfo
;
2475 dvd
.bufferLength
= sizeof(copy
);
2478 ret
= CDROM_GetStatusCode(ioctl( fd
, DKIOCDVDREPORTKEY
, &key
));
2480 if (ret
== STATUS_SUCCESS
)
2482 ret
= CDROM_GetStatusCode(ioctl( fd
, DKIOCDVDREADSTRUCTURE
, &dvd
));
2484 if (ret
== STATUS_SUCCESS
)
2486 region
->CopySystem
= copy
.copyrightProtectionSystemType
;
2487 region
->RegionData
= copy
.regionMask
;
2488 region
->SystemRegion
= rpc
.driveRegion
;
2489 region
->ResetCount
= rpc
.numberUserResets
;
2494 FIXME("not supported on this O/S\n");
2495 return STATUS_NOT_SUPPORTED
;
2499 static DWORD
DVD_ReadStructureSize(const DVD_READ_STRUCTURE
*structure
, DWORD size
)
2501 if (!structure
|| size
!= sizeof(DVD_READ_STRUCTURE
))
2504 switch (structure
->Format
)
2506 case DvdPhysicalDescriptor
:
2507 return sizeof(DVD_LAYER_DESCRIPTOR
);
2508 case DvdCopyrightDescriptor
:
2509 return sizeof(DVD_COPYRIGHT_DESCRIPTOR
);
2510 case DvdDiskKeyDescriptor
:
2511 return sizeof(DVD_DISK_KEY_DESCRIPTOR
);
2512 case DvdBCADescriptor
:
2513 return sizeof(DVD_BCA_DESCRIPTOR
);
2514 case DvdManufacturerDescriptor
:
2515 return sizeof(DVD_MANUFACTURER_DESCRIPTOR
);
2521 /******************************************************************
2526 static NTSTATUS
DVD_ReadStructure(int dev
, const DVD_READ_STRUCTURE
*structure
, PDVD_LAYER_DESCRIPTOR layer
)
2528 #ifdef DVD_READ_STRUCT
2529 /* dvd_struct is not defined consistently across platforms */
2532 struct dvd_physical physical
;
2533 struct dvd_copyright copyright
;
2534 struct dvd_disckey disckey
;
2536 struct dvd_manufact manufact
;
2539 if (structure
->BlockByteOffset
.QuadPart
) FIXME(": BlockByteOffset is not handled\n");
2541 switch (structure
->Format
)
2543 case DvdPhysicalDescriptor
:
2544 s
.physical
.type
= DVD_STRUCT_PHYSICAL
;
2545 s
.physical
.layer_num
= structure
->LayerNumber
;
2548 case DvdCopyrightDescriptor
:
2549 s
.copyright
.type
= DVD_STRUCT_COPYRIGHT
;
2550 s
.copyright
.layer_num
= structure
->LayerNumber
;
2553 case DvdDiskKeyDescriptor
:
2554 s
.disckey
.type
= DVD_STRUCT_DISCKEY
;
2555 s
.disckey
.agid
= structure
->SessionId
;
2558 case DvdBCADescriptor
:
2559 s
.bca
.type
= DVD_STRUCT_BCA
;
2562 case DvdManufacturerDescriptor
:
2563 s
.manufact
.type
= DVD_STRUCT_MANUFACT
;
2564 s
.manufact
.layer_num
= structure
->LayerNumber
;
2567 case DvdMaxDescriptor
: /* This is not a real request, no matter what MSDN says! */
2569 return STATUS_INVALID_PARAMETER
;
2572 if (ioctl(dev
, DVD_READ_STRUCT
, &s
) < 0)
2573 return STATUS_INVALID_PARAMETER
;
2575 switch (structure
->Format
)
2577 case DvdPhysicalDescriptor
:
2579 internal_dvd_layer_descriptor
*p
= (internal_dvd_layer_descriptor
*) layer
;
2580 struct dvd_layer
*l
= &s
.physical
.layer
[s
.physical
.layer_num
];
2582 p
->Header
.Length
= 0x0802;
2583 p
->Header
.Reserved
[0] = 0;
2584 p
->Header
.Reserved
[1] = 0;
2585 p
->Descriptor
.BookVersion
= l
->book_version
;
2586 p
->Descriptor
.BookType
= l
->book_type
;
2587 p
->Descriptor
.MinimumRate
= l
->min_rate
;
2588 p
->Descriptor
.DiskSize
= l
->disc_size
;
2589 p
->Descriptor
.LayerType
= l
->layer_type
;
2590 p
->Descriptor
.TrackPath
= l
->track_path
;
2591 p
->Descriptor
.NumberOfLayers
= l
->nlayers
;
2592 p
->Descriptor
.Reserved1
= 0;
2593 p
->Descriptor
.TrackDensity
= l
->track_density
;
2594 p
->Descriptor
.LinearDensity
= l
->linear_density
;
2595 p
->Descriptor
.StartingDataSector
= GET_BE_DWORD(l
->start_sector
);
2596 p
->Descriptor
.EndDataSector
= GET_BE_DWORD(l
->end_sector
);
2597 p
->Descriptor
.EndLayerZeroSector
= GET_BE_DWORD(l
->end_sector_l0
);
2598 p
->Descriptor
.Reserved5
= 0;
2599 p
->Descriptor
.BCAFlag
= l
->bca
;
2603 case DvdCopyrightDescriptor
:
2605 PDVD_COPYRIGHT_DESCRIPTOR p
= (PDVD_COPYRIGHT_DESCRIPTOR
) layer
;
2607 p
->CopyrightProtectionType
= s
.copyright
.cpst
;
2608 p
->RegionManagementInformation
= s
.copyright
.rmi
;
2613 case DvdDiskKeyDescriptor
:
2615 PDVD_DISK_KEY_DESCRIPTOR p
= (PDVD_DISK_KEY_DESCRIPTOR
) layer
;
2617 memcpy(p
->DiskKeyData
, s
.disckey
.value
, 2048);
2621 case DvdBCADescriptor
:
2623 PDVD_BCA_DESCRIPTOR p
= (PDVD_BCA_DESCRIPTOR
) layer
;
2625 memcpy(p
->BCAInformation
, s
.bca
.value
, s
.bca
.len
);
2629 case DvdManufacturerDescriptor
:
2631 internal_dvd_manufacturer_descriptor
*p
= (internal_dvd_manufacturer_descriptor
*) layer
;
2633 p
->Header
.Length
= 0x0802;
2634 p
->Header
.Reserved
[0] = 0;
2635 p
->Header
.Reserved
[1] = 0;
2636 memcpy(p
->Descriptor
.ManufacturingInformation
, s
.manufact
.value
, 2048);
2640 case DvdMaxDescriptor
: /* Suppress warning */
2643 #elif defined(__APPLE__)
2645 dk_dvd_read_structure_t dvdrs
;
2648 DVDPhysicalFormatInfo phys
;
2649 DVDCopyrightInfo copy
;
2650 DVDDiscKeyInfo disk_key
;
2651 DVDManufacturingInfo manf
;
2655 PDVD_LAYER_DESCRIPTOR layer
;
2656 internal_dvd_layer_descriptor
*xlayer
;
2657 PDVD_COPYRIGHT_DESCRIPTOR copy
;
2658 PDVD_DISK_KEY_DESCRIPTOR disk_key
;
2659 internal_dvd_manufacturer_descriptor
*manf
;
2662 nt_desc
.layer
= layer
;
2663 RtlZeroMemory(&dvdrs
, sizeof(dvdrs
));
2664 dvdrs
.address
= (uint32_t)(structure
->BlockByteOffset
.QuadPart
>>11);
2665 dvdrs
.grantID
= (uint8_t)structure
->SessionId
;
2666 dvdrs
.layer
= structure
->LayerNumber
;
2667 switch(structure
->Format
)
2669 case DvdPhysicalDescriptor
:
2670 dvdrs
.format
= kDVDStructureFormatPhysicalFormatInfo
;
2671 dvdrs
.bufferLength
= sizeof(desc
.phys
);
2672 dvdrs
.buffer
= &desc
.phys
;
2675 case DvdCopyrightDescriptor
:
2676 dvdrs
.format
= kDVDStructureFormatCopyrightInfo
;
2677 dvdrs
.bufferLength
= sizeof(desc
.copy
);
2678 dvdrs
.buffer
= &desc
.copy
;
2681 case DvdDiskKeyDescriptor
:
2682 dvdrs
.format
= kDVDStructureFormatDiscKeyInfo
;
2683 dvdrs
.bufferLength
= sizeof(desc
.disk_key
);
2684 dvdrs
.buffer
= &desc
.disk_key
;
2687 case DvdBCADescriptor
:
2688 FIXME("DvdBCADescriptor NIY\n");
2689 return STATUS_NOT_SUPPORTED
;
2691 case DvdManufacturerDescriptor
:
2692 dvdrs
.format
= kDVDStructureFormatManufacturingInfo
;
2693 dvdrs
.bufferLength
= sizeof(desc
.manf
);
2694 dvdrs
.buffer
= &desc
.manf
;
2697 case DvdMaxDescriptor
:
2699 FIXME("got unknown structure type 0x%x\n", structure
->Format
);
2700 return STATUS_NOT_SUPPORTED
;
2702 ret
= CDROM_GetStatusCode(ioctl(dev
, DKIOCDVDREADSTRUCTURE
, &dvdrs
));
2703 if(ret
== STATUS_SUCCESS
)
2705 switch(structure
->Format
)
2707 case DvdPhysicalDescriptor
:
2708 nt_desc
.xlayer
->Header
.Length
= 0x0802;
2709 nt_desc
.xlayer
->Header
.Reserved
[0] = 0;
2710 nt_desc
.xlayer
->Header
.Reserved
[1] = 0;
2711 nt_desc
.xlayer
->Descriptor
.BookVersion
= desc
.phys
.partVersion
;
2712 nt_desc
.xlayer
->Descriptor
.BookType
= desc
.phys
.bookType
;
2713 nt_desc
.xlayer
->Descriptor
.MinimumRate
= desc
.phys
.minimumRate
;
2714 nt_desc
.xlayer
->Descriptor
.DiskSize
= desc
.phys
.discSize
;
2715 nt_desc
.xlayer
->Descriptor
.LayerType
= desc
.phys
.layerType
;
2716 nt_desc
.xlayer
->Descriptor
.TrackPath
= desc
.phys
.trackPath
;
2717 nt_desc
.xlayer
->Descriptor
.NumberOfLayers
= desc
.phys
.numberOfLayers
;
2718 nt_desc
.xlayer
->Descriptor
.Reserved1
= 0;
2719 nt_desc
.xlayer
->Descriptor
.TrackDensity
= desc
.phys
.trackDensity
;
2720 nt_desc
.xlayer
->Descriptor
.LinearDensity
= desc
.phys
.linearDensity
;
2721 nt_desc
.xlayer
->Descriptor
.StartingDataSector
= GET_BE_DWORD(*(DWORD
*)&desc
.phys
.zero1
);
2722 nt_desc
.xlayer
->Descriptor
.EndDataSector
= GET_BE_DWORD(*(DWORD
*)&desc
.phys
.zero2
);
2723 nt_desc
.xlayer
->Descriptor
.EndLayerZeroSector
= GET_BE_DWORD(*(DWORD
*)&desc
.phys
.zero3
);
2724 nt_desc
.xlayer
->Descriptor
.Reserved5
= 0;
2725 nt_desc
.xlayer
->Descriptor
.BCAFlag
= desc
.phys
.bcaFlag
;
2728 case DvdCopyrightDescriptor
:
2729 nt_desc
.copy
->CopyrightProtectionType
=
2730 desc
.copy
.copyrightProtectionSystemType
;
2731 nt_desc
.copy
->RegionManagementInformation
=
2732 desc
.copy
.regionMask
;
2733 nt_desc
.copy
->Reserved
= 0;
2736 case DvdDiskKeyDescriptor
:
2738 nt_desc
.disk_key
->DiskKeyData
,
2739 desc
.disk_key
.discKeyStructures
,
2743 case DvdManufacturerDescriptor
:
2744 nt_desc
.manf
->Header
.Length
= 0x0802;
2745 nt_desc
.manf
->Header
.Reserved
[0] = 0;
2746 nt_desc
.manf
->Header
.Reserved
[1] = 0;
2748 nt_desc
.manf
->Descriptor
.ManufacturingInformation
,
2749 desc
.manf
.discManufacturingInfo
,
2753 case DvdBCADescriptor
:
2754 case DvdMaxDescriptor
:
2756 /* Silence warning */
2764 return STATUS_SUCCESS
;
2768 /******************************************************************
2770 * Implements the IOCTL_GET_INQUIRY_DATA ioctl.
2771 * Returns Inquiry data for all devices on the specified scsi bus
2772 * Returns STATUS_BUFFER_TOO_SMALL if the output buffer is too small,
2773 * STATUS_INVALID_DEVICE_REQUEST if the given handle isn't to a SCSI device,
2774 * or STATUS_NOT_SUPPORTED if the OS driver is too old
2776 static NTSTATUS
GetInquiryData(int fd
, PSCSI_ADAPTER_BUS_INFO BufferOut
, DWORD OutBufferSize
)
2778 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
2779 PSCSI_INQUIRY_DATA pInquiryData
;
2780 UCHAR sense_buffer
[32];
2783 UCHAR inquiry
[INQ_CMD_LEN
] = {INQUIRY
, 0, 0, 0, INQ_REPLY_LEN
, 0};
2785 /* Check we have a SCSI device and a supported driver */
2786 if(ioctl(fd
, SG_GET_VERSION_NUM
, &version
) != 0)
2788 WARN("IOCTL_SCSI_GET_INQUIRY_DATA sg driver is not loaded\n");
2789 return STATUS_INVALID_DEVICE_REQUEST
;
2791 if(version
< 30000 )
2792 return STATUS_NOT_SUPPORTED
;
2794 /* FIXME: Enumerate devices on the bus */
2795 BufferOut
->NumberOfBuses
= 1;
2796 BufferOut
->BusData
[0].NumberOfLogicalUnits
= 1;
2797 BufferOut
->BusData
[0].InquiryDataOffset
= sizeof(SCSI_ADAPTER_BUS_INFO
);
2799 pInquiryData
= (PSCSI_INQUIRY_DATA
)(BufferOut
+ 1);
2801 RtlZeroMemory(&iocmd
, sizeof(iocmd
));
2802 iocmd
.interface_id
= 'S';
2803 iocmd
.cmd_len
= sizeof(inquiry
);
2804 iocmd
.mx_sb_len
= sizeof(sense_buffer
);
2805 iocmd
.dxfer_direction
= SG_DXFER_FROM_DEV
;
2806 iocmd
.dxfer_len
= INQ_REPLY_LEN
;
2807 iocmd
.dxferp
= pInquiryData
->InquiryData
;
2808 iocmd
.cmdp
= inquiry
;
2809 iocmd
.sbp
= sense_buffer
;
2810 iocmd
.timeout
= 1000;
2812 iochk
= ioctl(fd
, SG_IO
, &iocmd
);
2814 WARN("ioctl SG_IO returned %d, error (%s)\n", iochk
, strerror(errno
));
2816 CDROM_GetInterfaceInfo(fd
, &BufferOut
->BusData
[0].InitiatorBusId
, &pInquiryData
->PathId
, &pInquiryData
->TargetId
, &pInquiryData
->Lun
);
2817 pInquiryData
->DeviceClaimed
= TRUE
;
2818 pInquiryData
->InquiryDataLength
= INQ_REPLY_LEN
;
2819 pInquiryData
->NextInquiryDataOffset
= 0;
2820 return STATUS_SUCCESS
;
2822 FIXME("not supported on this O/S\n");
2823 return STATUS_NOT_SUPPORTED
;
2827 /******************************************************************
2828 * CDROM_DeviceIoControl
2832 NTSTATUS
CDROM_DeviceIoControl(HANDLE hDevice
,
2833 HANDLE hEvent
, PIO_APC_ROUTINE UserApcRoutine
,
2834 PVOID UserApcContext
,
2835 PIO_STATUS_BLOCK piosb
,
2836 ULONG dwIoControlCode
,
2837 LPVOID lpInBuffer
, DWORD nInBufferSize
,
2838 LPVOID lpOutBuffer
, DWORD nOutBufferSize
)
2841 NTSTATUS status
= STATUS_SUCCESS
;
2842 int fd
, needs_close
, dev
= 0;
2844 TRACE("%p %s %p %d %p %d %p\n",
2845 hDevice
, iocodex(dwIoControlCode
), lpInBuffer
, nInBufferSize
,
2846 lpOutBuffer
, nOutBufferSize
, piosb
);
2848 piosb
->Information
= 0;
2850 if ((status
= server_get_unix_fd( hDevice
, 0, &fd
, &needs_close
, NULL
, NULL
)))
2852 if (status
== STATUS_BAD_DEVICE_TYPE
) return status
; /* no associated fd */
2856 if ((status
= CDROM_Open(fd
, &dev
)))
2858 if (needs_close
) close( fd
);
2866 /* This is ugly as hell, but Mac OS is unable to do anything from the
2867 * partition fd, it wants an fd for the whole device, and it sometimes
2868 * also requires the device fd to be closed first, so we have to close
2869 * the handle that the caller gave us.
2870 * Also for some reason it wants the fd to be closed before we even
2871 * open the parent if we're trying to eject the disk.
2873 if ((status
= get_parent_device( fd
, name
, sizeof(name
) ))) goto error
;
2874 if (dwIoControlCode
== IOCTL_STORAGE_EJECT_MEDIA
)
2876 if (needs_close
) close( fd
);
2877 TRACE("opening parent %s\n", name
);
2878 if ((fd
= open( name
, O_RDONLY
)) == -1)
2880 status
= FILE_GetNtStatus();
2887 switch (dwIoControlCode
)
2889 case IOCTL_CDROM_CHECK_VERIFY
:
2890 case IOCTL_DISK_CHECK_VERIFY
:
2891 case IOCTL_STORAGE_CHECK_VERIFY
:
2892 case IOCTL_STORAGE_CHECK_VERIFY2
:
2894 CDROM_ClearCacheEntry(dev
);
2895 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2896 status
= STATUS_INVALID_PARAMETER
;
2897 else status
= CDROM_Verify(dev
, fd
);
2900 /* EPP case IOCTL_STORAGE_CHECK_VERIFY2: */
2902 /* EPP case IOCTL_STORAGE_FIND_NEW_DEVICES: */
2903 /* EPP case IOCTL_CDROM_FIND_NEW_DEVICES: */
2905 case IOCTL_STORAGE_LOAD_MEDIA
:
2906 case IOCTL_CDROM_LOAD_MEDIA
:
2908 CDROM_ClearCacheEntry(dev
);
2909 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2910 status
= STATUS_INVALID_PARAMETER
;
2911 else status
= CDROM_SetTray(fd
, FALSE
);
2913 case IOCTL_STORAGE_EJECT_MEDIA
:
2915 CDROM_ClearCacheEntry(dev
);
2916 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2917 status
= STATUS_INVALID_PARAMETER
;
2919 status
= CDROM_SetTray(fd
, TRUE
);
2922 case IOCTL_CDROM_MEDIA_REMOVAL
:
2923 case IOCTL_DISK_MEDIA_REMOVAL
:
2924 case IOCTL_STORAGE_MEDIA_REMOVAL
:
2925 case IOCTL_STORAGE_EJECTION_CONTROL
:
2926 /* FIXME the last ioctl:s is not the same as the two others...
2927 * lockcount/owner should be handled */
2929 CDROM_ClearCacheEntry(dev
);
2930 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2931 else if (nInBufferSize
< sizeof(PREVENT_MEDIA_REMOVAL
)) status
= STATUS_BUFFER_TOO_SMALL
;
2932 else status
= CDROM_ControlEjection(fd
, lpInBuffer
);
2935 case IOCTL_DISK_GET_MEDIA_TYPES
:
2936 case IOCTL_STORAGE_GET_MEDIA_TYPES
:
2937 case IOCTL_STORAGE_GET_MEDIA_TYPES_EX
:
2938 sz
= sizeof(GET_MEDIA_TYPES
);
2939 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2940 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2941 else status
= CDROM_GetMediaType(dev
, lpOutBuffer
);
2944 case IOCTL_STORAGE_GET_DEVICE_NUMBER
:
2945 sz
= sizeof(STORAGE_DEVICE_NUMBER
);
2946 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2947 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2948 else status
= CDROM_GetDeviceNumber(dev
, lpOutBuffer
);
2951 case IOCTL_STORAGE_RESET_DEVICE
:
2953 CDROM_ClearCacheEntry(dev
);
2954 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2955 status
= STATUS_INVALID_PARAMETER
;
2956 else status
= CDROM_ResetAudio(fd
);
2959 case IOCTL_CDROM_GET_CONTROL
:
2960 sz
= sizeof(CDROM_AUDIO_CONTROL
);
2961 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2962 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2963 else status
= CDROM_GetControl(dev
, fd
, lpOutBuffer
);
2966 case IOCTL_CDROM_GET_DRIVE_GEOMETRY
:
2967 sz
= sizeof(DISK_GEOMETRY
);
2968 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2969 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2970 else status
= CDROM_GetDriveGeometry(dev
, fd
, lpOutBuffer
);
2973 case IOCTL_CDROM_DISK_TYPE
:
2974 sz
= sizeof(CDROM_DISK_DATA
);
2975 /* CDROM_ClearCacheEntry(dev); */
2976 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2977 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2978 else status
= CDROM_GetDiskData(dev
, fd
, lpOutBuffer
);
2981 /* EPP case IOCTL_CDROM_GET_LAST_SESSION: */
2983 case IOCTL_CDROM_READ_Q_CHANNEL
:
2984 sz
= sizeof(SUB_Q_CHANNEL_DATA
);
2985 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(CDROM_SUB_Q_DATA_FORMAT
))
2986 status
= STATUS_INVALID_PARAMETER
;
2987 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2988 else status
= CDROM_ReadQChannel(dev
, fd
, lpInBuffer
, lpOutBuffer
);
2991 case IOCTL_CDROM_READ_TOC
:
2992 sz
= sizeof(CDROM_TOC
);
2993 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2994 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2995 else status
= CDROM_ReadTOC(dev
, fd
, lpOutBuffer
);
2998 /* EPP case IOCTL_CDROM_READ_TOC_EX: */
3000 case IOCTL_CDROM_PAUSE_AUDIO
:
3002 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
3003 status
= STATUS_INVALID_PARAMETER
;
3004 else status
= CDROM_PauseAudio(fd
);
3006 case IOCTL_CDROM_PLAY_AUDIO_MSF
:
3008 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
3009 else if (nInBufferSize
< sizeof(CDROM_PLAY_AUDIO_MSF
)) status
= STATUS_BUFFER_TOO_SMALL
;
3010 else status
= CDROM_PlayAudioMSF(fd
, lpInBuffer
);
3012 case IOCTL_CDROM_RESUME_AUDIO
:
3014 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
3015 status
= STATUS_INVALID_PARAMETER
;
3016 else status
= CDROM_ResumeAudio(fd
);
3018 case IOCTL_CDROM_SEEK_AUDIO_MSF
:
3020 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
3021 else if (nInBufferSize
< sizeof(CDROM_SEEK_AUDIO_MSF
)) status
= STATUS_BUFFER_TOO_SMALL
;
3022 else status
= CDROM_SeekAudioMSF(dev
, fd
, lpInBuffer
);
3024 case IOCTL_CDROM_STOP_AUDIO
:
3026 CDROM_ClearCacheEntry(dev
); /* Maybe intention is to change media */
3027 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
3028 status
= STATUS_INVALID_PARAMETER
;
3029 else status
= CDROM_StopAudio(fd
);
3031 case IOCTL_CDROM_GET_VOLUME
:
3032 sz
= sizeof(VOLUME_CONTROL
);
3033 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
3034 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
3035 else status
= CDROM_GetVolume(fd
, lpOutBuffer
);
3037 case IOCTL_CDROM_SET_VOLUME
:
3039 CDROM_ClearCacheEntry(dev
);
3040 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(VOLUME_CONTROL
) || lpOutBuffer
!= NULL
)
3041 status
= STATUS_INVALID_PARAMETER
;
3042 else status
= CDROM_SetVolume(fd
, lpInBuffer
);
3044 case IOCTL_CDROM_RAW_READ
:
3046 if (nInBufferSize
< sizeof(RAW_READ_INFO
)) status
= STATUS_INVALID_PARAMETER
;
3047 else if (lpOutBuffer
== NULL
) status
= STATUS_BUFFER_TOO_SMALL
;
3048 else status
= CDROM_RawRead(fd
, lpInBuffer
, lpOutBuffer
,
3049 nOutBufferSize
, &sz
);
3051 case IOCTL_SCSI_GET_ADDRESS
:
3052 sz
= sizeof(SCSI_ADDRESS
);
3053 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
3054 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
3055 else status
= CDROM_GetAddress(fd
, lpOutBuffer
);
3057 case IOCTL_SCSI_PASS_THROUGH_DIRECT
:
3058 sz
= sizeof(SCSI_PASS_THROUGH_DIRECT
);
3059 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
3060 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH_DIRECT
)) status
= STATUS_BUFFER_TOO_SMALL
;
3061 else status
= CDROM_ScsiPassThroughDirect(fd
, lpOutBuffer
);
3063 case IOCTL_SCSI_PASS_THROUGH
:
3064 sz
= sizeof(SCSI_PASS_THROUGH
);
3065 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
3066 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH
)) status
= STATUS_BUFFER_TOO_SMALL
;
3067 else status
= CDROM_ScsiPassThrough(fd
, lpOutBuffer
);
3069 case IOCTL_SCSI_GET_CAPABILITIES
:
3070 sz
= sizeof(IO_SCSI_CAPABILITIES
);
3071 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
3072 else if (nOutBufferSize
< sizeof(IO_SCSI_CAPABILITIES
)) status
= STATUS_BUFFER_TOO_SMALL
;
3073 else status
= CDROM_ScsiGetCaps(fd
, lpOutBuffer
);
3075 case IOCTL_DVD_START_SESSION
:
3076 sz
= sizeof(DVD_SESSION_ID
);
3077 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
3078 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
3081 TRACE("before in 0x%08x out 0x%08x\n",(lpInBuffer
)?*(PDVD_SESSION_ID
)lpInBuffer
:0,
3082 *(PDVD_SESSION_ID
)lpOutBuffer
);
3083 status
= DVD_StartSession(fd
, lpInBuffer
, lpOutBuffer
);
3084 TRACE("before in 0x%08x out 0x%08x\n",(lpInBuffer
)?*(PDVD_SESSION_ID
)lpInBuffer
:0,
3085 *(PDVD_SESSION_ID
)lpOutBuffer
);
3088 case IOCTL_DVD_END_SESSION
:
3089 sz
= sizeof(DVD_SESSION_ID
);
3090 if ((lpInBuffer
== NULL
) || (nInBufferSize
< sz
))status
= STATUS_INVALID_PARAMETER
;
3091 else status
= DVD_EndSession(fd
, lpInBuffer
);
3093 case IOCTL_DVD_SEND_KEY
:
3096 (((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
!= nInBufferSize
))
3097 status
= STATUS_INVALID_PARAMETER
;
3100 TRACE("doing DVD_SendKey\n");
3101 status
= DVD_SendKey(fd
, lpInBuffer
);
3104 case IOCTL_DVD_READ_KEY
:
3106 (((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
!= nInBufferSize
))
3107 status
= STATUS_INVALID_PARAMETER
;
3108 else if (lpInBuffer
!=lpOutBuffer
) status
= STATUS_BUFFER_TOO_SMALL
;
3111 TRACE("doing DVD_READ_KEY\n");
3112 sz
= ((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
;
3113 status
= DVD_ReadKey(fd
, lpInBuffer
);
3116 case IOCTL_DVD_GET_REGION
:
3117 sz
= sizeof(DVD_REGION
);
3118 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
3119 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
3122 TRACE("doing DVD_Get_REGION\n");
3123 status
= DVD_GetRegion(fd
, lpOutBuffer
);
3126 case IOCTL_DVD_READ_STRUCTURE
:
3127 sz
= DVD_ReadStructureSize(lpInBuffer
, nInBufferSize
);
3128 if (lpInBuffer
== NULL
|| nInBufferSize
!= sizeof(DVD_READ_STRUCTURE
)) status
= STATUS_INVALID_PARAMETER
;
3129 else if (nOutBufferSize
< sz
|| !lpOutBuffer
) status
= STATUS_BUFFER_TOO_SMALL
;
3132 TRACE("doing DVD_READ_STRUCTURE\n");
3133 status
= DVD_ReadStructure(fd
, lpInBuffer
, lpOutBuffer
);
3137 case IOCTL_SCSI_GET_INQUIRY_DATA
:
3139 status
= GetInquiryData(fd
, lpOutBuffer
, nOutBufferSize
);
3143 if (needs_close
) close( fd
);
3144 return STATUS_NOT_SUPPORTED
;
3146 if (needs_close
) close( fd
);
3148 piosb
->u
.Status
= status
;
3149 piosb
->Information
= sz
;
3150 if (hEvent
) NtSetEvent(hEvent
, NULL
);