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
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
37 #ifdef HAVE_SYS_STAT_H
38 # include <sys/stat.h>
40 #include <sys/types.h>
42 #ifdef HAVE_SYS_IOCTL_H
43 #include <sys/ioctl.h>
48 #ifdef HAVE_SCSI_SCSI_H
49 # include <scsi/scsi.h>
50 # undef REASSIGN_BLOCKS /* avoid conflict with winioctl.h */
52 #ifdef HAVE_SCSI_SCSI_IOCTL_H
53 # include <scsi/scsi_ioctl.h>
55 #ifdef HAVE_LINUX_MAJOR_H
56 # include <linux/major.h>
58 #ifdef HAVE_LINUX_HDREG_H
59 # include <linux/hdreg.h>
61 #ifdef HAVE_LINUX_PARAM_H
62 # include <linux/param.h>
64 #ifdef HAVE_LINUX_CDROM_H
65 # include <linux/cdrom.h>
67 #ifdef HAVE_LINUX_UCDROM_H
68 # include <linux/ucdrom.h>
70 #ifdef HAVE_SYS_CDIO_H
71 # include <sys/cdio.h>
73 #ifdef HAVE_SYS_SCSIIO_H
74 # include <sys/scsiio.h>
77 #define NONAMELESSUNION
78 #define NONAMELESSSTRUCT
88 #include "ntdll_misc.h"
89 #include "wine/server.h"
90 #include "wine/library.h"
91 #include "wine/debug.h"
93 /* Non-Linux systems do not have linux/cdrom.h and the like, and thus
94 lack the following constants. */
97 # define CD_SECS 60 /* seconds per minute */
100 # define CD_FRAMES 75 /* frames per second */
103 /* definitions taken from libdvdcss */
105 #define IOCTL_DVD_BASE FILE_DEVICE_DVD
107 #define IOCTL_DVD_START_SESSION CTL_CODE(IOCTL_DVD_BASE, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
108 #define IOCTL_DVD_READ_KEY CTL_CODE(IOCTL_DVD_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
109 #define IOCTL_DVD_SEND_KEY CTL_CODE(IOCTL_DVD_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
110 #define IOCTL_DVD_END_SESSION CTL_CODE(IOCTL_DVD_BASE, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
111 #define IOCTL_DVD_SET_READ_AHEAD CTL_CODE(IOCTL_DVD_BASE, 0x0404, METHOD_BUFFERED, FILE_READ_ACCESS)
112 #define IOCTL_DVD_GET_REGION CTL_CODE(IOCTL_DVD_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS)
113 #define IOCTL_DVD_SEND_KEY2 CTL_CODE(IOCTL_DVD_BASE, 0x0406, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
115 #define IOCTL_DVD_READ_STRUCTURE CTL_CODE(IOCTL_DVD_BASE, 0x0450, METHOD_BUFFERED, FILE_READ_ACCESS)
118 DvdChallengeKey
= 0x01,
126 DvdInvalidateAGID
= 0x3f
129 typedef ULONG DVD_SESSION_ID
, *PDVD_SESSION_ID
;
131 typedef struct _DVD_COPY_PROTECT_KEY
{
133 DVD_SESSION_ID SessionId
;
134 DVD_KEY_TYPE KeyType
;
139 ULONG Reserved
; /* used for NT alignment */
141 LARGE_INTEGER TitleOffset
;
144 } DVD_COPY_PROTECT_KEY
, *PDVD_COPY_PROTECT_KEY
;
146 typedef struct _DVD_RPC_KEY
{
147 UCHAR UserResetsAvailable
:3;
148 UCHAR ManufacturerResetsAvailable
:3;
153 } DVD_RPC_KEY
, * PDVD_RPC_KEY
;
155 typedef struct _DVD_ASF
{
159 } DVD_ASF
, * PDVD_ASF
;
161 typedef struct _DVD_REGION
163 unsigned char copy_system
;
164 unsigned char region_data
; /* current media region (not playable when set) */
165 unsigned char system_region
; /* current drive region (playable when set) */
166 unsigned char reset_count
; /* number of resets available */
167 } DVD_REGION
, * PDVD_REGION
;
169 typedef struct _DVD_READ_STRUCTURE
{
170 /* Contains an offset to the logical block address of the descriptor to be retrieved. */
171 LARGE_INTEGER block_byte_offset
;
173 /* 0:Physical descriptor, 1:Copyright descriptor, 2:Disk key descriptor
174 3:BCA descriptor, 4:Manufacturer descriptor, 5:Max descriptor
178 /* Session ID, that is obtained by IOCTL_DVD_START_SESSION */
182 unsigned char layer_no
;
183 }DVD_READ_STRUCTURE
, * PDVD_READ_STRUCTURE
;
185 typedef struct _DVD_LAYER_DESCRIPTOR
187 unsigned short length
;
189 unsigned char book_version
: 4;
191 /* 0:DVD-ROM, 1:DVD-RAM, 2:DVD-R, 3:DVD-RW, 9:DVD-RW */
192 unsigned char book_type
: 4;
194 unsigned char minimum_rate
: 4;
196 /* The physical size of the media. 0:120 mm, 1:80 mm. */
197 unsigned char disk_size
: 4;
199 /* 1:Read-only layer, 2:Recordable layer, 4:Rewritable layer */
200 unsigned char layer_type
: 4;
202 /* 0:parallel track path, 1:opposite track path */
203 unsigned char track_path
: 1;
205 /* 0:one layers, 1:two layers, and so on */
206 unsigned char num_of_layers
: 2;
208 unsigned char reserved1
: 1;
210 /* 0:0.74 µm/track, 1:0.80 µm/track, 2:0.615 µm/track */
211 unsigned char track_density
: 4;
213 /* 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 */
214 unsigned char linear_density
: 4;
216 /* Must be either 0x30000:DVD-ROM or DVD-R/-RW or 0x31000:DVD-RAM or DVD+RW */
217 unsigned long starting_data_sector
;
219 unsigned long end_data_sector
;
220 unsigned long end_layer_zero_sector
;
221 unsigned char reserved5
: 7;
223 /* 0 indicates no BCA data */
224 unsigned char BCA_flag
: 1;
226 unsigned char reserved6
;
227 }DVD_LAYER_DESCRIPTOR
, * PDVD_LAYER_DESCRIPTOR
;
229 typedef struct _DVD_COPYRIGHT_DESCRIPTOR
231 unsigned char protection
;
232 unsigned char region
;
233 unsigned short reserved
;
234 }DVD_COPYRIGHT_DESCRIPTOR
, * PDVD_COPYRIGHT_DESCRIPTOR
;
236 typedef struct _DVD_MANUFACTURER_DESCRIPTOR
238 unsigned char manufacturing
[2048];
239 }DVD_MANUFACTURER_DESCRIPTOR
, * PDVD_MANUFACTURER_DESCRIPTOR
;
241 #define DVD_CHALLENGE_KEY_LENGTH (12 + sizeof(DVD_COPY_PROTECT_KEY) - sizeof(UCHAR))
243 #define DVD_DISK_KEY_LENGTH (2048 + sizeof(DVD_COPY_PROTECT_KEY) - sizeof(UCHAR))
245 #define DVD_KEY_SIZE 5
246 #define DVD_CHALLENGE_SIZE 10
247 #define DVD_DISCKEY_SIZE 2048
248 #define DVD_SECTOR_PROTECTED 0x00000020
250 static const struct iocodexs
255 #define X(x) { x, #x },
256 X(IOCTL_CDROM_CHECK_VERIFY
)
257 X(IOCTL_CDROM_CURRENT_POSITION
)
258 X(IOCTL_CDROM_DISK_TYPE
)
259 X(IOCTL_CDROM_GET_CONTROL
)
260 X(IOCTL_CDROM_GET_DRIVE_GEOMETRY
)
261 X(IOCTL_CDROM_GET_VOLUME
)
262 X(IOCTL_CDROM_LOAD_MEDIA
)
263 X(IOCTL_CDROM_MEDIA_CATALOG
)
264 X(IOCTL_CDROM_MEDIA_REMOVAL
)
265 X(IOCTL_CDROM_PAUSE_AUDIO
)
266 X(IOCTL_CDROM_PLAY_AUDIO_MSF
)
267 X(IOCTL_CDROM_RAW_READ
)
268 X(IOCTL_CDROM_READ_Q_CHANNEL
)
269 X(IOCTL_CDROM_READ_TOC
)
270 X(IOCTL_CDROM_RESUME_AUDIO
)
271 X(IOCTL_CDROM_SEEK_AUDIO_MSF
)
272 X(IOCTL_CDROM_SET_VOLUME
)
273 X(IOCTL_CDROM_STOP_AUDIO
)
274 X(IOCTL_CDROM_TRACK_ISRC
)
275 X(IOCTL_DISK_MEDIA_REMOVAL
)
276 X(IOCTL_DVD_END_SESSION
)
277 X(IOCTL_DVD_GET_REGION
)
278 X(IOCTL_DVD_READ_KEY
)
279 X(IOCTL_DVD_READ_STRUCTURE
)
280 X(IOCTL_DVD_SEND_KEY
)
281 X(IOCTL_DVD_START_SESSION
)
282 X(IOCTL_SCSI_GET_ADDRESS
)
283 X(IOCTL_SCSI_GET_CAPABILITIES
)
284 X(IOCTL_SCSI_PASS_THROUGH
)
285 X(IOCTL_SCSI_PASS_THROUGH_DIRECT
)
286 X(IOCTL_STORAGE_CHECK_VERIFY
)
287 X(IOCTL_STORAGE_EJECTION_CONTROL
)
288 X(IOCTL_STORAGE_EJECT_MEDIA
)
289 X(IOCTL_STORAGE_GET_DEVICE_NUMBER
)
290 X(IOCTL_STORAGE_LOAD_MEDIA
)
291 X(IOCTL_STORAGE_MEDIA_REMOVAL
)
292 X(IOCTL_STORAGE_RESET_DEVICE
)
295 static const char *iocodex(DWORD code
)
298 static char buffer
[25];
299 for(i
=0; i
<sizeof(iocodextable
)/sizeof(struct iocodexs
); i
++)
300 if (code
==iocodextable
[i
].code
)
301 return iocodextable
[i
].codex
;
302 sprintf(buffer
, "IOCTL_CODE_%x", (int)code
);
306 WINE_DEFAULT_DEBUG_CHANNEL(cdrom
);
308 #define FRAME_OF_ADDR(a) (((int)(a)[1] * CD_SECS + (a)[2]) * CD_FRAMES + (a)[3])
309 #define FRAME_OF_MSF(a) (((int)(a).M * CD_SECS + (a).S) * CD_FRAMES + (a).F)
310 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
311 #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;}
313 static NTSTATUS
CDROM_ReadTOC(int, int, CDROM_TOC
*);
314 static NTSTATUS
CDROM_GetStatusCode(int);
320 # define IDE6_MAJOR 88
323 # define IDE7_MAJOR 89
326 # ifdef CDROM_SEND_PACKET
327 /* structure for CDROM_PACKET_COMMAND ioctl */
328 /* not all Linux versions have all the fields, so we define the
329 * structure ourselves to make sure */
330 struct linux_cdrom_generic_command
332 unsigned char cmd
[CDROM_PACKET_SIZE
];
333 unsigned char *buffer
;
336 struct request_sense
*sense
;
337 unsigned char data_direction
;
342 # endif /* CDROM_SEND_PACKET */
346 /* FIXME: this is needed because we can't open simultaneously several times /dev/cdrom
347 * this should be removed when a proper device interface is implemented
349 * (WS) We need this to keep track of current position and to safely
350 * detect media changes. Besides this should provide a great speed up
356 char toc_good
; /* if false, will reread TOC from disk */
358 SUB_Q_CURRENT_POSITION CurrentPosition
;
360 /* who has more than 5 cdroms on his/her machine ?? */
361 /* FIXME: this should grow depending on the number of cdroms we install/configure
364 #define MAX_CACHE_ENTRIES 5
365 static struct cdrom_cache cdrom_cache
[MAX_CACHE_ENTRIES
];
367 static CRITICAL_SECTION cache_section
;
368 static CRITICAL_SECTION_DEBUG critsect_debug
=
370 0, 0, &cache_section
,
371 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
372 0, 0, { 0, (DWORD
)(__FILE__
": cache_section") }
374 static CRITICAL_SECTION cache_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
376 /* Proposed media change function: not really needed at this time */
377 /* This is a 1 or 0 type of function */
379 static int CDROM_MediaChanged(int dev
)
383 struct cdrom_tochdr hdr
;
384 struct cdrom_tocentry entry
;
386 if (dev
< 0 || dev
>= MAX_CACHE_ENTRIES
)
388 if ( ioctl(cdrom_cache
[dev
].fd
, CDROMREADTOCHDR
, &hdr
) == -1 )
391 if ( memcmp(&hdr
, &cdrom_cache
[dev
].hdr
, sizeof(struct cdrom_tochdr
)) )
394 for (i
=hdr
.cdth_trk0
; i
<=hdr
.cdth_trk1
+1; i
++)
396 if (i
== hdr
.cdth_trk1
+ 1)
398 entry
.cdte_track
= CDROM_LEADOUT
;
400 entry
.cdte_track
= i
;
402 entry
.cdte_format
= CDROM_MSF
;
403 if ( ioctl(cdrom_cache
[dev
].fd
, CDROMREADTOCENTRY
, &entry
) == -1)
405 if ( memcmp(&entry
, cdrom_cache
[dev
].entry
+i
-hdr
.cdth_trk0
,
406 sizeof(struct cdrom_tocentry
)) )
413 /******************************************************************
414 * CDROM_SyncCache [internal]
416 * Read the TOC in and store it in the cdrom_cache structure.
417 * Further requests for the TOC will be copied from the cache
418 * unless certain events like disk ejection is detected, in which
419 * case the cache will be cleared, causing it to be resynced.
420 * The cache section must be held by caller.
422 static int CDROM_SyncCache(int dev
, int fd
)
426 struct cdrom_tochdr hdr
;
427 struct cdrom_tocentry entry
;
428 #elif defined(__FreeBSD__) || defined(__NetBSD__)
429 struct ioc_toc_header hdr
;
430 struct ioc_read_toc_entry entry
;
431 struct cd_toc_entry toc_buffer
;
433 CDROM_TOC
*toc
= &cdrom_cache
[dev
].toc
;
434 cdrom_cache
[dev
].toc_good
= 0;
438 io
= ioctl(fd
, CDROMREADTOCHDR
, &hdr
);
441 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
445 toc
->FirstTrack
= hdr
.cdth_trk0
;
446 toc
->LastTrack
= hdr
.cdth_trk1
;
447 tsz
= sizeof(toc
->FirstTrack
) + sizeof(toc
->LastTrack
)
448 + sizeof(TRACK_DATA
) * (toc
->LastTrack
-toc
->FirstTrack
+2);
449 toc
->Length
[0] = tsz
>> 8;
450 toc
->Length
[1] = tsz
;
452 TRACE("caching toc from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
454 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
456 if (i
== toc
->LastTrack
+ 1)
457 entry
.cdte_track
= CDROM_LEADOUT
;
459 entry
.cdte_track
= i
;
460 entry
.cdte_format
= CDROM_MSF
;
461 io
= ioctl(fd
, CDROMREADTOCENTRY
, &entry
);
463 WARN("error read entry (%s)\n", strerror(errno
));
466 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= entry
.cdte_ctrl
;
467 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= entry
.cdte_adr
;
468 /* marking last track with leadout value as index */
469 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.cdte_track
;
470 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
471 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = entry
.cdte_addr
.msf
.minute
;
472 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = entry
.cdte_addr
.msf
.second
;
473 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = entry
.cdte_addr
.msf
.frame
;
475 cdrom_cache
[dev
].toc_good
= 1;
477 #elif defined(__FreeBSD__) || defined(__NetBSD__)
479 io
= ioctl(fd
, CDIOREADTOCHEADER
, &hdr
);
482 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
485 toc
->FirstTrack
= hdr
.starting_track
;
486 toc
->LastTrack
= hdr
.ending_track
;
487 tsz
= sizeof(toc
->FirstTrack
) + sizeof(toc
->LastTrack
)
488 + sizeof(TRACK_DATA
) * (toc
->LastTrack
-toc
->FirstTrack
+2);
489 toc
->Length
[0] = tsz
>> 8;
490 toc
->Length
[1] = tsz
;
492 TRACE("caching toc from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
494 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
496 if (i
== toc
->LastTrack
+ 1)
499 entry
.starting_track
= LEADOUT
;
501 entry
.starting_track
= i
;
503 memset((char *)&toc_buffer
, 0, sizeof(toc_buffer
));
504 entry
.address_format
= CD_MSF_FORMAT
;
505 entry
.data_len
= sizeof(toc_buffer
);
506 entry
.data
= &toc_buffer
;
507 io
= ioctl(fd
, CDIOREADTOCENTRYS
, &entry
);
509 WARN("error read entry (%s)\n", strerror(errno
));
512 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= toc_buffer
.control
;
513 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= toc_buffer
.addr_type
;
514 /* marking last track with leadout value as index */
515 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.starting_track
;
516 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
517 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = toc_buffer
.addr
.msf
.minute
;
518 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = toc_buffer
.addr
.msf
.second
;
519 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = toc_buffer
.addr
.msf
.frame
;
521 cdrom_cache
[dev
].toc_good
= 1;
524 return STATUS_NOT_SUPPORTED
;
527 return CDROM_GetStatusCode(io
);
530 static void CDROM_ClearCacheEntry(int dev
)
532 RtlEnterCriticalSection( &cache_section
);
533 cdrom_cache
[dev
].toc_good
= 0;
534 RtlLeaveCriticalSection( &cache_section
);
539 /******************************************************************
540 * CDROM_GetInterfaceInfo
542 * Determines the ide interface (the number after the ide), and the
543 * number of the device on that interface for ide cdroms (*port == 0).
544 * Determines the scsi information for scsi cdroms (*port >= 1).
545 * Returns false if the info cannot not be obtained.
547 static int CDROM_GetInterfaceInfo(int fd
, int* port
, int* iface
, int* device
,int* lun
)
551 if ( fstat(fd
, &st
) == -1 || ! S_ISBLK(st
.st_mode
)) return 0;
556 switch (major(st
.st_rdev
)) {
557 case IDE0_MAJOR
: *iface
= 0; break;
558 case IDE1_MAJOR
: *iface
= 1; break;
559 case IDE2_MAJOR
: *iface
= 2; break;
560 case IDE3_MAJOR
: *iface
= 3; break;
561 case IDE4_MAJOR
: *iface
= 4; break;
562 case IDE5_MAJOR
: *iface
= 5; break;
563 case IDE6_MAJOR
: *iface
= 6; break;
564 case IDE7_MAJOR
: *iface
= 7; break;
565 default: *port
= 1; break;
569 *device
= (minor(st
.st_rdev
) >> 6);
572 #ifdef SCSI_IOCTL_GET_IDLUN
574 if (ioctl(fd
, SCSI_IOCTL_GET_IDLUN
, &idlun
) != -1)
576 *port
= ((idlun
[0] >> 24) & 0xff) + 1;
577 *iface
= (idlun
[0] >> 16) & 0xff;
578 *device
= idlun
[0] & 0xff;
579 *lun
= (idlun
[0] >> 8) & 0xff;
584 WARN("CD-ROM device (%d, %d) not supported\n", major(st
.st_rdev
), minor(st
.st_rdev
));
589 #elif defined(__NetBSD__)
590 struct scsi_addr addr
;
591 if (ioctl(fd
, SCIOCIDENTIFY
, &addr
) != -1)
595 case TYPE_SCSI
: *port
= 1;
596 *iface
= addr
.addr
.scsi
.scbus
;
597 *device
= addr
.addr
.scsi
.target
;
598 *lun
= addr
.addr
.scsi
.lun
;
600 case TYPE_ATAPI
: *port
= 0;
601 *iface
= addr
.addr
.atapi
.atbus
;
602 *device
= addr
.addr
.atapi
.drive
;
609 #elif defined(__FreeBSD__)
610 FIXME("not implemented for BSD\n");
613 FIXME("not implemented for nonlinux\n");
619 /******************************************************************
623 static NTSTATUS
CDROM_Open(int fd
, int* dev
)
626 NTSTATUS ret
= STATUS_SUCCESS
;
631 RtlEnterCriticalSection( &cache_section
);
632 for (*dev
= 0; *dev
< MAX_CACHE_ENTRIES
; (*dev
)++)
635 cdrom_cache
[*dev
].device
== 0 &&
636 cdrom_cache
[*dev
].inode
== 0)
638 else if (cdrom_cache
[*dev
].device
== st
.st_dev
&&
639 cdrom_cache
[*dev
].inode
== st
.st_ino
)
642 if (*dev
== MAX_CACHE_ENTRIES
)
644 if (empty
== -1) ret
= STATUS_NOT_IMPLEMENTED
;
648 cdrom_cache
[*dev
].device
= st
.st_dev
;
649 cdrom_cache
[*dev
].inode
= st
.st_ino
;
652 RtlLeaveCriticalSection( &cache_section
);
654 TRACE("%d, %d\n", *dev
, fd
);
658 /******************************************************************
659 * CDROM_GetStatusCode
663 static NTSTATUS
CDROM_GetStatusCode(int io
)
665 if (io
== 0) return STATUS_SUCCESS
;
666 return FILE_GetNtStatus();
669 /******************************************************************
673 static NTSTATUS
CDROM_GetControl(int dev
, CDROM_AUDIO_CONTROL
* cac
)
675 cac
->LbaFormat
= 0; /* FIXME */
676 cac
->LogicalBlocksPerSecond
= 1; /* FIXME */
677 return STATUS_NOT_SUPPORTED
;
680 /******************************************************************
681 * CDROM_GetDeviceNumber
684 static NTSTATUS
CDROM_GetDeviceNumber(int dev
, STORAGE_DEVICE_NUMBER
* devnum
)
686 return STATUS_NOT_SUPPORTED
;
689 /******************************************************************
690 * CDROM_GetDriveGeometry
693 static NTSTATUS
CDROM_GetDriveGeometry(int dev
, int fd
, DISK_GEOMETRY
* dg
)
699 if ((ret
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return ret
;
701 fsize
= FRAME_OF_TOC(toc
, toc
.LastTrack
+1)
702 - FRAME_OF_TOC(toc
, 1); /* Total size in frames */
704 dg
->Cylinders
.u
.LowPart
= fsize
/ (64 * 32);
705 dg
->Cylinders
.u
.HighPart
= 0;
706 dg
->MediaType
= RemovableMedia
;
707 dg
->TracksPerCylinder
= 64;
708 dg
->SectorsPerTrack
= 32;
709 dg
->BytesPerSector
= 2048;
713 /**************************************************************************
714 * CDROM_Reset [internal]
716 static NTSTATUS
CDROM_ResetAudio(int fd
)
719 return CDROM_GetStatusCode(ioctl(fd
, CDROMRESET
));
720 #elif defined(__FreeBSD__) || defined(__NetBSD__)
721 return CDROM_GetStatusCode(ioctl(fd
, CDIOCRESET
, NULL
));
723 return STATUS_NOT_SUPPORTED
;
727 /******************************************************************
732 static NTSTATUS
CDROM_SetTray(int fd
, BOOL doEject
)
735 return CDROM_GetStatusCode(ioctl(fd
, doEject
? CDROMEJECT
: CDROMCLOSETRAY
));
736 #elif defined(__FreeBSD__) || defined(__NetBSD__)
737 return CDROM_GetStatusCode((ioctl(fd
, CDIOCALLOW
, NULL
)) ||
738 (ioctl(fd
, doEject
? CDIOCEJECT
: CDIOCCLOSE
, NULL
)) ||
739 (ioctl(fd
, CDIOCPREVENT
, NULL
)));
741 return STATUS_NOT_SUPPORTED
;
745 /******************************************************************
746 * CDROM_ControlEjection
750 static NTSTATUS
CDROM_ControlEjection(int fd
, const PREVENT_MEDIA_REMOVAL
* rmv
)
753 return CDROM_GetStatusCode(ioctl(fd
, CDROM_LOCKDOOR
, rmv
->PreventMediaRemoval
));
754 #elif defined(__FreeBSD__) || defined(__NetBSD__)
755 return CDROM_GetStatusCode(ioctl(fd
, (rmv
->PreventMediaRemoval
) ? CDIOCPREVENT
: CDIOCALLOW
, NULL
));
757 return STATUS_NOT_SUPPORTED
;
761 /******************************************************************
766 static NTSTATUS
CDROM_ReadTOC(int dev
, int fd
, CDROM_TOC
* toc
)
768 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
770 if (dev
< 0 || dev
>= MAX_CACHE_ENTRIES
)
771 return STATUS_INVALID_PARAMETER
;
773 RtlEnterCriticalSection( &cache_section
);
774 if (cdrom_cache
[dev
].toc_good
|| !(ret
= CDROM_SyncCache(dev
, fd
)))
776 *toc
= cdrom_cache
[dev
].toc
;
777 ret
= STATUS_SUCCESS
;
779 RtlLeaveCriticalSection( &cache_section
);
783 /******************************************************************
788 static NTSTATUS
CDROM_GetDiskData(int dev
, int fd
, CDROM_DISK_DATA
* data
)
794 if ((ret
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return ret
;
796 for (i
= toc
.FirstTrack
; i
<= toc
.LastTrack
; i
++) {
797 if (toc
.TrackData
[i
-toc
.FirstTrack
].Control
& 0x04)
798 data
->DiskData
|= CDROM_DISK_DATA_TRACK
;
800 data
->DiskData
|= CDROM_DISK_AUDIO_TRACK
;
802 return STATUS_SUCCESS
;
805 /******************************************************************
810 static NTSTATUS
CDROM_ReadQChannel(int dev
, int fd
, const CDROM_SUB_Q_DATA_FORMAT
* fmt
,
811 SUB_Q_CHANNEL_DATA
* data
)
813 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
816 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
818 struct cdrom_subchnl sc
;
819 sc
.cdsc_format
= CDROM_MSF
;
821 io
= ioctl(fd
, CDROMSUBCHNL
, &sc
);
824 TRACE("opened or no_media (%s)!\n", strerror(errno
));
825 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
826 CDROM_ClearCacheEntry(dev
);
830 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
832 switch (sc
.cdsc_audiostatus
) {
833 case CDROM_AUDIO_INVALID
:
834 CDROM_ClearCacheEntry(dev
);
835 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
837 case CDROM_AUDIO_NO_STATUS
:
838 CDROM_ClearCacheEntry(dev
);
839 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
841 case CDROM_AUDIO_PLAY
:
842 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
844 case CDROM_AUDIO_PAUSED
:
845 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
847 case CDROM_AUDIO_COMPLETED
:
848 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
850 case CDROM_AUDIO_ERROR
:
851 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
854 TRACE("status=%02X !\n", sc
.cdsc_audiostatus
);
859 case IOCTL_CDROM_CURRENT_POSITION
:
860 size
= sizeof(SUB_Q_CURRENT_POSITION
);
861 RtlEnterCriticalSection( &cache_section
);
862 if (hdr
->AudioStatus
==AUDIO_STATUS_IN_PROGRESS
) {
863 data
->CurrentPosition
.FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
864 data
->CurrentPosition
.Control
= sc
.cdsc_ctrl
;
865 data
->CurrentPosition
.ADR
= sc
.cdsc_adr
;
866 data
->CurrentPosition
.TrackNumber
= sc
.cdsc_trk
;
867 data
->CurrentPosition
.IndexNumber
= sc
.cdsc_ind
;
869 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
870 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.cdsc_absaddr
.msf
.minute
;
871 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.cdsc_absaddr
.msf
.second
;
872 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.cdsc_absaddr
.msf
.frame
;
874 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
875 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.cdsc_reladdr
.msf
.minute
;
876 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.cdsc_reladdr
.msf
.second
;
877 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.cdsc_reladdr
.msf
.frame
;
879 cdrom_cache
[dev
].CurrentPosition
= data
->CurrentPosition
;
881 else /* not playing */
883 cdrom_cache
[dev
].CurrentPosition
.Header
= *hdr
; /* Preserve header info */
884 data
->CurrentPosition
= cdrom_cache
[dev
].CurrentPosition
;
886 RtlLeaveCriticalSection( &cache_section
);
888 case IOCTL_CDROM_MEDIA_CATALOG
:
889 size
= sizeof(SUB_Q_MEDIA_CATALOG_NUMBER
);
890 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
892 struct cdrom_mcn mcn
;
893 if ((io
= ioctl(fd
, CDROM_GET_MCN
, &mcn
)) == -1) goto end
;
895 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
896 data
->MediaCatalog
.Mcval
= 0; /* FIXME */
897 memcpy(data
->MediaCatalog
.MediaCatalog
, mcn
.medium_catalog_number
, 14);
898 data
->MediaCatalog
.MediaCatalog
[14] = 0;
901 case IOCTL_CDROM_TRACK_ISRC
:
902 size
= sizeof(SUB_Q_CURRENT_POSITION
);
903 FIXME("TrackIsrc: NIY on linux\n");
904 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
905 data
->TrackIsrc
.Tcval
= 0;
911 ret
= CDROM_GetStatusCode(io
);
912 #elif defined(__FreeBSD__) || defined(__NetBSD__)
914 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
916 struct ioc_read_subchannel read_sc
;
917 struct cd_sub_channel_info sc
;
919 read_sc
.address_format
= CD_MSF_FORMAT
;
921 read_sc
.data_len
= sizeof(sc
);
925 case IOCTL_CDROM_CURRENT_POSITION
:
926 read_sc
.data_format
= CD_CURRENT_POSITION
;
928 case IOCTL_CDROM_MEDIA_CATALOG
:
929 read_sc
.data_format
= CD_MEDIA_CATALOG
;
931 case IOCTL_CDROM_TRACK_ISRC
:
932 read_sc
.data_format
= CD_TRACK_INFO
;
933 sc
.what
.track_info
.track_number
= data
->TrackIsrc
.Track
;
936 io
= ioctl(fd
, CDIOCREADSUBCHANNEL
, &read_sc
);
939 TRACE("opened or no_media (%s)!\n", strerror(errno
));
940 CDROM_ClearCacheEntry(dev
);
941 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
945 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
947 switch (sc
.header
.audio_status
) {
948 case CD_AS_AUDIO_INVALID
:
949 CDROM_ClearCacheEntry(dev
);
950 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
952 case CD_AS_NO_STATUS
:
953 CDROM_ClearCacheEntry(dev
);
954 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
956 case CD_AS_PLAY_IN_PROGRESS
:
957 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
959 case CD_AS_PLAY_PAUSED
:
960 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
962 case CD_AS_PLAY_COMPLETED
:
963 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
965 case CD_AS_PLAY_ERROR
:
966 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
969 TRACE("status=%02X !\n", sc
.header
.audio_status
);
973 case IOCTL_CDROM_CURRENT_POSITION
:
974 size
= sizeof(SUB_Q_CURRENT_POSITION
);
975 RtlEnterCriticalSection( &cache_section
);
976 if (hdr
->AudioStatus
==AUDIO_STATUS_IN_PROGRESS
) {
977 data
->CurrentPosition
.FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
978 data
->CurrentPosition
.Control
= sc
.what
.position
.control
;
979 data
->CurrentPosition
.ADR
= sc
.what
.position
.addr_type
;
980 data
->CurrentPosition
.TrackNumber
= sc
.what
.position
.track_number
;
981 data
->CurrentPosition
.IndexNumber
= sc
.what
.position
.index_number
;
983 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
984 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.what
.position
.absaddr
.msf
.minute
;
985 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.what
.position
.absaddr
.msf
.second
;
986 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.what
.position
.absaddr
.msf
.frame
;
987 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
988 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.what
.position
.reladdr
.msf
.minute
;
989 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.what
.position
.reladdr
.msf
.second
;
990 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.what
.position
.reladdr
.msf
.frame
;
991 cdrom_cache
[dev
].CurrentPosition
= data
->CurrentPosition
;
993 else { /* not playing */
994 cdrom_cache
[dev
].CurrentPosition
.Header
= *hdr
; /* Preserve header info */
995 data
->CurrentPosition
= cdrom_cache
[dev
].CurrentPosition
;
997 RtlLeaveCriticalSection( &cache_section
);
999 case IOCTL_CDROM_MEDIA_CATALOG
:
1000 size
= sizeof(SUB_Q_MEDIA_CATALOG_NUMBER
);
1001 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
1002 data
->MediaCatalog
.Mcval
= sc
.what
.media_catalog
.mc_valid
;
1003 memcpy(data
->MediaCatalog
.MediaCatalog
, sc
.what
.media_catalog
.mc_number
, 15);
1005 case IOCTL_CDROM_TRACK_ISRC
:
1006 size
= sizeof(SUB_Q_CURRENT_POSITION
);
1007 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
1008 data
->TrackIsrc
.Tcval
= sc
.what
.track_info
.ti_valid
;
1009 memcpy(data
->TrackIsrc
.TrackIsrc
, sc
.what
.track_info
.ti_number
, 15);
1014 ret
= CDROM_GetStatusCode(io
);
1019 /******************************************************************
1024 static NTSTATUS
CDROM_Verify(int dev
, int fd
)
1026 /* quick implementation */
1027 CDROM_SUB_Q_DATA_FORMAT fmt
;
1028 SUB_Q_CHANNEL_DATA data
;
1030 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
1031 return CDROM_ReadQChannel(dev
, fd
, &fmt
, &data
) ? 1 : 0;
1034 /******************************************************************
1035 * CDROM_PlayAudioMSF
1039 static NTSTATUS
CDROM_PlayAudioMSF(int fd
, const CDROM_PLAY_AUDIO_MSF
* audio_msf
)
1041 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1043 struct cdrom_msf msf
;
1046 msf
.cdmsf_min0
= audio_msf
->StartingM
;
1047 msf
.cdmsf_sec0
= audio_msf
->StartingS
;
1048 msf
.cdmsf_frame0
= audio_msf
->StartingF
;
1049 msf
.cdmsf_min1
= audio_msf
->EndingM
;
1050 msf
.cdmsf_sec1
= audio_msf
->EndingS
;
1051 msf
.cdmsf_frame1
= audio_msf
->EndingF
;
1053 io
= ioctl(fd
, CDROMSTART
);
1056 WARN("motor doesn't start !\n");
1059 io
= ioctl(fd
, CDROMPLAYMSF
, &msf
);
1062 WARN("device doesn't play !\n");
1065 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1066 msf
.cdmsf_min0
, msf
.cdmsf_sec0
, msf
.cdmsf_frame0
,
1067 msf
.cdmsf_min1
, msf
.cdmsf_sec1
, msf
.cdmsf_frame1
);
1069 ret
= CDROM_GetStatusCode(io
);
1070 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1071 struct ioc_play_msf msf
;
1074 msf
.start_m
= audio_msf
->StartingM
;
1075 msf
.start_s
= audio_msf
->StartingS
;
1076 msf
.start_f
= audio_msf
->StartingF
;
1077 msf
.end_m
= audio_msf
->EndingM
;
1078 msf
.end_s
= audio_msf
->EndingS
;
1079 msf
.end_f
= audio_msf
->EndingF
;
1081 io
= ioctl(fd
, CDIOCSTART
, NULL
);
1084 WARN("motor doesn't start !\n");
1087 io
= ioctl(fd
, CDIOCPLAYMSF
, &msf
);
1090 WARN("device doesn't play !\n");
1093 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1094 msf
.start_m
, msf
.start_s
, msf
.start_f
,
1095 msf
.end_m
, msf
.end_s
, msf
.end_f
);
1097 ret
= CDROM_GetStatusCode(io
);
1102 /******************************************************************
1103 * CDROM_SeekAudioMSF
1107 static NTSTATUS
CDROM_SeekAudioMSF(int dev
, int fd
, const CDROM_SEEK_AUDIO_MSF
* audio_msf
)
1111 SUB_Q_CURRENT_POSITION
*cp
;
1113 struct cdrom_msf0 msf
;
1114 struct cdrom_subchnl sc
;
1115 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1116 struct ioc_play_msf msf
;
1117 struct ioc_read_subchannel read_sc
;
1118 struct cd_sub_channel_info sc
;
1122 /* Use the information on the TOC to compute the new current
1123 * position, which is shadowed on the cache. [Portable]. */
1124 frame
= FRAME_OF_MSF(*audio_msf
);
1126 if ((io
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return io
;
1128 for(i
=toc
.FirstTrack
;i
<=toc
.LastTrack
+1;i
++)
1129 if (FRAME_OF_TOC(toc
,i
)>frame
) break;
1130 if (i
<= toc
.FirstTrack
|| i
> toc
.LastTrack
+1)
1131 return STATUS_INVALID_PARAMETER
;
1133 RtlEnterCriticalSection( &cache_section
);
1134 cp
= &cdrom_cache
[dev
].CurrentPosition
;
1135 cp
->FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
1136 cp
->Control
= toc
.TrackData
[i
-toc
.FirstTrack
].Control
;
1137 cp
->ADR
= toc
.TrackData
[i
-toc
.FirstTrack
].Adr
;
1138 cp
->TrackNumber
= toc
.TrackData
[i
-toc
.FirstTrack
].TrackNumber
;
1139 cp
->IndexNumber
= 0; /* FIXME: where do they keep these? */
1140 cp
->AbsoluteAddress
[0] = 0;
1141 cp
->AbsoluteAddress
[1] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[1];
1142 cp
->AbsoluteAddress
[2] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[2];
1143 cp
->AbsoluteAddress
[3] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[3];
1144 frame
-= FRAME_OF_TOC(toc
,i
);
1145 cp
->TrackRelativeAddress
[0] = 0;
1146 MSF_OF_FRAME(cp
->TrackRelativeAddress
[1], frame
);
1147 RtlLeaveCriticalSection( &cache_section
);
1149 /* If playing, then issue a seek command, otherwise do nothing */
1151 sc
.cdsc_format
= CDROM_MSF
;
1153 io
= ioctl(fd
, CDROMSUBCHNL
, &sc
);
1156 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1157 CDROM_ClearCacheEntry(dev
);
1158 return CDROM_GetStatusCode(io
);
1160 if (sc
.cdsc_audiostatus
==CDROM_AUDIO_PLAY
)
1162 msf
.minute
= audio_msf
->M
;
1163 msf
.second
= audio_msf
->S
;
1164 msf
.frame
= audio_msf
->F
;
1165 return CDROM_GetStatusCode(ioctl(fd
, CDROMSEEK
, &msf
));
1167 return STATUS_SUCCESS
;
1168 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1169 read_sc
.address_format
= CD_MSF_FORMAT
;
1171 read_sc
.data_len
= sizeof(sc
);
1173 read_sc
.data_format
= CD_CURRENT_POSITION
;
1175 io
= ioctl(fd
, CDIOCREADSUBCHANNEL
, &read_sc
);
1178 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1179 CDROM_ClearCacheEntry(dev
);
1180 return CDROM_GetStatusCode(io
);
1182 if (sc
.header
.audio_status
==CD_AS_PLAY_IN_PROGRESS
)
1185 msf
.start_m
= audio_msf
->M
;
1186 msf
.start_s
= audio_msf
->S
;
1187 msf
.start_f
= audio_msf
->F
;
1188 final_frame
= FRAME_OF_TOC(toc
,toc
.LastTrack
+1)-1;
1189 MSF_OF_FRAME(msf
.end_m
, final_frame
);
1191 return CDROM_GetStatusCode(ioctl(fd
, CDIOCPLAYMSF
, &msf
));
1193 return STATUS_SUCCESS
;
1195 return STATUS_NOT_SUPPORTED
;
1199 /******************************************************************
1204 static NTSTATUS
CDROM_PauseAudio(int fd
)
1207 return CDROM_GetStatusCode(ioctl(fd
, CDROMPAUSE
));
1208 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1209 return CDROM_GetStatusCode(ioctl(fd
, CDIOCPAUSE
, NULL
));
1211 return STATUS_NOT_SUPPORTED
;
1215 /******************************************************************
1220 static NTSTATUS
CDROM_ResumeAudio(int fd
)
1223 return CDROM_GetStatusCode(ioctl(fd
, CDROMRESUME
));
1224 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1225 return CDROM_GetStatusCode(ioctl(fd
, CDIOCRESUME
, NULL
));
1227 return STATUS_NOT_SUPPORTED
;
1231 /******************************************************************
1236 static NTSTATUS
CDROM_StopAudio(int fd
)
1239 return CDROM_GetStatusCode(ioctl(fd
, CDROMSTOP
));
1240 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1241 return CDROM_GetStatusCode(ioctl(fd
, CDIOCSTOP
, NULL
));
1243 return STATUS_NOT_SUPPORTED
;
1247 /******************************************************************
1252 static NTSTATUS
CDROM_GetVolume(int fd
, VOLUME_CONTROL
* vc
)
1255 struct cdrom_volctrl volc
;
1258 io
= ioctl(fd
, CDROMVOLREAD
, &volc
);
1261 vc
->PortVolume
[0] = volc
.channel0
;
1262 vc
->PortVolume
[1] = volc
.channel1
;
1263 vc
->PortVolume
[2] = volc
.channel2
;
1264 vc
->PortVolume
[3] = volc
.channel3
;
1266 return CDROM_GetStatusCode(io
);
1267 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1268 struct ioc_vol volc
;
1271 io
= ioctl(fd
, CDIOCGETVOL
, &volc
);
1274 vc
->PortVolume
[0] = volc
.vol
[0];
1275 vc
->PortVolume
[1] = volc
.vol
[1];
1276 vc
->PortVolume
[2] = volc
.vol
[2];
1277 vc
->PortVolume
[3] = volc
.vol
[3];
1279 return CDROM_GetStatusCode(io
);
1281 return STATUS_NOT_SUPPORTED
;
1285 /******************************************************************
1290 static NTSTATUS
CDROM_SetVolume(int fd
, const VOLUME_CONTROL
* vc
)
1293 struct cdrom_volctrl volc
;
1295 volc
.channel0
= vc
->PortVolume
[0];
1296 volc
.channel1
= vc
->PortVolume
[1];
1297 volc
.channel2
= vc
->PortVolume
[2];
1298 volc
.channel3
= vc
->PortVolume
[3];
1300 return CDROM_GetStatusCode(ioctl(fd
, CDROMVOLCTRL
, &volc
));
1301 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1302 struct ioc_vol volc
;
1304 volc
.vol
[0] = vc
->PortVolume
[0];
1305 volc
.vol
[1] = vc
->PortVolume
[1];
1306 volc
.vol
[2] = vc
->PortVolume
[2];
1307 volc
.vol
[3] = vc
->PortVolume
[3];
1309 return CDROM_GetStatusCode(ioctl(fd
, CDIOCSETVOL
, &volc
));
1311 return STATUS_NOT_SUPPORTED
;
1315 /******************************************************************
1320 static NTSTATUS
CDROM_RawRead(int fd
, const RAW_READ_INFO
* raw
, void* buffer
, DWORD len
, DWORD
* sz
)
1322 int ret
= STATUS_NOT_SUPPORTED
;
1326 switch (raw
->TrackMode
)
1328 case YellowMode2
: sectSize
= 2336; break;
1329 case XAForm2
: sectSize
= 2328; break;
1330 case CDDA
: sectSize
= 2352; break;
1331 default: return STATUS_INVALID_PARAMETER
;
1333 if (len
< raw
->SectorCount
* sectSize
) return STATUS_BUFFER_TOO_SMALL
;
1334 /* strangely enough, it seems that sector offsets are always indicated with a size of 2048,
1335 * even if a larger size if read...
1339 struct cdrom_read cdr
;
1340 struct cdrom_read_audio cdra
;
1342 switch (raw
->TrackMode
)
1345 if (raw
->DiskOffset
.u
.HighPart
) FIXME("Unsupported value\n");
1346 cdr
.cdread_lba
= raw
->DiskOffset
.u
.LowPart
; /* FIXME ? */
1347 cdr
.cdread_bufaddr
= buffer
;
1348 cdr
.cdread_buflen
= raw
->SectorCount
* sectSize
;
1349 io
= ioctl(fd
, CDROMREADMODE2
, &cdr
);
1352 FIXME("XAForm2: NIY\n");
1355 /* FIXME: the output doesn't seem 100% correct... in fact output is shifted
1356 * between by NT2K box and this... should check on the same drive...
1357 * otherwise, I fear a 2352/2368 mismatch somewhere in one of the drivers
1359 * Anyway, that's not critical at all. We're talking of 16/32 bytes, we're
1360 * talking of 0.2 ms of sound
1362 /* 2048 = 2 ** 11 */
1363 if (raw
->DiskOffset
.u
.HighPart
& ~2047) FIXME("Unsupported value\n");
1364 cdra
.addr
.lba
= ((raw
->DiskOffset
.u
.LowPart
>> 11) |
1365 (raw
->DiskOffset
.u
.HighPart
<< (32 - 11))) - 1;
1366 FIXME("reading at %u\n", cdra
.addr
.lba
);
1367 cdra
.addr_format
= CDROM_LBA
;
1368 cdra
.nframes
= raw
->SectorCount
;
1370 io
= ioctl(fd
, CDROMREADAUDIO
, &cdra
);
1373 FIXME("NIY: %d\n", raw
->TrackMode
);
1379 switch (raw
->TrackMode
)
1382 FIXME("YellowMode2: NIY\n");
1385 FIXME("XAForm2: NIY\n");
1388 FIXME("CDDA: NIY\n");
1394 *sz
= sectSize
* raw
->SectorCount
;
1395 ret
= CDROM_GetStatusCode(io
);
1399 /******************************************************************
1400 * CDROM_ScsiPassThroughDirect
1404 static NTSTATUS
CDROM_ScsiPassThroughDirect(int fd
, PSCSI_PASS_THROUGH_DIRECT pPacket
)
1406 int ret
= STATUS_NOT_SUPPORTED
;
1407 #if defined(linux) && defined(CDROM_SEND_PACKET)
1408 struct linux_cdrom_generic_command cmd
;
1409 struct request_sense sense
;
1412 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH_DIRECT
))
1413 return STATUS_BUFFER_TOO_SMALL
;
1415 if (pPacket
->CdbLength
> 12)
1416 return STATUS_INVALID_PARAMETER
;
1418 if (pPacket
->SenseInfoLength
> sizeof(sense
))
1419 return STATUS_INVALID_PARAMETER
;
1421 memset(&cmd
, 0, sizeof(cmd
));
1422 memset(&sense
, 0, sizeof(sense
));
1424 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1426 cmd
.buffer
= pPacket
->DataBuffer
;
1427 cmd
.buflen
= pPacket
->DataTransferLength
;
1430 cmd
.timeout
= pPacket
->TimeOutValue
*HZ
;
1432 switch (pPacket
->DataIn
)
1434 case SCSI_IOCTL_DATA_OUT
:
1435 cmd
.data_direction
= CGC_DATA_WRITE
;
1437 case SCSI_IOCTL_DATA_IN
:
1438 cmd
.data_direction
= CGC_DATA_READ
;
1440 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1441 cmd
.data_direction
= CGC_DATA_NONE
;
1444 return STATUS_INVALID_PARAMETER
;
1447 io
= ioctl(fd
, CDROM_SEND_PACKET
, &cmd
);
1449 if (pPacket
->SenseInfoLength
!= 0)
1451 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1452 &sense
, pPacket
->SenseInfoLength
);
1455 pPacket
->ScsiStatus
= cmd
.stat
;
1457 ret
= CDROM_GetStatusCode(io
);
1459 #elif defined(__NetBSD__)
1463 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH_DIRECT
))
1464 return STATUS_BUFFER_TOO_SMALL
;
1466 if (pPacket
->CdbLength
> 12)
1467 return STATUS_INVALID_PARAMETER
;
1469 if (pPacket
->SenseInfoLength
> SENSEBUFLEN
)
1470 return STATUS_INVALID_PARAMETER
;
1472 memset(&cmd
, 0, sizeof(cmd
));
1473 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1475 cmd
.cmdlen
= pPacket
->CdbLength
;
1476 cmd
.databuf
= pPacket
->DataBuffer
;
1477 cmd
.datalen
= pPacket
->DataTransferLength
;
1478 cmd
.senselen
= pPacket
->SenseInfoLength
;
1479 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1481 switch (pPacket
->DataIn
)
1483 case SCSI_IOCTL_DATA_OUT
:
1484 cmd
.flags
|= SCCMD_WRITE
;
1486 case SCSI_IOCTL_DATA_IN
:
1487 cmd
.flags
|= SCCMD_READ
;
1489 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1493 return STATUS_INVALID_PARAMETER
;
1496 io
= ioctl(fd
, SCIOCCOMMAND
, &cmd
);
1500 case SCCMD_OK
: break;
1501 case SCCMD_TIMEOUT
: return STATUS_TIMEOUT
;
1503 case SCCMD_BUSY
: return STATUS_DEVICE_BUSY
;
1505 case SCCMD_SENSE
: break;
1506 case SCCMD_UNKNOWN
: return STATUS_UNSUCCESSFUL
;
1510 if (pPacket
->SenseInfoLength
!= 0)
1512 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1513 cmd
.sense
, pPacket
->SenseInfoLength
);
1516 pPacket
->ScsiStatus
= cmd
.status
;
1518 ret
= CDROM_GetStatusCode(io
);
1523 /******************************************************************
1524 * CDROM_ScsiPassThrough
1528 static NTSTATUS
CDROM_ScsiPassThrough(int fd
, PSCSI_PASS_THROUGH pPacket
)
1530 int ret
= STATUS_NOT_SUPPORTED
;
1531 #if defined(linux) && defined(CDROM_SEND_PACKET)
1532 struct linux_cdrom_generic_command cmd
;
1533 struct request_sense sense
;
1536 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH
))
1537 return STATUS_BUFFER_TOO_SMALL
;
1539 if (pPacket
->CdbLength
> 12)
1540 return STATUS_INVALID_PARAMETER
;
1542 if (pPacket
->SenseInfoLength
> sizeof(sense
))
1543 return STATUS_INVALID_PARAMETER
;
1545 memset(&cmd
, 0, sizeof(cmd
));
1546 memset(&sense
, 0, sizeof(sense
));
1548 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1550 if ( pPacket
->DataBufferOffset
> 0x1000 )
1552 cmd
.buffer
= (void*)pPacket
->DataBufferOffset
;
1556 cmd
.buffer
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1558 cmd
.buflen
= pPacket
->DataTransferLength
;
1561 cmd
.timeout
= pPacket
->TimeOutValue
*HZ
;
1563 switch (pPacket
->DataIn
)
1565 case SCSI_IOCTL_DATA_OUT
:
1566 cmd
.data_direction
= CGC_DATA_WRITE
;
1568 case SCSI_IOCTL_DATA_IN
:
1569 cmd
.data_direction
= CGC_DATA_READ
;
1571 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1572 cmd
.data_direction
= CGC_DATA_NONE
;
1575 return STATUS_INVALID_PARAMETER
;
1578 io
= ioctl(fd
, CDROM_SEND_PACKET
, &cmd
);
1580 if (pPacket
->SenseInfoLength
!= 0)
1582 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1583 &sense
, pPacket
->SenseInfoLength
);
1586 pPacket
->ScsiStatus
= cmd
.stat
;
1588 ret
= CDROM_GetStatusCode(io
);
1590 #elif defined(__NetBSD__)
1594 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH
))
1595 return STATUS_BUFFER_TOO_SMALL
;
1597 if (pPacket
->CdbLength
> 12)
1598 return STATUS_INVALID_PARAMETER
;
1600 if (pPacket
->SenseInfoLength
> SENSEBUFLEN
)
1601 return STATUS_INVALID_PARAMETER
;
1603 memset(&cmd
, 0, sizeof(cmd
));
1604 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1606 if ( pPacket
->DataBufferOffset
> 0x1000 )
1608 cmd
.databuf
= (void*)pPacket
->DataBufferOffset
;
1612 cmd
.databuf
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1615 cmd
.cmdlen
= pPacket
->CdbLength
;
1616 cmd
.datalen
= pPacket
->DataTransferLength
;
1617 cmd
.senselen
= pPacket
->SenseInfoLength
;
1618 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1620 switch (pPacket
->DataIn
)
1622 case SCSI_IOCTL_DATA_OUT
:
1623 cmd
.flags
|= SCCMD_WRITE
;
1625 case SCSI_IOCTL_DATA_IN
:
1626 cmd
.flags
|= SCCMD_READ
;
1628 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1632 return STATUS_INVALID_PARAMETER
;
1635 io
= ioctl(fd
, SCIOCCOMMAND
, &cmd
);
1639 case SCCMD_OK
: break;
1640 case SCCMD_TIMEOUT
: return STATUS_TIMEOUT
;
1642 case SCCMD_BUSY
: return STATUS_DEVICE_BUSY
;
1644 case SCCMD_SENSE
: break;
1645 case SCCMD_UNKNOWN
: return STATUS_UNSUCCESSFUL
;
1649 if (pPacket
->SenseInfoLength
!= 0)
1651 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1652 cmd
.sense
, pPacket
->SenseInfoLength
);
1655 pPacket
->ScsiStatus
= cmd
.status
;
1657 ret
= CDROM_GetStatusCode(io
);
1662 /******************************************************************
1667 static NTSTATUS
CDROM_ScsiGetCaps(PIO_SCSI_CAPABILITIES caps
)
1669 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
1671 caps
->Length
= sizeof(*caps
);
1673 caps
->MaximumTransferLength
= SG_SCATTER_SZ
; /* FIXME */
1674 caps
->MaximumPhysicalPages
= SG_SCATTER_SZ
/ getpagesize();
1675 caps
->SupportedAsynchronousEvents
= TRUE
;
1676 caps
->AlignmentMask
= getpagesize();
1677 caps
->TaggedQueuing
= FALSE
; /* we could check that it works and answer TRUE */
1678 caps
->AdapterScansDown
= FALSE
; /* FIXME ? */
1679 caps
->AdapterUsesPio
= FALSE
; /* FIXME ? */
1680 ret
= STATUS_SUCCESS
;
1682 FIXME("Unimplemented\n");
1687 /******************************************************************
1690 * implements IOCTL_SCSI_GET_ADDRESS
1692 static NTSTATUS
CDROM_GetAddress(int fd
, SCSI_ADDRESS
* address
)
1694 int portnum
, busid
, targetid
, lun
;
1696 address
->Length
= sizeof(SCSI_ADDRESS
);
1697 if ( ! CDROM_GetInterfaceInfo(fd
, &portnum
, &busid
, &targetid
, &lun
))
1698 return STATUS_NOT_SUPPORTED
;
1700 address
->PortNumber
= portnum
;
1701 address
->PathId
= busid
; /* bus number */
1702 address
->TargetId
= targetid
;
1704 return STATUS_SUCCESS
;
1707 /******************************************************************
1712 static NTSTATUS
DVD_StartSession(int fd
, PDVD_SESSION_ID sid_in
, PDVD_SESSION_ID sid_out
)
1715 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1716 dvd_authinfo auth_info
;
1718 memset( &auth_info
, 0, sizeof( auth_info
) );
1719 auth_info
.type
= DVD_LU_SEND_AGID
;
1720 if (sid_in
) auth_info
.lsa
.agid
= *(int*)sid_in
; /* ?*/
1722 TRACE("fd 0x%08x\n",fd
);
1723 ret
=CDROM_GetStatusCode(ioctl(fd
, DVD_AUTH
, &auth_info
));
1724 *sid_out
= auth_info
.lsa
.agid
;
1726 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1727 return STATUS_NOT_SUPPORTED
;
1729 return STATUS_NOT_SUPPORTED
;
1733 /******************************************************************
1738 static NTSTATUS
DVD_EndSession(int fd
, PDVD_SESSION_ID sid
)
1741 dvd_authinfo auth_info
;
1743 memset( &auth_info
, 0, sizeof( auth_info
) );
1744 auth_info
.type
= DVD_INVALIDATE_AGID
;
1745 auth_info
.lsa
.agid
= *(int*)sid
;
1748 return CDROM_GetStatusCode(ioctl(fd
, DVD_AUTH
, &auth_info
));
1749 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1750 return STATUS_NOT_SUPPORTED
;
1752 return STATUS_NOT_SUPPORTED
;
1756 /******************************************************************
1761 static NTSTATUS
DVD_SendKey(int fd
, PDVD_COPY_PROTECT_KEY key
)
1764 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1765 dvd_authinfo auth_info
;
1767 memset( &auth_info
, 0, sizeof( auth_info
) );
1768 switch (key
->KeyType
)
1770 case DvdChallengeKey
:
1771 auth_info
.type
= DVD_HOST_SEND_CHALLENGE
;
1772 auth_info
.hsc
.agid
= (int)key
->SessionId
;
1773 TRACE("DvdChallengeKey ioc 0x%x\n", DVD_AUTH
);
1774 memcpy( auth_info
.hsc
.chal
, key
->KeyData
, DVD_CHALLENGE_SIZE
);
1775 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1778 auth_info
.type
= DVD_HOST_SEND_KEY2
;
1779 auth_info
.hsk
.agid
= (int)key
->SessionId
;
1781 memcpy( auth_info
.hsk
.key
, key
->KeyData
, DVD_KEY_SIZE
);
1783 TRACE("DvdBusKey2\n");
1784 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1788 FIXME("Unknown Keytype 0x%x\n",key
->KeyType
);
1791 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1793 return STATUS_NOT_SUPPORTED
;
1796 return STATUS_NOT_SUPPORTED
;
1798 TRACE("not reached\n");
1801 /******************************************************************
1806 static NTSTATUS
DVD_ReadKey(int fd
, PDVD_COPY_PROTECT_KEY key
)
1809 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1811 dvd_authinfo auth_info
;
1813 memset( &dvd
, 0, sizeof( dvd_struct
) );
1814 memset( &auth_info
, 0, sizeof( auth_info
) );
1815 switch (key
->KeyType
)
1819 dvd
.type
= DVD_STRUCT_DISCKEY
;
1820 dvd
.disckey
.agid
= (int)key
->SessionId
;
1821 memset( dvd
.disckey
.value
, 0, DVD_DISCKEY_SIZE
);
1823 TRACE("DvdDiskKey\n");
1824 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_READ_STRUCT
, &dvd
));
1825 if (ret
== STATUS_SUCCESS
)
1826 memcpy(key
->KeyData
,dvd
.disckey
.value
,DVD_DISCKEY_SIZE
);
1829 auth_info
.type
= DVD_LU_SEND_TITLE_KEY
;
1830 auth_info
.lstk
.agid
= (int)key
->SessionId
;
1831 auth_info
.lstk
.lba
= (int)(key
->Parameters
.TitleOffset
.QuadPart
>>11);
1832 TRACE("DvdTitleKey session %d Quadpart 0x%08lx offset 0x%08x\n",
1833 (int)key
->SessionId
, (long)key
->Parameters
.TitleOffset
.QuadPart
,
1834 auth_info
.lstk
.lba
);
1835 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1836 if (ret
== STATUS_SUCCESS
)
1837 memcpy(key
->KeyData
, auth_info
.lstk
.title_key
, DVD_KEY_SIZE
);
1839 case DvdChallengeKey
:
1841 auth_info
.type
= DVD_LU_SEND_CHALLENGE
;
1842 auth_info
.lsc
.agid
= (int)key
->SessionId
;
1844 TRACE("DvdChallengeKey\n");
1845 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1846 if (ret
== STATUS_SUCCESS
)
1847 memcpy( key
->KeyData
, auth_info
.lsc
.chal
, DVD_CHALLENGE_SIZE
);
1850 auth_info
.type
= DVD_LU_SEND_ASF
;
1852 auth_info
.lsasf
.asf
=((PDVD_ASF
)key
->KeyData
)->SuccessFlag
;
1853 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1854 ((PDVD_ASF
)key
->KeyData
)->SuccessFlag
= auth_info
.lsasf
.asf
;
1857 auth_info
.type
= DVD_LU_SEND_KEY1
;
1858 auth_info
.lsk
.agid
= (int)key
->SessionId
;
1860 TRACE("DvdBusKey1\n");
1861 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1863 if (ret
== STATUS_SUCCESS
)
1864 memcpy( key
->KeyData
, auth_info
.lsk
.key
, DVD_KEY_SIZE
);
1867 auth_info
.type
= DVD_LU_SEND_RPC_STATE
;
1869 TRACE("DvdGetRpcKey\n");
1870 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1872 if (ret
== STATUS_SUCCESS
)
1874 ((PDVD_RPC_KEY
)key
->KeyData
)->TypeCode
= auth_info
.lrpcs
.type
;
1875 ((PDVD_RPC_KEY
)key
->KeyData
)->RegionMask
= auth_info
.lrpcs
.region_mask
;
1876 ((PDVD_RPC_KEY
)key
->KeyData
)->RpcScheme
= auth_info
.lrpcs
.rpc_scheme
;
1880 FIXME("Unknown keytype 0x%x\n",key
->KeyType
);
1883 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1885 return STATUS_NOT_SUPPORTED
;
1888 return STATUS_NOT_SUPPORTED
;
1890 TRACE("not reached\n");
1893 /******************************************************************
1898 static NTSTATUS
DVD_GetRegion(int dev
, PDVD_REGION region
)
1901 return STATUS_SUCCESS
;
1905 /******************************************************************
1910 static NTSTATUS
DVD_ReadStructure(int dev
, PDVD_READ_STRUCTURE structure
, PDVD_LAYER_DESCRIPTOR layer
)
1913 return STATUS_SUCCESS
;
1916 /******************************************************************
1917 * CDROM_DeviceIoControl
1921 NTSTATUS
CDROM_DeviceIoControl(HANDLE hDevice
,
1922 HANDLE hEvent
, PIO_APC_ROUTINE UserApcRoutine
,
1923 PVOID UserApcContext
,
1924 PIO_STATUS_BLOCK piosb
,
1925 ULONG dwIoControlCode
,
1926 LPVOID lpInBuffer
, DWORD nInBufferSize
,
1927 LPVOID lpOutBuffer
, DWORD nOutBufferSize
)
1930 NTSTATUS status
= STATUS_SUCCESS
;
1933 TRACE("%lx %s %lx %ld %lx %ld %p\n",
1934 (DWORD
)hDevice
, iocodex(dwIoControlCode
), (DWORD
)lpInBuffer
, nInBufferSize
,
1935 (DWORD
)lpOutBuffer
, nOutBufferSize
, piosb
);
1937 piosb
->Information
= 0;
1939 if ((status
= wine_server_handle_to_fd( hDevice
, 0, &fd
, NULL
))) goto error
;
1940 if ((status
= CDROM_Open(fd
, &dev
)))
1942 wine_server_release_fd( hDevice
, fd
);
1946 switch (dwIoControlCode
)
1948 case IOCTL_STORAGE_CHECK_VERIFY
:
1949 case IOCTL_CDROM_CHECK_VERIFY
:
1951 CDROM_ClearCacheEntry(dev
);
1952 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1953 status
= STATUS_INVALID_PARAMETER
;
1954 else status
= CDROM_Verify(dev
, fd
);
1957 /* EPP case IOCTL_STORAGE_CHECK_VERIFY2: */
1959 /* EPP case IOCTL_STORAGE_FIND_NEW_DEVICES: */
1960 /* EPP case IOCTL_CDROM_FIND_NEW_DEVICES: */
1962 case IOCTL_STORAGE_LOAD_MEDIA
:
1963 case IOCTL_CDROM_LOAD_MEDIA
:
1965 CDROM_ClearCacheEntry(dev
);
1966 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1967 status
= STATUS_INVALID_PARAMETER
;
1968 else status
= CDROM_SetTray(fd
, FALSE
);
1970 case IOCTL_STORAGE_EJECT_MEDIA
:
1972 CDROM_ClearCacheEntry(dev
);
1973 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
1974 status
= STATUS_INVALID_PARAMETER
;
1975 else status
= CDROM_SetTray(fd
, TRUE
);
1978 case IOCTL_CDROM_MEDIA_REMOVAL
:
1979 case IOCTL_DISK_MEDIA_REMOVAL
:
1980 case IOCTL_STORAGE_MEDIA_REMOVAL
:
1981 case IOCTL_STORAGE_EJECTION_CONTROL
:
1982 /* FIXME the last ioctl:s is not the same as the two others...
1983 * lockcount/owner should be handled */
1985 CDROM_ClearCacheEntry(dev
);
1986 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
1987 else if (nInBufferSize
< sizeof(PREVENT_MEDIA_REMOVAL
)) status
= STATUS_BUFFER_TOO_SMALL
;
1988 else status
= CDROM_ControlEjection(fd
, (const PREVENT_MEDIA_REMOVAL
*)lpInBuffer
);
1991 /* EPP case IOCTL_STORAGE_GET_MEDIA_TYPES: */
1993 case IOCTL_STORAGE_GET_DEVICE_NUMBER
:
1994 sz
= sizeof(STORAGE_DEVICE_NUMBER
);
1995 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
1996 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
1997 else status
= CDROM_GetDeviceNumber(dev
, (STORAGE_DEVICE_NUMBER
*)lpOutBuffer
);
2000 case IOCTL_STORAGE_RESET_DEVICE
:
2002 CDROM_ClearCacheEntry(dev
);
2003 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2004 status
= STATUS_INVALID_PARAMETER
;
2005 else status
= CDROM_ResetAudio(fd
);
2008 case IOCTL_CDROM_GET_CONTROL
:
2009 sz
= sizeof(CDROM_AUDIO_CONTROL
);
2010 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2011 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2012 else status
= CDROM_GetControl(dev
, (CDROM_AUDIO_CONTROL
*)lpOutBuffer
);
2015 case IOCTL_CDROM_GET_DRIVE_GEOMETRY
:
2016 sz
= sizeof(DISK_GEOMETRY
);
2017 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2018 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2019 else status
= CDROM_GetDriveGeometry(dev
, fd
, (DISK_GEOMETRY
*)lpOutBuffer
);
2022 case IOCTL_CDROM_DISK_TYPE
:
2023 sz
= sizeof(CDROM_DISK_DATA
);
2024 /* CDROM_ClearCacheEntry(dev); */
2025 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2026 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2027 else status
= CDROM_GetDiskData(dev
, fd
, (CDROM_DISK_DATA
*)lpOutBuffer
);
2030 /* EPP case IOCTL_CDROM_GET_LAST_SESSION: */
2032 case IOCTL_CDROM_READ_Q_CHANNEL
:
2033 sz
= sizeof(SUB_Q_CHANNEL_DATA
);
2034 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(CDROM_SUB_Q_DATA_FORMAT
))
2035 status
= STATUS_INVALID_PARAMETER
;
2036 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2037 else status
= CDROM_ReadQChannel(dev
, fd
, (const CDROM_SUB_Q_DATA_FORMAT
*)lpInBuffer
,
2038 (SUB_Q_CHANNEL_DATA
*)lpOutBuffer
);
2041 case IOCTL_CDROM_READ_TOC
:
2042 sz
= sizeof(CDROM_TOC
);
2043 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2044 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2045 else status
= CDROM_ReadTOC(dev
, fd
, (CDROM_TOC
*)lpOutBuffer
);
2048 /* EPP case IOCTL_CDROM_READ_TOC_EX: */
2050 case IOCTL_CDROM_PAUSE_AUDIO
:
2052 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2053 status
= STATUS_INVALID_PARAMETER
;
2054 else status
= CDROM_PauseAudio(fd
);
2056 case IOCTL_CDROM_PLAY_AUDIO_MSF
:
2058 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2059 else if (nInBufferSize
< sizeof(CDROM_PLAY_AUDIO_MSF
)) status
= STATUS_BUFFER_TOO_SMALL
;
2060 else status
= CDROM_PlayAudioMSF(fd
, (const CDROM_PLAY_AUDIO_MSF
*)lpInBuffer
);
2062 case IOCTL_CDROM_RESUME_AUDIO
:
2064 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2065 status
= STATUS_INVALID_PARAMETER
;
2066 else status
= CDROM_ResumeAudio(fd
);
2068 case IOCTL_CDROM_SEEK_AUDIO_MSF
:
2070 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2071 else if (nInBufferSize
< sizeof(CDROM_SEEK_AUDIO_MSF
)) status
= STATUS_BUFFER_TOO_SMALL
;
2072 else status
= CDROM_SeekAudioMSF(dev
, fd
, (const CDROM_SEEK_AUDIO_MSF
*)lpInBuffer
);
2074 case IOCTL_CDROM_STOP_AUDIO
:
2076 CDROM_ClearCacheEntry(dev
); /* Maybe intention is to change media */
2077 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2078 status
= STATUS_INVALID_PARAMETER
;
2079 else status
= CDROM_StopAudio(fd
);
2081 case IOCTL_CDROM_GET_VOLUME
:
2082 sz
= sizeof(VOLUME_CONTROL
);
2083 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2084 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2085 else status
= CDROM_GetVolume(fd
, (VOLUME_CONTROL
*)lpOutBuffer
);
2087 case IOCTL_CDROM_SET_VOLUME
:
2089 CDROM_ClearCacheEntry(dev
);
2090 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(VOLUME_CONTROL
) || lpOutBuffer
!= NULL
)
2091 status
= STATUS_INVALID_PARAMETER
;
2092 else status
= CDROM_SetVolume(fd
, (const VOLUME_CONTROL
*)lpInBuffer
);
2094 case IOCTL_CDROM_RAW_READ
:
2096 if (nInBufferSize
< sizeof(RAW_READ_INFO
)) status
= STATUS_INVALID_PARAMETER
;
2097 else if (lpOutBuffer
== NULL
) status
= STATUS_BUFFER_TOO_SMALL
;
2098 else status
= CDROM_RawRead(fd
, (const RAW_READ_INFO
*)lpInBuffer
,
2099 lpOutBuffer
, nOutBufferSize
, &sz
);
2101 case IOCTL_SCSI_GET_ADDRESS
:
2102 sz
= sizeof(SCSI_ADDRESS
);
2103 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2104 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2105 else status
= CDROM_GetAddress(fd
, (SCSI_ADDRESS
*)lpOutBuffer
);
2107 case IOCTL_SCSI_PASS_THROUGH_DIRECT
:
2108 sz
= sizeof(SCSI_PASS_THROUGH_DIRECT
);
2109 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2110 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH_DIRECT
)) status
= STATUS_BUFFER_TOO_SMALL
;
2111 else status
= CDROM_ScsiPassThroughDirect(fd
, (PSCSI_PASS_THROUGH_DIRECT
)lpOutBuffer
);
2113 case IOCTL_SCSI_PASS_THROUGH
:
2114 sz
= sizeof(SCSI_PASS_THROUGH
);
2115 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2116 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH
)) status
= STATUS_BUFFER_TOO_SMALL
;
2117 else status
= CDROM_ScsiPassThrough(fd
, (PSCSI_PASS_THROUGH
)lpOutBuffer
);
2119 case IOCTL_SCSI_GET_CAPABILITIES
:
2120 sz
= sizeof(IO_SCSI_CAPABILITIES
);
2121 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2122 else if (nOutBufferSize
< sizeof(IO_SCSI_CAPABILITIES
)) status
= STATUS_BUFFER_TOO_SMALL
;
2123 else status
= CDROM_ScsiGetCaps((PIO_SCSI_CAPABILITIES
)lpOutBuffer
);
2125 case IOCTL_DVD_START_SESSION
:
2126 sz
= sizeof(DVD_SESSION_ID
);
2127 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2128 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2131 TRACE("before in 0x%08lx out 0x%08lx\n",(lpInBuffer
)?*(PDVD_SESSION_ID
)lpInBuffer
:0,
2132 *(PDVD_SESSION_ID
)lpOutBuffer
);
2133 status
= DVD_StartSession(fd
, (PDVD_SESSION_ID
)lpInBuffer
, (PDVD_SESSION_ID
)lpOutBuffer
);
2134 TRACE("before in 0x%08lx out 0x%08lx\n",(lpInBuffer
)?*(PDVD_SESSION_ID
)lpInBuffer
:0,
2135 *(PDVD_SESSION_ID
)lpOutBuffer
);
2138 case IOCTL_DVD_END_SESSION
:
2139 sz
= sizeof(DVD_SESSION_ID
);
2140 if ((lpInBuffer
== NULL
) || (nInBufferSize
< sz
))status
= STATUS_INVALID_PARAMETER
;
2141 else status
= DVD_EndSession(fd
, (PDVD_SESSION_ID
)lpInBuffer
);
2143 case IOCTL_DVD_SEND_KEY
:
2146 (((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
!= nInBufferSize
))
2147 status
= STATUS_INVALID_PARAMETER
;
2150 TRACE("doing DVD_SendKey\n");
2151 status
= DVD_SendKey(fd
, (PDVD_COPY_PROTECT_KEY
)lpInBuffer
);
2154 case IOCTL_DVD_READ_KEY
:
2156 (((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
!= nInBufferSize
))
2157 status
= STATUS_INVALID_PARAMETER
;
2158 else if (lpInBuffer
!=lpOutBuffer
) status
= STATUS_BUFFER_TOO_SMALL
;
2161 TRACE("doing DVD_READ_KEY\n");
2162 sz
= ((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
;
2163 status
= DVD_ReadKey(fd
, (PDVD_COPY_PROTECT_KEY
)lpInBuffer
);
2166 case IOCTL_DVD_GET_REGION
:
2167 sz
= sizeof(DVD_REGION
);
2168 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2169 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2170 TRACE("doing DVD_Get_REGION\n");
2171 status
= DVD_GetRegion(fd
, (PDVD_REGION
)lpOutBuffer
);
2173 case IOCTL_DVD_READ_STRUCTURE
:
2174 sz
= sizeof(DVD_LAYER_DESCRIPTOR
);
2175 if (lpInBuffer
== NULL
|| nInBufferSize
!= sizeof(DVD_READ_STRUCTURE
)) status
= STATUS_INVALID_PARAMETER
;
2176 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2177 TRACE("doing DVD_READ_STRUCTURE\n");
2178 status
= DVD_ReadStructure(fd
, (PDVD_READ_STRUCTURE
)lpInBuffer
, (PDVD_LAYER_DESCRIPTOR
)lpOutBuffer
);
2182 FIXME("Unsupported IOCTL %lx (type=%lx access=%lx func=%lx meth=%lx)\n",
2183 dwIoControlCode
, dwIoControlCode
>> 16, (dwIoControlCode
>> 14) & 3,
2184 (dwIoControlCode
>> 2) & 0xFFF, dwIoControlCode
& 3);
2186 status
= STATUS_INVALID_PARAMETER
;
2189 wine_server_release_fd( hDevice
, fd
);
2191 piosb
->u
.Status
= status
;
2192 piosb
->Information
= sz
;
2193 if (hEvent
) NtSetEvent(hEvent
, NULL
);