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
87 #include "ntdll_misc.h"
88 #include "wine/server.h"
89 #include "wine/library.h"
90 #include "wine/debug.h"
92 /* Non-Linux systems do not have linux/cdrom.h and the like, and thus
93 lack the following constants. */
96 # define CD_SECS 60 /* seconds per minute */
99 # define CD_FRAMES 75 /* frames per second */
102 /* definitions taken from libdvdcss */
104 #define IOCTL_DVD_BASE FILE_DEVICE_DVD
106 #define IOCTL_DVD_START_SESSION CTL_CODE(IOCTL_DVD_BASE, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
107 #define IOCTL_DVD_READ_KEY CTL_CODE(IOCTL_DVD_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
108 #define IOCTL_DVD_SEND_KEY CTL_CODE(IOCTL_DVD_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
109 #define IOCTL_DVD_END_SESSION CTL_CODE(IOCTL_DVD_BASE, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
110 #define IOCTL_DVD_SET_READ_AHEAD CTL_CODE(IOCTL_DVD_BASE, 0x0404, METHOD_BUFFERED, FILE_READ_ACCESS)
111 #define IOCTL_DVD_GET_REGION CTL_CODE(IOCTL_DVD_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS)
112 #define IOCTL_DVD_SEND_KEY2 CTL_CODE(IOCTL_DVD_BASE, 0x0406, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
114 #define IOCTL_DVD_READ_STRUCTURE CTL_CODE(IOCTL_DVD_BASE, 0x0450, METHOD_BUFFERED, FILE_READ_ACCESS)
117 DvdChallengeKey
= 0x01,
125 DvdInvalidateAGID
= 0x3f
128 typedef ULONG DVD_SESSION_ID
, *PDVD_SESSION_ID
;
130 typedef struct _DVD_COPY_PROTECT_KEY
{
132 DVD_SESSION_ID SessionId
;
133 DVD_KEY_TYPE KeyType
;
138 ULONG Reserved
; /* used for NT alignment */
140 LARGE_INTEGER TitleOffset
;
143 } DVD_COPY_PROTECT_KEY
, *PDVD_COPY_PROTECT_KEY
;
145 typedef struct _DVD_RPC_KEY
{
146 UCHAR UserResetsAvailable
:3;
147 UCHAR ManufacturerResetsAvailable
:3;
152 } DVD_RPC_KEY
, * PDVD_RPC_KEY
;
154 typedef struct _DVD_ASF
{
158 } DVD_ASF
, * PDVD_ASF
;
160 typedef struct _DVD_REGION
162 unsigned char copy_system
;
163 unsigned char region_data
; /* current media region (not playable when set) */
164 unsigned char system_region
; /* current drive region (playable when set) */
165 unsigned char reset_count
; /* number of resets available */
166 } DVD_REGION
, * PDVD_REGION
;
168 typedef struct _DVD_READ_STRUCTURE
{
169 /* Contains an offset to the logical block address of the descriptor to be retrieved. */
170 LARGE_INTEGER block_byte_offset
;
172 /* 0:Physical descriptor, 1:Copyright descriptor, 2:Disk key descriptor
173 3:BCA descriptor, 4:Manufacturer descriptor, 5:Max descriptor
177 /* Session ID, that is obtained by IOCTL_DVD_START_SESSION */
181 unsigned char layer_no
;
182 }DVD_READ_STRUCTURE
, * PDVD_READ_STRUCTURE
;
184 typedef struct _DVD_LAYER_DESCRIPTOR
186 unsigned short length
;
188 unsigned char book_version
: 4;
190 /* 0:DVD-ROM, 1:DVD-RAM, 2:DVD-R, 3:DVD-RW, 9:DVD-RW */
191 unsigned char book_type
: 4;
193 unsigned char minimum_rate
: 4;
195 /* The physical size of the media. 0:120 mm, 1:80 mm. */
196 unsigned char disk_size
: 4;
198 /* 1:Read-only layer, 2:Recordable layer, 4:Rewritable layer */
199 unsigned char layer_type
: 4;
201 /* 0:parallel track path, 1:opposite track path */
202 unsigned char track_path
: 1;
204 /* 0:one layers, 1:two layers, and so on */
205 unsigned char num_of_layers
: 2;
207 unsigned char reserved1
: 1;
209 /* 0:0.74 µm/track, 1:0.80 µm/track, 2:0.615 µm/track */
210 unsigned char track_density
: 4;
212 /* 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 */
213 unsigned char linear_density
: 4;
215 /* Must be either 0x30000:DVD-ROM or DVD-R/-RW or 0x31000:DVD-RAM or DVD+RW */
216 unsigned long starting_data_sector
;
218 unsigned long end_data_sector
;
219 unsigned long end_layer_zero_sector
;
220 unsigned char reserved5
: 7;
222 /* 0 indicates no BCA data */
223 unsigned char BCA_flag
: 1;
225 unsigned char reserved6
;
226 }DVD_LAYER_DESCRIPTOR
, * PDVD_LAYER_DESCRIPTOR
;
228 typedef struct _DVD_COPYRIGHT_DESCRIPTOR
230 unsigned char protection
;
231 unsigned char region
;
232 unsigned short reserved
;
233 }DVD_COPYRIGHT_DESCRIPTOR
, * PDVD_COPYRIGHT_DESCRIPTOR
;
235 typedef struct _DVD_MANUFACTURER_DESCRIPTOR
237 unsigned char manufacturing
[2048];
238 }DVD_MANUFACTURER_DESCRIPTOR
, * PDVD_MANUFACTURER_DESCRIPTOR
;
240 #define DVD_CHALLENGE_KEY_LENGTH (12 + sizeof(DVD_COPY_PROTECT_KEY) - sizeof(UCHAR))
242 #define DVD_DISK_KEY_LENGTH (2048 + sizeof(DVD_COPY_PROTECT_KEY) - sizeof(UCHAR))
244 #define DVD_KEY_SIZE 5
245 #define DVD_CHALLENGE_SIZE 10
246 #define DVD_DISCKEY_SIZE 2048
247 #define DVD_SECTOR_PROTECTED 0x00000020
249 static const struct iocodexs
254 #define X(x) { x, #x },
255 X(IOCTL_CDROM_CHECK_VERIFY
)
256 X(IOCTL_CDROM_CURRENT_POSITION
)
257 X(IOCTL_CDROM_DISK_TYPE
)
258 X(IOCTL_CDROM_GET_CONTROL
)
259 X(IOCTL_CDROM_GET_DRIVE_GEOMETRY
)
260 X(IOCTL_CDROM_GET_VOLUME
)
261 X(IOCTL_CDROM_LOAD_MEDIA
)
262 X(IOCTL_CDROM_MEDIA_CATALOG
)
263 X(IOCTL_CDROM_MEDIA_REMOVAL
)
264 X(IOCTL_CDROM_PAUSE_AUDIO
)
265 X(IOCTL_CDROM_PLAY_AUDIO_MSF
)
266 X(IOCTL_CDROM_RAW_READ
)
267 X(IOCTL_CDROM_READ_Q_CHANNEL
)
268 X(IOCTL_CDROM_READ_TOC
)
269 X(IOCTL_CDROM_RESUME_AUDIO
)
270 X(IOCTL_CDROM_SEEK_AUDIO_MSF
)
271 X(IOCTL_CDROM_SET_VOLUME
)
272 X(IOCTL_CDROM_STOP_AUDIO
)
273 X(IOCTL_CDROM_TRACK_ISRC
)
274 X(IOCTL_DISK_MEDIA_REMOVAL
)
275 X(IOCTL_DVD_END_SESSION
)
276 X(IOCTL_DVD_GET_REGION
)
277 X(IOCTL_DVD_READ_KEY
)
278 X(IOCTL_DVD_READ_STRUCTURE
)
279 X(IOCTL_DVD_SEND_KEY
)
280 X(IOCTL_DVD_START_SESSION
)
281 X(IOCTL_SCSI_GET_ADDRESS
)
282 X(IOCTL_SCSI_GET_CAPABILITIES
)
283 X(IOCTL_SCSI_PASS_THROUGH
)
284 X(IOCTL_SCSI_PASS_THROUGH_DIRECT
)
285 X(IOCTL_STORAGE_CHECK_VERIFY
)
286 X(IOCTL_STORAGE_EJECTION_CONTROL
)
287 X(IOCTL_STORAGE_EJECT_MEDIA
)
288 X(IOCTL_STORAGE_GET_DEVICE_NUMBER
)
289 X(IOCTL_STORAGE_LOAD_MEDIA
)
290 X(IOCTL_STORAGE_MEDIA_REMOVAL
)
291 X(IOCTL_STORAGE_RESET_DEVICE
)
294 static const char *iocodex(DWORD code
)
297 static char buffer
[25];
298 for(i
=0; i
<sizeof(iocodextable
)/sizeof(struct iocodexs
); i
++)
299 if (code
==iocodextable
[i
].code
)
300 return iocodextable
[i
].codex
;
301 sprintf(buffer
, "IOCTL_CODE_%x", (int)code
);
305 WINE_DEFAULT_DEBUG_CHANNEL(cdrom
);
307 #define FRAME_OF_ADDR(a) (((int)(a)[1] * CD_SECS + (a)[2]) * CD_FRAMES + (a)[3])
308 #define FRAME_OF_MSF(a) (((int)(a).M * CD_SECS + (a).S) * CD_FRAMES + (a).F)
309 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
310 #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;}
312 static NTSTATUS
CDROM_ReadTOC(int, int, CDROM_TOC
*);
313 static NTSTATUS
CDROM_GetStatusCode(int);
319 # define IDE6_MAJOR 88
322 # define IDE7_MAJOR 89
325 # ifdef CDROM_SEND_PACKET
326 /* structure for CDROM_PACKET_COMMAND ioctl */
327 /* not all Linux versions have all the fields, so we define the
328 * structure ourselves to make sure */
329 struct linux_cdrom_generic_command
331 unsigned char cmd
[CDROM_PACKET_SIZE
];
332 unsigned char *buffer
;
335 struct request_sense
*sense
;
336 unsigned char data_direction
;
341 # endif /* CDROM_SEND_PACKET */
345 /* FIXME: this is needed because we can't open simultaneously several times /dev/cdrom
346 * this should be removed when a proper device interface is implemented
348 * (WS) We need this to keep track of current position and to safely
349 * detect media changes. Besides this should provide a great speed up
355 char toc_good
; /* if false, will reread TOC from disk */
357 SUB_Q_CURRENT_POSITION CurrentPosition
;
359 /* who has more than 5 cdroms on his/her machine ?? */
360 /* FIXME: this should grow depending on the number of cdroms we install/configure
363 #define MAX_CACHE_ENTRIES 5
364 static struct cdrom_cache cdrom_cache
[MAX_CACHE_ENTRIES
];
366 static RTL_CRITICAL_SECTION cache_section
;
367 static RTL_CRITICAL_SECTION_DEBUG critsect_debug
=
369 0, 0, &cache_section
,
370 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
371 0, 0, { 0, (DWORD
)(__FILE__
": cache_section") }
373 static RTL_CRITICAL_SECTION cache_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
375 /* Proposed media change function: not really needed at this time */
376 /* This is a 1 or 0 type of function */
378 static int CDROM_MediaChanged(int dev
)
382 struct cdrom_tochdr hdr
;
383 struct cdrom_tocentry entry
;
385 if (dev
< 0 || dev
>= MAX_CACHE_ENTRIES
)
387 if ( ioctl(cdrom_cache
[dev
].fd
, CDROMREADTOCHDR
, &hdr
) == -1 )
390 if ( memcmp(&hdr
, &cdrom_cache
[dev
].hdr
, sizeof(struct cdrom_tochdr
)) )
393 for (i
=hdr
.cdth_trk0
; i
<=hdr
.cdth_trk1
+1; i
++)
395 if (i
== hdr
.cdth_trk1
+ 1)
397 entry
.cdte_track
= CDROM_LEADOUT
;
399 entry
.cdte_track
= i
;
401 entry
.cdte_format
= CDROM_MSF
;
402 if ( ioctl(cdrom_cache
[dev
].fd
, CDROMREADTOCENTRY
, &entry
) == -1)
404 if ( memcmp(&entry
, cdrom_cache
[dev
].entry
+i
-hdr
.cdth_trk0
,
405 sizeof(struct cdrom_tocentry
)) )
412 /******************************************************************
413 * CDROM_SyncCache [internal]
415 * Read the TOC in and store it in the cdrom_cache structure.
416 * Further requests for the TOC will be copied from the cache
417 * unless certain events like disk ejection is detected, in which
418 * case the cache will be cleared, causing it to be resynced.
419 * The cache section must be held by caller.
421 static int CDROM_SyncCache(int dev
, int fd
)
425 struct cdrom_tochdr hdr
;
426 struct cdrom_tocentry entry
;
427 #elif defined(__FreeBSD__) || defined(__NetBSD__)
428 struct ioc_toc_header hdr
;
429 struct ioc_read_toc_entry entry
;
430 struct cd_toc_entry toc_buffer
;
432 CDROM_TOC
*toc
= &cdrom_cache
[dev
].toc
;
433 cdrom_cache
[dev
].toc_good
= 0;
437 io
= ioctl(fd
, CDROMREADTOCHDR
, &hdr
);
440 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
444 toc
->FirstTrack
= hdr
.cdth_trk0
;
445 toc
->LastTrack
= hdr
.cdth_trk1
;
446 tsz
= sizeof(toc
->FirstTrack
) + sizeof(toc
->LastTrack
)
447 + sizeof(TRACK_DATA
) * (toc
->LastTrack
-toc
->FirstTrack
+2);
448 toc
->Length
[0] = tsz
>> 8;
449 toc
->Length
[1] = tsz
;
451 TRACE("caching toc from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
453 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
455 if (i
== toc
->LastTrack
+ 1)
456 entry
.cdte_track
= CDROM_LEADOUT
;
458 entry
.cdte_track
= i
;
459 entry
.cdte_format
= CDROM_MSF
;
460 io
= ioctl(fd
, CDROMREADTOCENTRY
, &entry
);
462 WARN("error read entry (%s)\n", strerror(errno
));
465 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= entry
.cdte_ctrl
;
466 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= entry
.cdte_adr
;
467 /* marking last track with leadout value as index */
468 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.cdte_track
;
469 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
470 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = entry
.cdte_addr
.msf
.minute
;
471 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = entry
.cdte_addr
.msf
.second
;
472 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = entry
.cdte_addr
.msf
.frame
;
474 cdrom_cache
[dev
].toc_good
= 1;
476 #elif defined(__FreeBSD__) || defined(__NetBSD__)
478 io
= ioctl(fd
, CDIOREADTOCHEADER
, &hdr
);
481 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
484 toc
->FirstTrack
= hdr
.starting_track
;
485 toc
->LastTrack
= hdr
.ending_track
;
486 tsz
= sizeof(toc
->FirstTrack
) + sizeof(toc
->LastTrack
)
487 + sizeof(TRACK_DATA
) * (toc
->LastTrack
-toc
->FirstTrack
+2);
488 toc
->Length
[0] = tsz
>> 8;
489 toc
->Length
[1] = tsz
;
491 TRACE("caching toc from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
493 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
495 if (i
== toc
->LastTrack
+ 1)
498 entry
.starting_track
= LEADOUT
;
500 entry
.starting_track
= i
;
502 memset((char *)&toc_buffer
, 0, sizeof(toc_buffer
));
503 entry
.address_format
= CD_MSF_FORMAT
;
504 entry
.data_len
= sizeof(toc_buffer
);
505 entry
.data
= &toc_buffer
;
506 io
= ioctl(fd
, CDIOREADTOCENTRYS
, &entry
);
508 WARN("error read entry (%s)\n", strerror(errno
));
511 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= toc_buffer
.control
;
512 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= toc_buffer
.addr_type
;
513 /* marking last track with leadout value as index */
514 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.starting_track
;
515 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
516 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = toc_buffer
.addr
.msf
.minute
;
517 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = toc_buffer
.addr
.msf
.second
;
518 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = toc_buffer
.addr
.msf
.frame
;
520 cdrom_cache
[dev
].toc_good
= 1;
523 return STATUS_NOT_SUPPORTED
;
526 return CDROM_GetStatusCode(io
);
529 static void CDROM_ClearCacheEntry(int dev
)
531 RtlEnterCriticalSection( &cache_section
);
532 cdrom_cache
[dev
].toc_good
= 0;
533 RtlLeaveCriticalSection( &cache_section
);
538 /******************************************************************
539 * CDROM_GetInterfaceInfo
541 * Determines the ide interface (the number after the ide), and the
542 * number of the device on that interface for ide cdroms (*port == 0).
543 * Determines the scsi information for scsi cdroms (*port >= 1).
544 * Returns false if the info cannot not be obtained.
546 static int CDROM_GetInterfaceInfo(int fd
, int* port
, int* iface
, int* device
,int* lun
)
550 if ( fstat(fd
, &st
) == -1 || ! S_ISBLK(st
.st_mode
)) return 0;
555 switch (major(st
.st_rdev
)) {
556 case IDE0_MAJOR
: *iface
= 0; break;
557 case IDE1_MAJOR
: *iface
= 1; break;
558 case IDE2_MAJOR
: *iface
= 2; break;
559 case IDE3_MAJOR
: *iface
= 3; break;
560 case IDE4_MAJOR
: *iface
= 4; break;
561 case IDE5_MAJOR
: *iface
= 5; break;
562 case IDE6_MAJOR
: *iface
= 6; break;
563 case IDE7_MAJOR
: *iface
= 7; break;
564 default: *port
= 1; break;
568 *device
= (minor(st
.st_rdev
) >> 6);
571 #ifdef SCSI_IOCTL_GET_IDLUN
573 if (ioctl(fd
, SCSI_IOCTL_GET_IDLUN
, &idlun
) != -1)
575 *port
= ((idlun
[0] >> 24) & 0xff) + 1;
576 *iface
= (idlun
[0] >> 16) & 0xff;
577 *device
= idlun
[0] & 0xff;
578 *lun
= (idlun
[0] >> 8) & 0xff;
583 WARN("CD-ROM device (%d, %d) not supported\n", major(st
.st_rdev
), minor(st
.st_rdev
));
588 #elif defined(__NetBSD__)
589 struct scsi_addr addr
;
590 if (ioctl(fd
, SCIOCIDENTIFY
, &addr
) != -1)
594 case TYPE_SCSI
: *port
= 1;
595 *iface
= addr
.addr
.scsi
.scbus
;
596 *device
= addr
.addr
.scsi
.target
;
597 *lun
= addr
.addr
.scsi
.lun
;
599 case TYPE_ATAPI
: *port
= 0;
600 *iface
= addr
.addr
.atapi
.atbus
;
601 *device
= addr
.addr
.atapi
.drive
;
608 #elif defined(__FreeBSD__)
609 FIXME("not implemented for BSD\n");
612 FIXME("not implemented for nonlinux\n");
618 /******************************************************************
622 static NTSTATUS
CDROM_Open(int fd
, int* dev
)
625 NTSTATUS ret
= STATUS_SUCCESS
;
630 RtlEnterCriticalSection( &cache_section
);
631 for (*dev
= 0; *dev
< MAX_CACHE_ENTRIES
; (*dev
)++)
634 cdrom_cache
[*dev
].device
== 0 &&
635 cdrom_cache
[*dev
].inode
== 0)
637 else if (cdrom_cache
[*dev
].device
== st
.st_dev
&&
638 cdrom_cache
[*dev
].inode
== st
.st_ino
)
641 if (*dev
== MAX_CACHE_ENTRIES
)
643 if (empty
== -1) ret
= STATUS_NOT_IMPLEMENTED
;
647 cdrom_cache
[*dev
].device
= st
.st_dev
;
648 cdrom_cache
[*dev
].inode
= st
.st_ino
;
651 RtlLeaveCriticalSection( &cache_section
);
653 TRACE("%d, %d\n", *dev
, fd
);
657 /******************************************************************
658 * CDROM_GetStatusCode
662 static NTSTATUS
CDROM_GetStatusCode(int io
)
664 if (io
== 0) return STATUS_SUCCESS
;
665 return FILE_GetNtStatus();
668 /******************************************************************
672 static NTSTATUS
CDROM_GetControl(int dev
, CDROM_AUDIO_CONTROL
* cac
)
674 cac
->LbaFormat
= 0; /* FIXME */
675 cac
->LogicalBlocksPerSecond
= 1; /* FIXME */
676 return STATUS_NOT_SUPPORTED
;
679 /******************************************************************
680 * CDROM_GetDeviceNumber
683 static NTSTATUS
CDROM_GetDeviceNumber(int dev
, STORAGE_DEVICE_NUMBER
* devnum
)
685 return STATUS_NOT_SUPPORTED
;
688 /******************************************************************
689 * CDROM_GetDriveGeometry
692 static NTSTATUS
CDROM_GetDriveGeometry(int dev
, int fd
, DISK_GEOMETRY
* dg
)
698 if ((ret
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return ret
;
700 fsize
= FRAME_OF_TOC(toc
, toc
.LastTrack
+1)
701 - FRAME_OF_TOC(toc
, 1); /* Total size in frames */
703 dg
->Cylinders
.u
.LowPart
= fsize
/ (64 * 32);
704 dg
->Cylinders
.u
.HighPart
= 0;
705 dg
->MediaType
= RemovableMedia
;
706 dg
->TracksPerCylinder
= 64;
707 dg
->SectorsPerTrack
= 32;
708 dg
->BytesPerSector
= 2048;
712 /**************************************************************************
713 * CDROM_Reset [internal]
715 static NTSTATUS
CDROM_ResetAudio(int fd
)
718 return CDROM_GetStatusCode(ioctl(fd
, CDROMRESET
));
719 #elif defined(__FreeBSD__) || defined(__NetBSD__)
720 return CDROM_GetStatusCode(ioctl(fd
, CDIOCRESET
, NULL
));
722 return STATUS_NOT_SUPPORTED
;
726 /******************************************************************
731 static NTSTATUS
CDROM_SetTray(int fd
, BOOL doEject
)
734 return CDROM_GetStatusCode(ioctl(fd
, doEject
? CDROMEJECT
: CDROMCLOSETRAY
));
735 #elif defined(__FreeBSD__) || defined(__NetBSD__)
736 return CDROM_GetStatusCode((ioctl(fd
, CDIOCALLOW
, NULL
)) ||
737 (ioctl(fd
, doEject
? CDIOCEJECT
: CDIOCCLOSE
, NULL
)) ||
738 (ioctl(fd
, CDIOCPREVENT
, NULL
)));
740 return STATUS_NOT_SUPPORTED
;
744 /******************************************************************
745 * CDROM_ControlEjection
749 static NTSTATUS
CDROM_ControlEjection(int fd
, const PREVENT_MEDIA_REMOVAL
* rmv
)
752 return CDROM_GetStatusCode(ioctl(fd
, CDROM_LOCKDOOR
, rmv
->PreventMediaRemoval
));
753 #elif defined(__FreeBSD__) || defined(__NetBSD__)
754 return CDROM_GetStatusCode(ioctl(fd
, (rmv
->PreventMediaRemoval
) ? CDIOCPREVENT
: CDIOCALLOW
, NULL
));
756 return STATUS_NOT_SUPPORTED
;
760 /******************************************************************
765 static NTSTATUS
CDROM_ReadTOC(int dev
, int fd
, CDROM_TOC
* toc
)
767 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
769 if (dev
< 0 || dev
>= MAX_CACHE_ENTRIES
)
770 return STATUS_INVALID_PARAMETER
;
772 RtlEnterCriticalSection( &cache_section
);
773 if (cdrom_cache
[dev
].toc_good
|| !(ret
= CDROM_SyncCache(dev
, fd
)))
775 *toc
= cdrom_cache
[dev
].toc
;
776 ret
= STATUS_SUCCESS
;
778 RtlLeaveCriticalSection( &cache_section
);
782 /******************************************************************
787 static NTSTATUS
CDROM_GetDiskData(int dev
, int fd
, CDROM_DISK_DATA
* data
)
793 if ((ret
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return ret
;
795 for (i
= toc
.FirstTrack
; i
<= toc
.LastTrack
; i
++) {
796 if (toc
.TrackData
[i
-toc
.FirstTrack
].Control
& 0x04)
797 data
->DiskData
|= CDROM_DISK_DATA_TRACK
;
799 data
->DiskData
|= CDROM_DISK_AUDIO_TRACK
;
801 return STATUS_SUCCESS
;
804 /******************************************************************
809 static NTSTATUS
CDROM_ReadQChannel(int dev
, int fd
, const CDROM_SUB_Q_DATA_FORMAT
* fmt
,
810 SUB_Q_CHANNEL_DATA
* data
)
812 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
815 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
817 struct cdrom_subchnl sc
;
818 sc
.cdsc_format
= CDROM_MSF
;
820 io
= ioctl(fd
, CDROMSUBCHNL
, &sc
);
823 TRACE("opened or no_media (%s)!\n", strerror(errno
));
824 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
825 CDROM_ClearCacheEntry(dev
);
829 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
831 switch (sc
.cdsc_audiostatus
) {
832 case CDROM_AUDIO_INVALID
:
833 CDROM_ClearCacheEntry(dev
);
834 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
836 case CDROM_AUDIO_NO_STATUS
:
837 CDROM_ClearCacheEntry(dev
);
838 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
840 case CDROM_AUDIO_PLAY
:
841 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
843 case CDROM_AUDIO_PAUSED
:
844 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
846 case CDROM_AUDIO_COMPLETED
:
847 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
849 case CDROM_AUDIO_ERROR
:
850 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
853 TRACE("status=%02X !\n", sc
.cdsc_audiostatus
);
858 case IOCTL_CDROM_CURRENT_POSITION
:
859 size
= sizeof(SUB_Q_CURRENT_POSITION
);
860 RtlEnterCriticalSection( &cache_section
);
861 if (hdr
->AudioStatus
==AUDIO_STATUS_IN_PROGRESS
) {
862 data
->CurrentPosition
.FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
863 data
->CurrentPosition
.Control
= sc
.cdsc_ctrl
;
864 data
->CurrentPosition
.ADR
= sc
.cdsc_adr
;
865 data
->CurrentPosition
.TrackNumber
= sc
.cdsc_trk
;
866 data
->CurrentPosition
.IndexNumber
= sc
.cdsc_ind
;
868 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
869 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.cdsc_absaddr
.msf
.minute
;
870 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.cdsc_absaddr
.msf
.second
;
871 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.cdsc_absaddr
.msf
.frame
;
873 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
874 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.cdsc_reladdr
.msf
.minute
;
875 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.cdsc_reladdr
.msf
.second
;
876 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.cdsc_reladdr
.msf
.frame
;
878 cdrom_cache
[dev
].CurrentPosition
= data
->CurrentPosition
;
880 else /* not playing */
882 cdrom_cache
[dev
].CurrentPosition
.Header
= *hdr
; /* Preserve header info */
883 data
->CurrentPosition
= cdrom_cache
[dev
].CurrentPosition
;
885 RtlLeaveCriticalSection( &cache_section
);
887 case IOCTL_CDROM_MEDIA_CATALOG
:
888 size
= sizeof(SUB_Q_MEDIA_CATALOG_NUMBER
);
889 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
891 struct cdrom_mcn mcn
;
892 if ((io
= ioctl(fd
, CDROM_GET_MCN
, &mcn
)) == -1) goto end
;
894 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
895 data
->MediaCatalog
.Mcval
= 0; /* FIXME */
896 memcpy(data
->MediaCatalog
.MediaCatalog
, mcn
.medium_catalog_number
, 14);
897 data
->MediaCatalog
.MediaCatalog
[14] = 0;
900 case IOCTL_CDROM_TRACK_ISRC
:
901 size
= sizeof(SUB_Q_CURRENT_POSITION
);
902 FIXME("TrackIsrc: NIY on linux\n");
903 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
904 data
->TrackIsrc
.Tcval
= 0;
910 ret
= CDROM_GetStatusCode(io
);
911 #elif defined(__FreeBSD__) || defined(__NetBSD__)
913 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
915 struct ioc_read_subchannel read_sc
;
916 struct cd_sub_channel_info sc
;
918 read_sc
.address_format
= CD_MSF_FORMAT
;
920 read_sc
.data_len
= sizeof(sc
);
924 case IOCTL_CDROM_CURRENT_POSITION
:
925 read_sc
.data_format
= CD_CURRENT_POSITION
;
927 case IOCTL_CDROM_MEDIA_CATALOG
:
928 read_sc
.data_format
= CD_MEDIA_CATALOG
;
930 case IOCTL_CDROM_TRACK_ISRC
:
931 read_sc
.data_format
= CD_TRACK_INFO
;
932 sc
.what
.track_info
.track_number
= data
->TrackIsrc
.Track
;
935 io
= ioctl(fd
, CDIOCREADSUBCHANNEL
, &read_sc
);
938 TRACE("opened or no_media (%s)!\n", strerror(errno
));
939 CDROM_ClearCacheEntry(dev
);
940 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
944 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
946 switch (sc
.header
.audio_status
) {
947 case CD_AS_AUDIO_INVALID
:
948 CDROM_ClearCacheEntry(dev
);
949 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
951 case CD_AS_NO_STATUS
:
952 CDROM_ClearCacheEntry(dev
);
953 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
955 case CD_AS_PLAY_IN_PROGRESS
:
956 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
958 case CD_AS_PLAY_PAUSED
:
959 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
961 case CD_AS_PLAY_COMPLETED
:
962 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
964 case CD_AS_PLAY_ERROR
:
965 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
968 TRACE("status=%02X !\n", sc
.header
.audio_status
);
972 case IOCTL_CDROM_CURRENT_POSITION
:
973 size
= sizeof(SUB_Q_CURRENT_POSITION
);
974 RtlEnterCriticalSection( &cache_section
);
975 if (hdr
->AudioStatus
==AUDIO_STATUS_IN_PROGRESS
) {
976 data
->CurrentPosition
.FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
977 data
->CurrentPosition
.Control
= sc
.what
.position
.control
;
978 data
->CurrentPosition
.ADR
= sc
.what
.position
.addr_type
;
979 data
->CurrentPosition
.TrackNumber
= sc
.what
.position
.track_number
;
980 data
->CurrentPosition
.IndexNumber
= sc
.what
.position
.index_number
;
982 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
983 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.what
.position
.absaddr
.msf
.minute
;
984 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.what
.position
.absaddr
.msf
.second
;
985 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.what
.position
.absaddr
.msf
.frame
;
986 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
987 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.what
.position
.reladdr
.msf
.minute
;
988 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.what
.position
.reladdr
.msf
.second
;
989 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.what
.position
.reladdr
.msf
.frame
;
990 cdrom_cache
[dev
].CurrentPosition
= data
->CurrentPosition
;
992 else { /* not playing */
993 cdrom_cache
[dev
].CurrentPosition
.Header
= *hdr
; /* Preserve header info */
994 data
->CurrentPosition
= cdrom_cache
[dev
].CurrentPosition
;
996 RtlLeaveCriticalSection( &cache_section
);
998 case IOCTL_CDROM_MEDIA_CATALOG
:
999 size
= sizeof(SUB_Q_MEDIA_CATALOG_NUMBER
);
1000 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
1001 data
->MediaCatalog
.Mcval
= sc
.what
.media_catalog
.mc_valid
;
1002 memcpy(data
->MediaCatalog
.MediaCatalog
, sc
.what
.media_catalog
.mc_number
, 15);
1004 case IOCTL_CDROM_TRACK_ISRC
:
1005 size
= sizeof(SUB_Q_CURRENT_POSITION
);
1006 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
1007 data
->TrackIsrc
.Tcval
= sc
.what
.track_info
.ti_valid
;
1008 memcpy(data
->TrackIsrc
.TrackIsrc
, sc
.what
.track_info
.ti_number
, 15);
1013 ret
= CDROM_GetStatusCode(io
);
1018 /******************************************************************
1023 static NTSTATUS
CDROM_Verify(int dev
, int fd
)
1025 /* quick implementation */
1026 CDROM_SUB_Q_DATA_FORMAT fmt
;
1027 SUB_Q_CHANNEL_DATA data
;
1029 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
1030 return CDROM_ReadQChannel(dev
, fd
, &fmt
, &data
) ? 1 : 0;
1033 /******************************************************************
1034 * CDROM_PlayAudioMSF
1038 static NTSTATUS
CDROM_PlayAudioMSF(int fd
, const CDROM_PLAY_AUDIO_MSF
* audio_msf
)
1040 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1042 struct cdrom_msf msf
;
1045 msf
.cdmsf_min0
= audio_msf
->StartingM
;
1046 msf
.cdmsf_sec0
= audio_msf
->StartingS
;
1047 msf
.cdmsf_frame0
= audio_msf
->StartingF
;
1048 msf
.cdmsf_min1
= audio_msf
->EndingM
;
1049 msf
.cdmsf_sec1
= audio_msf
->EndingS
;
1050 msf
.cdmsf_frame1
= audio_msf
->EndingF
;
1052 io
= ioctl(fd
, CDROMSTART
);
1055 WARN("motor doesn't start !\n");
1058 io
= ioctl(fd
, CDROMPLAYMSF
, &msf
);
1061 WARN("device doesn't play !\n");
1064 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1065 msf
.cdmsf_min0
, msf
.cdmsf_sec0
, msf
.cdmsf_frame0
,
1066 msf
.cdmsf_min1
, msf
.cdmsf_sec1
, msf
.cdmsf_frame1
);
1068 ret
= CDROM_GetStatusCode(io
);
1069 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1070 struct ioc_play_msf msf
;
1073 msf
.start_m
= audio_msf
->StartingM
;
1074 msf
.start_s
= audio_msf
->StartingS
;
1075 msf
.start_f
= audio_msf
->StartingF
;
1076 msf
.end_m
= audio_msf
->EndingM
;
1077 msf
.end_s
= audio_msf
->EndingS
;
1078 msf
.end_f
= audio_msf
->EndingF
;
1080 io
= ioctl(fd
, CDIOCSTART
, NULL
);
1083 WARN("motor doesn't start !\n");
1086 io
= ioctl(fd
, CDIOCPLAYMSF
, &msf
);
1089 WARN("device doesn't play !\n");
1092 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1093 msf
.start_m
, msf
.start_s
, msf
.start_f
,
1094 msf
.end_m
, msf
.end_s
, msf
.end_f
);
1096 ret
= CDROM_GetStatusCode(io
);
1101 /******************************************************************
1102 * CDROM_SeekAudioMSF
1106 static NTSTATUS
CDROM_SeekAudioMSF(int dev
, int fd
, const CDROM_SEEK_AUDIO_MSF
* audio_msf
)
1110 SUB_Q_CURRENT_POSITION
*cp
;
1112 struct cdrom_msf0 msf
;
1113 struct cdrom_subchnl sc
;
1114 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1115 struct ioc_play_msf msf
;
1116 struct ioc_read_subchannel read_sc
;
1117 struct cd_sub_channel_info sc
;
1121 /* Use the information on the TOC to compute the new current
1122 * position, which is shadowed on the cache. [Portable]. */
1123 frame
= FRAME_OF_MSF(*audio_msf
);
1125 if ((io
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return io
;
1127 for(i
=toc
.FirstTrack
;i
<=toc
.LastTrack
+1;i
++)
1128 if (FRAME_OF_TOC(toc
,i
)>frame
) break;
1129 if (i
<= toc
.FirstTrack
|| i
> toc
.LastTrack
+1)
1130 return STATUS_INVALID_PARAMETER
;
1132 RtlEnterCriticalSection( &cache_section
);
1133 cp
= &cdrom_cache
[dev
].CurrentPosition
;
1134 cp
->FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
1135 cp
->Control
= toc
.TrackData
[i
-toc
.FirstTrack
].Control
;
1136 cp
->ADR
= toc
.TrackData
[i
-toc
.FirstTrack
].Adr
;
1137 cp
->TrackNumber
= toc
.TrackData
[i
-toc
.FirstTrack
].TrackNumber
;
1138 cp
->IndexNumber
= 0; /* FIXME: where do they keep these? */
1139 cp
->AbsoluteAddress
[0] = 0;
1140 cp
->AbsoluteAddress
[1] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[1];
1141 cp
->AbsoluteAddress
[2] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[2];
1142 cp
->AbsoluteAddress
[3] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[3];
1143 frame
-= FRAME_OF_TOC(toc
,i
);
1144 cp
->TrackRelativeAddress
[0] = 0;
1145 MSF_OF_FRAME(cp
->TrackRelativeAddress
[1], frame
);
1146 RtlLeaveCriticalSection( &cache_section
);
1148 /* If playing, then issue a seek command, otherwise do nothing */
1150 sc
.cdsc_format
= CDROM_MSF
;
1152 io
= ioctl(fd
, CDROMSUBCHNL
, &sc
);
1155 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1156 CDROM_ClearCacheEntry(dev
);
1157 return CDROM_GetStatusCode(io
);
1159 if (sc
.cdsc_audiostatus
==CDROM_AUDIO_PLAY
)
1161 msf
.minute
= audio_msf
->M
;
1162 msf
.second
= audio_msf
->S
;
1163 msf
.frame
= audio_msf
->F
;
1164 return CDROM_GetStatusCode(ioctl(fd
, CDROMSEEK
, &msf
));
1166 return STATUS_SUCCESS
;
1167 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1168 read_sc
.address_format
= CD_MSF_FORMAT
;
1170 read_sc
.data_len
= sizeof(sc
);
1172 read_sc
.data_format
= CD_CURRENT_POSITION
;
1174 io
= ioctl(fd
, CDIOCREADSUBCHANNEL
, &read_sc
);
1177 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1178 CDROM_ClearCacheEntry(dev
);
1179 return CDROM_GetStatusCode(io
);
1181 if (sc
.header
.audio_status
==CD_AS_PLAY_IN_PROGRESS
)
1184 msf
.start_m
= audio_msf
->M
;
1185 msf
.start_s
= audio_msf
->S
;
1186 msf
.start_f
= audio_msf
->F
;
1187 final_frame
= FRAME_OF_TOC(toc
,toc
.LastTrack
+1)-1;
1188 MSF_OF_FRAME(msf
.end_m
, final_frame
);
1190 return CDROM_GetStatusCode(ioctl(fd
, CDIOCPLAYMSF
, &msf
));
1192 return STATUS_SUCCESS
;
1194 return STATUS_NOT_SUPPORTED
;
1198 /******************************************************************
1203 static NTSTATUS
CDROM_PauseAudio(int fd
)
1206 return CDROM_GetStatusCode(ioctl(fd
, CDROMPAUSE
));
1207 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1208 return CDROM_GetStatusCode(ioctl(fd
, CDIOCPAUSE
, NULL
));
1210 return STATUS_NOT_SUPPORTED
;
1214 /******************************************************************
1219 static NTSTATUS
CDROM_ResumeAudio(int fd
)
1222 return CDROM_GetStatusCode(ioctl(fd
, CDROMRESUME
));
1223 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1224 return CDROM_GetStatusCode(ioctl(fd
, CDIOCRESUME
, NULL
));
1226 return STATUS_NOT_SUPPORTED
;
1230 /******************************************************************
1235 static NTSTATUS
CDROM_StopAudio(int fd
)
1238 return CDROM_GetStatusCode(ioctl(fd
, CDROMSTOP
));
1239 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1240 return CDROM_GetStatusCode(ioctl(fd
, CDIOCSTOP
, NULL
));
1242 return STATUS_NOT_SUPPORTED
;
1246 /******************************************************************
1251 static NTSTATUS
CDROM_GetVolume(int fd
, VOLUME_CONTROL
* vc
)
1254 struct cdrom_volctrl volc
;
1257 io
= ioctl(fd
, CDROMVOLREAD
, &volc
);
1260 vc
->PortVolume
[0] = volc
.channel0
;
1261 vc
->PortVolume
[1] = volc
.channel1
;
1262 vc
->PortVolume
[2] = volc
.channel2
;
1263 vc
->PortVolume
[3] = volc
.channel3
;
1265 return CDROM_GetStatusCode(io
);
1266 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1267 struct ioc_vol volc
;
1270 io
= ioctl(fd
, CDIOCGETVOL
, &volc
);
1273 vc
->PortVolume
[0] = volc
.vol
[0];
1274 vc
->PortVolume
[1] = volc
.vol
[1];
1275 vc
->PortVolume
[2] = volc
.vol
[2];
1276 vc
->PortVolume
[3] = volc
.vol
[3];
1278 return CDROM_GetStatusCode(io
);
1280 return STATUS_NOT_SUPPORTED
;
1284 /******************************************************************
1289 static NTSTATUS
CDROM_SetVolume(int fd
, const VOLUME_CONTROL
* vc
)
1292 struct cdrom_volctrl volc
;
1294 volc
.channel0
= vc
->PortVolume
[0];
1295 volc
.channel1
= vc
->PortVolume
[1];
1296 volc
.channel2
= vc
->PortVolume
[2];
1297 volc
.channel3
= vc
->PortVolume
[3];
1299 return CDROM_GetStatusCode(ioctl(fd
, CDROMVOLCTRL
, &volc
));
1300 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1301 struct ioc_vol volc
;
1303 volc
.vol
[0] = vc
->PortVolume
[0];
1304 volc
.vol
[1] = vc
->PortVolume
[1];
1305 volc
.vol
[2] = vc
->PortVolume
[2];
1306 volc
.vol
[3] = vc
->PortVolume
[3];
1308 return CDROM_GetStatusCode(ioctl(fd
, CDIOCSETVOL
, &volc
));
1310 return STATUS_NOT_SUPPORTED
;
1314 /******************************************************************
1319 static NTSTATUS
CDROM_RawRead(int fd
, const RAW_READ_INFO
* raw
, void* buffer
, DWORD len
, DWORD
* sz
)
1321 int ret
= STATUS_NOT_SUPPORTED
;
1325 switch (raw
->TrackMode
)
1327 case YellowMode2
: sectSize
= 2336; break;
1328 case XAForm2
: sectSize
= 2328; break;
1329 case CDDA
: sectSize
= 2352; break;
1330 default: return STATUS_INVALID_PARAMETER
;
1332 if (len
< raw
->SectorCount
* sectSize
) return STATUS_BUFFER_TOO_SMALL
;
1333 /* strangely enough, it seems that sector offsets are always indicated with a size of 2048,
1334 * even if a larger size if read...
1338 struct cdrom_read cdr
;
1339 struct cdrom_read_audio cdra
;
1341 switch (raw
->TrackMode
)
1344 if (raw
->DiskOffset
.u
.HighPart
) FIXME("Unsupported value\n");
1345 cdr
.cdread_lba
= raw
->DiskOffset
.u
.LowPart
; /* FIXME ? */
1346 cdr
.cdread_bufaddr
= buffer
;
1347 cdr
.cdread_buflen
= raw
->SectorCount
* sectSize
;
1348 io
= ioctl(fd
, CDROMREADMODE2
, &cdr
);
1351 FIXME("XAForm2: NIY\n");
1354 /* FIXME: the output doesn't seem 100% correct... in fact output is shifted
1355 * between by NT2K box and this... should check on the same drive...
1356 * otherwise, I fear a 2352/2368 mismatch somewhere in one of the drivers
1358 * Anyway, that's not critical at all. We're talking of 16/32 bytes, we're
1359 * talking of 0.2 ms of sound
1361 /* 2048 = 2 ** 11 */
1362 if (raw
->DiskOffset
.u
.HighPart
& ~2047) FIXME("Unsupported value\n");
1363 cdra
.addr
.lba
= ((raw
->DiskOffset
.u
.LowPart
>> 11) |
1364 (raw
->DiskOffset
.u
.HighPart
<< (32 - 11))) - 1;
1365 FIXME("reading at %u\n", cdra
.addr
.lba
);
1366 cdra
.addr_format
= CDROM_LBA
;
1367 cdra
.nframes
= raw
->SectorCount
;
1369 io
= ioctl(fd
, CDROMREADAUDIO
, &cdra
);
1372 FIXME("NIY: %d\n", raw
->TrackMode
);
1378 switch (raw
->TrackMode
)
1381 FIXME("YellowMode2: NIY\n");
1384 FIXME("XAForm2: NIY\n");
1387 FIXME("CDDA: NIY\n");
1393 *sz
= sectSize
* raw
->SectorCount
;
1394 ret
= CDROM_GetStatusCode(io
);
1398 /******************************************************************
1399 * CDROM_ScsiPassThroughDirect
1400 * Implements IOCTL_SCSI_PASS_THROUGH_DIRECT
1403 static NTSTATUS
CDROM_ScsiPassThroughDirect(int fd
, PSCSI_PASS_THROUGH_DIRECT pPacket
)
1405 int ret
= STATUS_NOT_SUPPORTED
;
1406 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1408 #elif defined HAVE_SCSIREQ_T_CMD
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 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1426 RtlZeroMemory(&cmd
, sizeof(cmd
));
1428 cmd
.interface_id
= 'S';
1429 cmd
.cmd_len
= pPacket
->CdbLength
;
1430 cmd
.mx_sb_len
= pPacket
->SenseInfoLength
;
1431 cmd
.dxfer_len
= pPacket
->DataTransferLength
;
1432 cmd
.dxferp
= pPacket
->DataBuffer
;
1433 cmd
.cmdp
= pPacket
->Cdb
;
1434 cmd
.sbp
= (char*)pPacket
+ pPacket
->SenseInfoOffset
;
1435 cmd
.timeout
= pPacket
->TimeOutValue
*1000;
1437 switch (pPacket
->DataIn
)
1439 case SCSI_IOCTL_DATA_IN
:
1440 cmd
.dxfer_direction
= SG_DXFER_TO_DEV
;
1442 case SCSI_IOCTL_DATA_OUT
:
1443 cmd
.dxfer_direction
= SG_DXFER_FROM_DEV
;
1445 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1446 cmd
.dxfer_direction
= SG_DXFER_NONE
;
1449 return STATUS_INVALID_PARAMETER
;
1452 io
= ioctl(fd
, SG_IO
, &cmd
);
1454 pPacket
->ScsiStatus
= cmd
.status
;
1455 pPacket
->DataTransferLength
= cmd
.resid
;
1456 pPacket
->SenseInfoLength
= cmd
.sb_len_wr
;
1458 ret
= CDROM_GetStatusCode(io
);
1460 #elif defined HAVE_SCSIREQ_T_CMD
1462 memset(&cmd
, 0, sizeof(cmd
));
1463 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1465 cmd
.cmdlen
= pPacket
->CdbLength
;
1466 cmd
.databuf
= pPacket
->DataBuffer
;
1467 cmd
.datalen
= pPacket
->DataTransferLength
;
1468 cmd
.senselen
= pPacket
->SenseInfoLength
;
1469 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1471 switch (pPacket
->DataIn
)
1473 case SCSI_IOCTL_DATA_OUT
:
1474 cmd
.flags
|= SCCMD_WRITE
;
1476 case SCSI_IOCTL_DATA_IN
:
1477 cmd
.flags
|= SCCMD_READ
;
1479 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1483 return STATUS_INVALID_PARAMETER
;
1486 io
= ioctl(fd
, SCIOCCOMMAND
, &cmd
);
1490 case SCCMD_OK
: break;
1491 case SCCMD_TIMEOUT
: return STATUS_TIMEOUT
;
1493 case SCCMD_BUSY
: return STATUS_DEVICE_BUSY
;
1495 case SCCMD_SENSE
: break;
1496 case SCCMD_UNKNOWN
: return STATUS_UNSUCCESSFUL
;
1500 if (pPacket
->SenseInfoLength
!= 0)
1502 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1503 cmd
.sense
, pPacket
->SenseInfoLength
);
1506 pPacket
->ScsiStatus
= cmd
.status
;
1508 ret
= CDROM_GetStatusCode(io
);
1513 /******************************************************************
1514 * CDROM_ScsiPassThrough
1515 * Implements IOCTL_SCSI_PASS_THROUGH
1518 static NTSTATUS
CDROM_ScsiPassThrough(int fd
, PSCSI_PASS_THROUGH pPacket
)
1520 int ret
= STATUS_NOT_SUPPORTED
;
1521 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1523 #elif defined HAVE_SCSIREQ_T_CMD
1528 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH
))
1529 return STATUS_BUFFER_TOO_SMALL
;
1531 if (pPacket
->CdbLength
> 16)
1532 return STATUS_INVALID_PARAMETER
;
1534 if (pPacket
->SenseInfoLength
> sizeof(struct request_sense
))
1535 return STATUS_INVALID_PARAMETER
;
1537 if (pPacket
->DataTransferLength
> 0 && pPacket
->DataBufferOffset
< sizeof(SCSI_PASS_THROUGH
))
1538 return STATUS_INVALID_PARAMETER
;
1540 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1541 RtlZeroMemory(&cmd
, sizeof(cmd
));
1543 cmd
.interface_id
= 'S';
1544 cmd
.dxfer_len
= pPacket
->DataTransferLength
;
1545 cmd
.dxferp
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1546 cmd
.cmd_len
= pPacket
->CdbLength
;
1547 cmd
.cmdp
= pPacket
->Cdb
;
1548 cmd
.mx_sb_len
= pPacket
->SenseInfoLength
;
1549 cmd
.timeout
= pPacket
->TimeOutValue
*1000;
1551 if(cmd
.mx_sb_len
> 0)
1552 cmd
.sbp
= (char*)pPacket
+ pPacket
->SenseInfoOffset
;
1554 switch (pPacket
->DataIn
)
1556 case SCSI_IOCTL_DATA_IN
:
1557 cmd
.dxfer_direction
= SG_DXFER_TO_DEV
;
1559 case SCSI_IOCTL_DATA_OUT
:
1560 cmd
.dxfer_direction
= SG_DXFER_FROM_DEV
;
1562 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1563 cmd
.dxfer_direction
= SG_DXFER_NONE
;
1566 return STATUS_INVALID_PARAMETER
;
1569 io
= ioctl(fd
, SG_IO
, &cmd
);
1571 pPacket
->ScsiStatus
= cmd
.status
;
1572 pPacket
->DataTransferLength
= cmd
.resid
;
1573 pPacket
->SenseInfoLength
= cmd
.sb_len_wr
;
1575 ret
= CDROM_GetStatusCode(io
);
1577 #elif defined HAVE_SCSIREQ_T_CMD
1579 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH
))
1580 return STATUS_BUFFER_TOO_SMALL
;
1582 if (pPacket
->CdbLength
> 12)
1583 return STATUS_INVALID_PARAMETER
;
1585 if (pPacket
->SenseInfoLength
> SENSEBUFLEN
)
1586 return STATUS_INVALID_PARAMETER
;
1588 memset(&cmd
, 0, sizeof(cmd
));
1589 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1591 if ( pPacket
->DataBufferOffset
> 0x1000 )
1593 cmd
.databuf
= (void*)pPacket
->DataBufferOffset
;
1597 cmd
.databuf
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1600 cmd
.cmdlen
= pPacket
->CdbLength
;
1601 cmd
.datalen
= pPacket
->DataTransferLength
;
1602 cmd
.senselen
= pPacket
->SenseInfoLength
;
1603 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1605 switch (pPacket
->DataIn
)
1607 case SCSI_IOCTL_DATA_OUT
:
1608 cmd
.flags
|= SCCMD_WRITE
;
1610 case SCSI_IOCTL_DATA_IN
:
1611 cmd
.flags
|= SCCMD_READ
;
1613 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1617 return STATUS_INVALID_PARAMETER
;
1620 io
= ioctl(fd
, SCIOCCOMMAND
, &cmd
);
1624 case SCCMD_OK
: break;
1625 case SCCMD_TIMEOUT
: return STATUS_TIMEOUT
;
1627 case SCCMD_BUSY
: return STATUS_DEVICE_BUSY
;
1629 case SCCMD_SENSE
: break;
1630 case SCCMD_UNKNOWN
: return STATUS_UNSUCCESSFUL
;
1634 if (pPacket
->SenseInfoLength
!= 0)
1636 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1637 cmd
.sense
, pPacket
->SenseInfoLength
);
1640 pPacket
->ScsiStatus
= cmd
.status
;
1642 ret
= CDROM_GetStatusCode(io
);
1647 /******************************************************************
1652 static NTSTATUS
CDROM_ScsiGetCaps(PIO_SCSI_CAPABILITIES caps
)
1654 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
1656 caps
->Length
= sizeof(*caps
);
1657 #ifdef SG_SCATTER_SZ
1658 caps
->MaximumTransferLength
= SG_SCATTER_SZ
; /* FIXME */
1659 caps
->MaximumPhysicalPages
= SG_SCATTER_SZ
/ getpagesize();
1660 caps
->SupportedAsynchronousEvents
= TRUE
;
1661 caps
->AlignmentMask
= getpagesize();
1662 caps
->TaggedQueuing
= FALSE
; /* we could check that it works and answer TRUE */
1663 caps
->AdapterScansDown
= FALSE
; /* FIXME ? */
1664 caps
->AdapterUsesPio
= FALSE
; /* FIXME ? */
1665 ret
= STATUS_SUCCESS
;
1667 FIXME("Unimplemented\n");
1672 /******************************************************************
1675 * implements IOCTL_SCSI_GET_ADDRESS
1677 static NTSTATUS
CDROM_GetAddress(int fd
, SCSI_ADDRESS
* address
)
1679 int portnum
, busid
, targetid
, lun
;
1681 address
->Length
= sizeof(SCSI_ADDRESS
);
1682 if ( ! CDROM_GetInterfaceInfo(fd
, &portnum
, &busid
, &targetid
, &lun
))
1683 return STATUS_NOT_SUPPORTED
;
1685 address
->PortNumber
= portnum
;
1686 address
->PathId
= busid
; /* bus number */
1687 address
->TargetId
= targetid
;
1689 return STATUS_SUCCESS
;
1692 /******************************************************************
1697 static NTSTATUS
DVD_StartSession(int fd
, PDVD_SESSION_ID sid_in
, PDVD_SESSION_ID sid_out
)
1700 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1701 dvd_authinfo auth_info
;
1703 memset( &auth_info
, 0, sizeof( auth_info
) );
1704 auth_info
.type
= DVD_LU_SEND_AGID
;
1705 if (sid_in
) auth_info
.lsa
.agid
= *(int*)sid_in
; /* ?*/
1707 TRACE("fd 0x%08x\n",fd
);
1708 ret
=CDROM_GetStatusCode(ioctl(fd
, DVD_AUTH
, &auth_info
));
1709 *sid_out
= auth_info
.lsa
.agid
;
1711 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1712 return STATUS_NOT_SUPPORTED
;
1714 return STATUS_NOT_SUPPORTED
;
1718 /******************************************************************
1723 static NTSTATUS
DVD_EndSession(int fd
, PDVD_SESSION_ID sid
)
1726 dvd_authinfo auth_info
;
1728 memset( &auth_info
, 0, sizeof( auth_info
) );
1729 auth_info
.type
= DVD_INVALIDATE_AGID
;
1730 auth_info
.lsa
.agid
= *(int*)sid
;
1733 return CDROM_GetStatusCode(ioctl(fd
, DVD_AUTH
, &auth_info
));
1734 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1735 return STATUS_NOT_SUPPORTED
;
1737 return STATUS_NOT_SUPPORTED
;
1741 /******************************************************************
1746 static NTSTATUS
DVD_SendKey(int fd
, PDVD_COPY_PROTECT_KEY key
)
1749 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1750 dvd_authinfo auth_info
;
1752 memset( &auth_info
, 0, sizeof( auth_info
) );
1753 switch (key
->KeyType
)
1755 case DvdChallengeKey
:
1756 auth_info
.type
= DVD_HOST_SEND_CHALLENGE
;
1757 auth_info
.hsc
.agid
= (int)key
->SessionId
;
1758 TRACE("DvdChallengeKey ioc 0x%x\n", DVD_AUTH
);
1759 memcpy( auth_info
.hsc
.chal
, key
->KeyData
, DVD_CHALLENGE_SIZE
);
1760 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1763 auth_info
.type
= DVD_HOST_SEND_KEY2
;
1764 auth_info
.hsk
.agid
= (int)key
->SessionId
;
1766 memcpy( auth_info
.hsk
.key
, key
->KeyData
, DVD_KEY_SIZE
);
1768 TRACE("DvdBusKey2\n");
1769 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1773 FIXME("Unknown Keytype 0x%x\n",key
->KeyType
);
1776 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1778 return STATUS_NOT_SUPPORTED
;
1781 return STATUS_NOT_SUPPORTED
;
1783 TRACE("not reached\n");
1786 /******************************************************************
1791 static NTSTATUS
DVD_ReadKey(int fd
, PDVD_COPY_PROTECT_KEY key
)
1794 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1796 dvd_authinfo auth_info
;
1798 memset( &dvd
, 0, sizeof( dvd_struct
) );
1799 memset( &auth_info
, 0, sizeof( auth_info
) );
1800 switch (key
->KeyType
)
1804 dvd
.type
= DVD_STRUCT_DISCKEY
;
1805 dvd
.disckey
.agid
= (int)key
->SessionId
;
1806 memset( dvd
.disckey
.value
, 0, DVD_DISCKEY_SIZE
);
1808 TRACE("DvdDiskKey\n");
1809 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_READ_STRUCT
, &dvd
));
1810 if (ret
== STATUS_SUCCESS
)
1811 memcpy(key
->KeyData
,dvd
.disckey
.value
,DVD_DISCKEY_SIZE
);
1814 auth_info
.type
= DVD_LU_SEND_TITLE_KEY
;
1815 auth_info
.lstk
.agid
= (int)key
->SessionId
;
1816 auth_info
.lstk
.lba
= (int)(key
->Parameters
.TitleOffset
.QuadPart
>>11);
1817 TRACE("DvdTitleKey session %d Quadpart 0x%08lx offset 0x%08x\n",
1818 (int)key
->SessionId
, (long)key
->Parameters
.TitleOffset
.QuadPart
,
1819 auth_info
.lstk
.lba
);
1820 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1821 if (ret
== STATUS_SUCCESS
)
1822 memcpy(key
->KeyData
, auth_info
.lstk
.title_key
, DVD_KEY_SIZE
);
1824 case DvdChallengeKey
:
1826 auth_info
.type
= DVD_LU_SEND_CHALLENGE
;
1827 auth_info
.lsc
.agid
= (int)key
->SessionId
;
1829 TRACE("DvdChallengeKey\n");
1830 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1831 if (ret
== STATUS_SUCCESS
)
1832 memcpy( key
->KeyData
, auth_info
.lsc
.chal
, DVD_CHALLENGE_SIZE
);
1835 auth_info
.type
= DVD_LU_SEND_ASF
;
1837 auth_info
.lsasf
.asf
=((PDVD_ASF
)key
->KeyData
)->SuccessFlag
;
1838 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1839 ((PDVD_ASF
)key
->KeyData
)->SuccessFlag
= auth_info
.lsasf
.asf
;
1842 auth_info
.type
= DVD_LU_SEND_KEY1
;
1843 auth_info
.lsk
.agid
= (int)key
->SessionId
;
1845 TRACE("DvdBusKey1\n");
1846 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1848 if (ret
== STATUS_SUCCESS
)
1849 memcpy( key
->KeyData
, auth_info
.lsk
.key
, DVD_KEY_SIZE
);
1852 auth_info
.type
= DVD_LU_SEND_RPC_STATE
;
1854 TRACE("DvdGetRpcKey\n");
1855 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1857 if (ret
== STATUS_SUCCESS
)
1859 ((PDVD_RPC_KEY
)key
->KeyData
)->TypeCode
= auth_info
.lrpcs
.type
;
1860 ((PDVD_RPC_KEY
)key
->KeyData
)->RegionMask
= auth_info
.lrpcs
.region_mask
;
1861 ((PDVD_RPC_KEY
)key
->KeyData
)->RpcScheme
= auth_info
.lrpcs
.rpc_scheme
;
1865 FIXME("Unknown keytype 0x%x\n",key
->KeyType
);
1868 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1870 return STATUS_NOT_SUPPORTED
;
1873 return STATUS_NOT_SUPPORTED
;
1875 TRACE("not reached\n");
1878 /******************************************************************
1883 static NTSTATUS
DVD_GetRegion(int dev
, PDVD_REGION region
)
1886 return STATUS_SUCCESS
;
1890 /******************************************************************
1895 static NTSTATUS
DVD_ReadStructure(int dev
, PDVD_READ_STRUCTURE structure
, PDVD_LAYER_DESCRIPTOR layer
)
1898 return STATUS_SUCCESS
;
1901 /******************************************************************
1902 * CDROM_DeviceIoControl
1906 NTSTATUS
CDROM_DeviceIoControl(HANDLE hDevice
,
1907 HANDLE hEvent
, PIO_APC_ROUTINE UserApcRoutine
,
1908 PVOID UserApcContext
,
1909 PIO_STATUS_BLOCK piosb
,
1910 ULONG dwIoControlCode
,
1911 LPVOID lpInBuffer
, DWORD nInBufferSize
,
1912 LPVOID lpOutBuffer
, DWORD nOutBufferSize
)
1915 NTSTATUS status
= STATUS_SUCCESS
;
1918 TRACE("%lx %s %lx %ld %lx %ld %p\n",
1919 (DWORD
)hDevice
, iocodex(dwIoControlCode
), (DWORD
)lpInBuffer
, nInBufferSize
,
1920 (DWORD
)lpOutBuffer
, nOutBufferSize
, piosb
);
1922 piosb
->Information
= 0;
1924 if ((status
= wine_server_handle_to_fd( hDevice
, 0, &fd
, NULL
))) goto error
;
1925 if ((status
= CDROM_Open(fd
, &dev
)))
1927 wine_server_release_fd( hDevice
, fd
);
1931 switch (dwIoControlCode
)
1933 case IOCTL_STORAGE_CHECK_VERIFY
:
1934 case IOCTL_CDROM_CHECK_VERIFY
:
1936 CDROM_ClearCacheEntry(dev
);
1937 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1938 status
= STATUS_INVALID_PARAMETER
;
1939 else status
= CDROM_Verify(dev
, fd
);
1942 /* EPP case IOCTL_STORAGE_CHECK_VERIFY2: */
1944 /* EPP case IOCTL_STORAGE_FIND_NEW_DEVICES: */
1945 /* EPP case IOCTL_CDROM_FIND_NEW_DEVICES: */
1947 case IOCTL_STORAGE_LOAD_MEDIA
:
1948 case IOCTL_CDROM_LOAD_MEDIA
:
1950 CDROM_ClearCacheEntry(dev
);
1951 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1952 status
= STATUS_INVALID_PARAMETER
;
1953 else status
= CDROM_SetTray(fd
, FALSE
);
1955 case IOCTL_STORAGE_EJECT_MEDIA
:
1957 CDROM_ClearCacheEntry(dev
);
1958 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1959 status
= STATUS_INVALID_PARAMETER
;
1960 else status
= CDROM_SetTray(fd
, TRUE
);
1963 case IOCTL_CDROM_MEDIA_REMOVAL
:
1964 case IOCTL_DISK_MEDIA_REMOVAL
:
1965 case IOCTL_STORAGE_MEDIA_REMOVAL
:
1966 case IOCTL_STORAGE_EJECTION_CONTROL
:
1967 /* FIXME the last ioctl:s is not the same as the two others...
1968 * lockcount/owner should be handled */
1970 CDROM_ClearCacheEntry(dev
);
1971 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
1972 else if (nInBufferSize
< sizeof(PREVENT_MEDIA_REMOVAL
)) status
= STATUS_BUFFER_TOO_SMALL
;
1973 else status
= CDROM_ControlEjection(fd
, (const PREVENT_MEDIA_REMOVAL
*)lpInBuffer
);
1976 /* EPP case IOCTL_STORAGE_GET_MEDIA_TYPES: */
1978 case IOCTL_STORAGE_GET_DEVICE_NUMBER
:
1979 sz
= sizeof(STORAGE_DEVICE_NUMBER
);
1980 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
1981 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
1982 else status
= CDROM_GetDeviceNumber(dev
, (STORAGE_DEVICE_NUMBER
*)lpOutBuffer
);
1985 case IOCTL_STORAGE_RESET_DEVICE
:
1987 CDROM_ClearCacheEntry(dev
);
1988 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1989 status
= STATUS_INVALID_PARAMETER
;
1990 else status
= CDROM_ResetAudio(fd
);
1993 case IOCTL_CDROM_GET_CONTROL
:
1994 sz
= sizeof(CDROM_AUDIO_CONTROL
);
1995 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
1996 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
1997 else status
= CDROM_GetControl(dev
, (CDROM_AUDIO_CONTROL
*)lpOutBuffer
);
2000 case IOCTL_CDROM_GET_DRIVE_GEOMETRY
:
2001 sz
= sizeof(DISK_GEOMETRY
);
2002 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2003 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2004 else status
= CDROM_GetDriveGeometry(dev
, fd
, (DISK_GEOMETRY
*)lpOutBuffer
);
2007 case IOCTL_CDROM_DISK_TYPE
:
2008 sz
= sizeof(CDROM_DISK_DATA
);
2009 /* CDROM_ClearCacheEntry(dev); */
2010 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2011 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2012 else status
= CDROM_GetDiskData(dev
, fd
, (CDROM_DISK_DATA
*)lpOutBuffer
);
2015 /* EPP case IOCTL_CDROM_GET_LAST_SESSION: */
2017 case IOCTL_CDROM_READ_Q_CHANNEL
:
2018 sz
= sizeof(SUB_Q_CHANNEL_DATA
);
2019 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(CDROM_SUB_Q_DATA_FORMAT
))
2020 status
= STATUS_INVALID_PARAMETER
;
2021 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2022 else status
= CDROM_ReadQChannel(dev
, fd
, (const CDROM_SUB_Q_DATA_FORMAT
*)lpInBuffer
,
2023 (SUB_Q_CHANNEL_DATA
*)lpOutBuffer
);
2026 case IOCTL_CDROM_READ_TOC
:
2027 sz
= sizeof(CDROM_TOC
);
2028 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2029 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2030 else status
= CDROM_ReadTOC(dev
, fd
, (CDROM_TOC
*)lpOutBuffer
);
2033 /* EPP case IOCTL_CDROM_READ_TOC_EX: */
2035 case IOCTL_CDROM_PAUSE_AUDIO
:
2037 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2038 status
= STATUS_INVALID_PARAMETER
;
2039 else status
= CDROM_PauseAudio(fd
);
2041 case IOCTL_CDROM_PLAY_AUDIO_MSF
:
2043 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2044 else if (nInBufferSize
< sizeof(CDROM_PLAY_AUDIO_MSF
)) status
= STATUS_BUFFER_TOO_SMALL
;
2045 else status
= CDROM_PlayAudioMSF(fd
, (const CDROM_PLAY_AUDIO_MSF
*)lpInBuffer
);
2047 case IOCTL_CDROM_RESUME_AUDIO
:
2049 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2050 status
= STATUS_INVALID_PARAMETER
;
2051 else status
= CDROM_ResumeAudio(fd
);
2053 case IOCTL_CDROM_SEEK_AUDIO_MSF
:
2055 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2056 else if (nInBufferSize
< sizeof(CDROM_SEEK_AUDIO_MSF
)) status
= STATUS_BUFFER_TOO_SMALL
;
2057 else status
= CDROM_SeekAudioMSF(dev
, fd
, (const CDROM_SEEK_AUDIO_MSF
*)lpInBuffer
);
2059 case IOCTL_CDROM_STOP_AUDIO
:
2061 CDROM_ClearCacheEntry(dev
); /* Maybe intention is to change media */
2062 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2063 status
= STATUS_INVALID_PARAMETER
;
2064 else status
= CDROM_StopAudio(fd
);
2066 case IOCTL_CDROM_GET_VOLUME
:
2067 sz
= sizeof(VOLUME_CONTROL
);
2068 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2069 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2070 else status
= CDROM_GetVolume(fd
, (VOLUME_CONTROL
*)lpOutBuffer
);
2072 case IOCTL_CDROM_SET_VOLUME
:
2074 CDROM_ClearCacheEntry(dev
);
2075 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(VOLUME_CONTROL
) || lpOutBuffer
!= NULL
)
2076 status
= STATUS_INVALID_PARAMETER
;
2077 else status
= CDROM_SetVolume(fd
, (const VOLUME_CONTROL
*)lpInBuffer
);
2079 case IOCTL_CDROM_RAW_READ
:
2081 if (nInBufferSize
< sizeof(RAW_READ_INFO
)) status
= STATUS_INVALID_PARAMETER
;
2082 else if (lpOutBuffer
== NULL
) status
= STATUS_BUFFER_TOO_SMALL
;
2083 else status
= CDROM_RawRead(fd
, (const RAW_READ_INFO
*)lpInBuffer
,
2084 lpOutBuffer
, nOutBufferSize
, &sz
);
2086 case IOCTL_SCSI_GET_ADDRESS
:
2087 sz
= sizeof(SCSI_ADDRESS
);
2088 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2089 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2090 else status
= CDROM_GetAddress(fd
, (SCSI_ADDRESS
*)lpOutBuffer
);
2092 case IOCTL_SCSI_PASS_THROUGH_DIRECT
:
2093 sz
= sizeof(SCSI_PASS_THROUGH_DIRECT
);
2094 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2095 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH_DIRECT
)) status
= STATUS_BUFFER_TOO_SMALL
;
2096 else status
= CDROM_ScsiPassThroughDirect(fd
, (PSCSI_PASS_THROUGH_DIRECT
)lpOutBuffer
);
2098 case IOCTL_SCSI_PASS_THROUGH
:
2099 sz
= sizeof(SCSI_PASS_THROUGH
);
2100 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2101 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH
)) status
= STATUS_BUFFER_TOO_SMALL
;
2102 else status
= CDROM_ScsiPassThrough(fd
, (PSCSI_PASS_THROUGH
)lpOutBuffer
);
2104 case IOCTL_SCSI_GET_CAPABILITIES
:
2105 sz
= sizeof(IO_SCSI_CAPABILITIES
);
2106 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2107 else if (nOutBufferSize
< sizeof(IO_SCSI_CAPABILITIES
)) status
= STATUS_BUFFER_TOO_SMALL
;
2108 else status
= CDROM_ScsiGetCaps((PIO_SCSI_CAPABILITIES
)lpOutBuffer
);
2110 case IOCTL_DVD_START_SESSION
:
2111 sz
= sizeof(DVD_SESSION_ID
);
2112 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2113 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2116 TRACE("before in 0x%08lx out 0x%08lx\n",(lpInBuffer
)?*(PDVD_SESSION_ID
)lpInBuffer
:0,
2117 *(PDVD_SESSION_ID
)lpOutBuffer
);
2118 status
= DVD_StartSession(fd
, (PDVD_SESSION_ID
)lpInBuffer
, (PDVD_SESSION_ID
)lpOutBuffer
);
2119 TRACE("before in 0x%08lx out 0x%08lx\n",(lpInBuffer
)?*(PDVD_SESSION_ID
)lpInBuffer
:0,
2120 *(PDVD_SESSION_ID
)lpOutBuffer
);
2123 case IOCTL_DVD_END_SESSION
:
2124 sz
= sizeof(DVD_SESSION_ID
);
2125 if ((lpInBuffer
== NULL
) || (nInBufferSize
< sz
))status
= STATUS_INVALID_PARAMETER
;
2126 else status
= DVD_EndSession(fd
, (PDVD_SESSION_ID
)lpInBuffer
);
2128 case IOCTL_DVD_SEND_KEY
:
2131 (((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
!= nInBufferSize
))
2132 status
= STATUS_INVALID_PARAMETER
;
2135 TRACE("doing DVD_SendKey\n");
2136 status
= DVD_SendKey(fd
, (PDVD_COPY_PROTECT_KEY
)lpInBuffer
);
2139 case IOCTL_DVD_READ_KEY
:
2141 (((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
!= nInBufferSize
))
2142 status
= STATUS_INVALID_PARAMETER
;
2143 else if (lpInBuffer
!=lpOutBuffer
) status
= STATUS_BUFFER_TOO_SMALL
;
2146 TRACE("doing DVD_READ_KEY\n");
2147 sz
= ((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
;
2148 status
= DVD_ReadKey(fd
, (PDVD_COPY_PROTECT_KEY
)lpInBuffer
);
2151 case IOCTL_DVD_GET_REGION
:
2152 sz
= sizeof(DVD_REGION
);
2153 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2154 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2155 TRACE("doing DVD_Get_REGION\n");
2156 status
= DVD_GetRegion(fd
, (PDVD_REGION
)lpOutBuffer
);
2158 case IOCTL_DVD_READ_STRUCTURE
:
2159 sz
= sizeof(DVD_LAYER_DESCRIPTOR
);
2160 if (lpInBuffer
== NULL
|| nInBufferSize
!= sizeof(DVD_READ_STRUCTURE
)) status
= STATUS_INVALID_PARAMETER
;
2161 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2162 TRACE("doing DVD_READ_STRUCTURE\n");
2163 status
= DVD_ReadStructure(fd
, (PDVD_READ_STRUCTURE
)lpInBuffer
, (PDVD_LAYER_DESCRIPTOR
)lpOutBuffer
);
2167 FIXME("Unsupported IOCTL %lx (type=%lx access=%lx func=%lx meth=%lx)\n",
2168 dwIoControlCode
, dwIoControlCode
>> 16, (dwIoControlCode
>> 14) & 3,
2169 (dwIoControlCode
>> 2) & 0xFFF, dwIoControlCode
& 3);
2171 status
= STATUS_INVALID_PARAMETER
;
2174 wine_server_release_fd( hDevice
, fd
);
2176 piosb
->u
.Status
= status
;
2177 piosb
->Information
= sz
;
2178 if (hEvent
) NtSetEvent(hEvent
, NULL
);