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 #ifdef HAVE_IOKIT_IOKITLIB_H
80 # include <IOKit/IOKitLib.h>
81 # include <IOKit/scsi/SCSICmds_REQUEST_SENSE_Defs.h>
82 # define SENSEBUFLEN kSenseDefaultSize
86 #define NONAMELESSUNION
87 #define NONAMELESSSTRUCT
95 #include "ntdll_misc.h"
96 #include "wine/server.h"
97 #include "wine/library.h"
98 #include "wine/debug.h"
100 WINE_DEFAULT_DEBUG_CHANNEL(cdrom
);
102 /* Non-Linux systems do not have linux/cdrom.h and the like, and thus
103 lack the following constants. */
106 # define CD_SECS 60 /* seconds per minute */
109 # define CD_FRAMES 75 /* frames per second */
112 /* definitions taken from libdvdcss */
114 #define IOCTL_DVD_BASE FILE_DEVICE_DVD
116 #define IOCTL_DVD_START_SESSION CTL_CODE(IOCTL_DVD_BASE, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS)
117 #define IOCTL_DVD_READ_KEY CTL_CODE(IOCTL_DVD_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS)
118 #define IOCTL_DVD_SEND_KEY CTL_CODE(IOCTL_DVD_BASE, 0x0402, METHOD_BUFFERED, FILE_READ_ACCESS)
119 #define IOCTL_DVD_END_SESSION CTL_CODE(IOCTL_DVD_BASE, 0x0403, METHOD_BUFFERED, FILE_READ_ACCESS)
120 #define IOCTL_DVD_SET_READ_AHEAD CTL_CODE(IOCTL_DVD_BASE, 0x0404, METHOD_BUFFERED, FILE_READ_ACCESS)
121 #define IOCTL_DVD_GET_REGION CTL_CODE(IOCTL_DVD_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS)
122 #define IOCTL_DVD_SEND_KEY2 CTL_CODE(IOCTL_DVD_BASE, 0x0406, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
124 #define IOCTL_DVD_READ_STRUCTURE CTL_CODE(IOCTL_DVD_BASE, 0x0450, METHOD_BUFFERED, FILE_READ_ACCESS)
127 DvdChallengeKey
= 0x01,
135 DvdInvalidateAGID
= 0x3f
138 typedef ULONG DVD_SESSION_ID
, *PDVD_SESSION_ID
;
140 typedef struct _DVD_COPY_PROTECT_KEY
{
142 DVD_SESSION_ID SessionId
;
143 DVD_KEY_TYPE KeyType
;
148 ULONG Reserved
; /* used for NT alignment */
150 LARGE_INTEGER TitleOffset
;
153 } DVD_COPY_PROTECT_KEY
, *PDVD_COPY_PROTECT_KEY
;
155 typedef struct _DVD_RPC_KEY
{
156 UCHAR UserResetsAvailable
:3;
157 UCHAR ManufacturerResetsAvailable
:3;
162 } DVD_RPC_KEY
, * PDVD_RPC_KEY
;
164 typedef struct _DVD_ASF
{
168 } DVD_ASF
, * PDVD_ASF
;
170 typedef struct _DVD_REGION
172 unsigned char copy_system
;
173 unsigned char region_data
; /* current media region (not playable when set) */
174 unsigned char system_region
; /* current drive region (playable when set) */
175 unsigned char reset_count
; /* number of resets available */
176 } DVD_REGION
, * PDVD_REGION
;
178 typedef struct _DVD_READ_STRUCTURE
{
179 /* Contains an offset to the logical block address of the descriptor to be retrieved. */
180 LARGE_INTEGER block_byte_offset
;
182 /* 0:Physical descriptor, 1:Copyright descriptor, 2:Disk key descriptor
183 3:BCA descriptor, 4:Manufacturer descriptor, 5:Max descriptor
187 /* Session ID, that is obtained by IOCTL_DVD_START_SESSION */
191 unsigned char layer_no
;
192 }DVD_READ_STRUCTURE
, * PDVD_READ_STRUCTURE
;
194 typedef struct _DVD_LAYER_DESCRIPTOR
196 unsigned short length
;
198 unsigned char book_version
: 4;
200 /* 0:DVD-ROM, 1:DVD-RAM, 2:DVD-R, 3:DVD-RW, 9:DVD-RW */
201 unsigned char book_type
: 4;
203 unsigned char minimum_rate
: 4;
205 /* The physical size of the media. 0:120 mm, 1:80 mm. */
206 unsigned char disk_size
: 4;
208 /* 1:Read-only layer, 2:Recordable layer, 4:Rewritable layer */
209 unsigned char layer_type
: 4;
211 /* 0:parallel track path, 1:opposite track path */
212 unsigned char track_path
: 1;
214 /* 0:one layers, 1:two layers, and so on */
215 unsigned char num_of_layers
: 2;
217 unsigned char reserved1
: 1;
219 /* 0:0.74 µm/track, 1:0.80 µm/track, 2:0.615 µm/track */
220 unsigned char track_density
: 4;
222 /* 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 */
223 unsigned char linear_density
: 4;
225 /* Must be either 0x30000:DVD-ROM or DVD-R/-RW or 0x31000:DVD-RAM or DVD+RW */
226 unsigned long starting_data_sector
;
228 unsigned long end_data_sector
;
229 unsigned long end_layer_zero_sector
;
230 unsigned char reserved5
: 7;
232 /* 0 indicates no BCA data */
233 unsigned char BCA_flag
: 1;
235 unsigned char reserved6
;
236 }DVD_LAYER_DESCRIPTOR
, * PDVD_LAYER_DESCRIPTOR
;
238 typedef struct _DVD_COPYRIGHT_DESCRIPTOR
240 unsigned char protection
;
241 unsigned char region
;
242 unsigned short reserved
;
243 }DVD_COPYRIGHT_DESCRIPTOR
, * PDVD_COPYRIGHT_DESCRIPTOR
;
245 typedef struct _DVD_MANUFACTURER_DESCRIPTOR
247 unsigned char manufacturing
[2048];
248 }DVD_MANUFACTURER_DESCRIPTOR
, * PDVD_MANUFACTURER_DESCRIPTOR
;
250 #define DVD_CHALLENGE_KEY_LENGTH (12 + sizeof(DVD_COPY_PROTECT_KEY) - sizeof(UCHAR))
252 #define DVD_DISK_KEY_LENGTH (2048 + sizeof(DVD_COPY_PROTECT_KEY) - sizeof(UCHAR))
254 #define DVD_KEY_SIZE 5
255 #define DVD_CHALLENGE_SIZE 10
256 #define DVD_DISCKEY_SIZE 2048
257 #define DVD_SECTOR_PROTECTED 0x00000020
259 static const struct iocodexs
264 #define X(x) { x, #x },
265 X(IOCTL_CDROM_CHECK_VERIFY
)
266 X(IOCTL_CDROM_CURRENT_POSITION
)
267 X(IOCTL_CDROM_DISK_TYPE
)
268 X(IOCTL_CDROM_GET_CONTROL
)
269 X(IOCTL_CDROM_GET_DRIVE_GEOMETRY
)
270 X(IOCTL_CDROM_GET_VOLUME
)
271 X(IOCTL_CDROM_LOAD_MEDIA
)
272 X(IOCTL_CDROM_MEDIA_CATALOG
)
273 X(IOCTL_CDROM_MEDIA_REMOVAL
)
274 X(IOCTL_CDROM_PAUSE_AUDIO
)
275 X(IOCTL_CDROM_PLAY_AUDIO_MSF
)
276 X(IOCTL_CDROM_RAW_READ
)
277 X(IOCTL_CDROM_READ_Q_CHANNEL
)
278 X(IOCTL_CDROM_READ_TOC
)
279 X(IOCTL_CDROM_RESUME_AUDIO
)
280 X(IOCTL_CDROM_SEEK_AUDIO_MSF
)
281 X(IOCTL_CDROM_SET_VOLUME
)
282 X(IOCTL_CDROM_STOP_AUDIO
)
283 X(IOCTL_CDROM_TRACK_ISRC
)
284 X(IOCTL_DISK_MEDIA_REMOVAL
)
285 X(IOCTL_DVD_END_SESSION
)
286 X(IOCTL_DVD_GET_REGION
)
287 X(IOCTL_DVD_READ_KEY
)
288 X(IOCTL_DVD_READ_STRUCTURE
)
289 X(IOCTL_DVD_SEND_KEY
)
290 X(IOCTL_DVD_START_SESSION
)
291 X(IOCTL_SCSI_GET_ADDRESS
)
292 X(IOCTL_SCSI_GET_CAPABILITIES
)
293 X(IOCTL_SCSI_GET_INQUIRY_DATA
)
294 X(IOCTL_SCSI_PASS_THROUGH
)
295 X(IOCTL_SCSI_PASS_THROUGH_DIRECT
)
296 X(IOCTL_STORAGE_CHECK_VERIFY
)
297 X(IOCTL_STORAGE_EJECTION_CONTROL
)
298 X(IOCTL_STORAGE_EJECT_MEDIA
)
299 X(IOCTL_STORAGE_GET_DEVICE_NUMBER
)
300 X(IOCTL_STORAGE_LOAD_MEDIA
)
301 X(IOCTL_STORAGE_MEDIA_REMOVAL
)
302 X(IOCTL_STORAGE_RESET_DEVICE
)
305 static const char *iocodex(DWORD code
)
308 static char buffer
[25];
309 for(i
=0; i
<sizeof(iocodextable
)/sizeof(struct iocodexs
); i
++)
310 if (code
==iocodextable
[i
].code
)
311 return iocodextable
[i
].codex
;
312 sprintf(buffer
, "IOCTL_CODE_%x", (int)code
);
316 #define INQ_REPLY_LEN 36
317 #define INQ_CMD_LEN 6
319 #define FRAME_OF_ADDR(a) (((int)(a)[1] * CD_SECS + (a)[2]) * CD_FRAMES + (a)[3])
320 #define FRAME_OF_MSF(a) (((int)(a).M * CD_SECS + (a).S) * CD_FRAMES + (a).F)
321 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
322 #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;}
324 static NTSTATUS
CDROM_ReadTOC(int, int, CDROM_TOC
*);
325 static NTSTATUS
CDROM_GetStatusCode(int);
331 # define IDE6_MAJOR 88
334 # define IDE7_MAJOR 89
337 # ifdef CDROM_SEND_PACKET
338 /* structure for CDROM_PACKET_COMMAND ioctl */
339 /* not all Linux versions have all the fields, so we define the
340 * structure ourselves to make sure */
341 struct linux_cdrom_generic_command
343 unsigned char cmd
[CDROM_PACKET_SIZE
];
344 unsigned char *buffer
;
347 struct request_sense
*sense
;
348 unsigned char data_direction
;
353 # endif /* CDROM_SEND_PACKET */
357 /* FIXME: this is needed because we can't open simultaneously several times /dev/cdrom
358 * this should be removed when a proper device interface is implemented
360 * (WS) We need this to keep track of current position and to safely
361 * detect media changes. Besides this should provide a great speed up
367 char toc_good
; /* if false, will reread TOC from disk */
369 SUB_Q_CURRENT_POSITION CurrentPosition
;
371 /* who has more than 5 cdroms on his/her machine ?? */
372 /* FIXME: this should grow depending on the number of cdroms we install/configure
375 #define MAX_CACHE_ENTRIES 5
376 static struct cdrom_cache cdrom_cache
[MAX_CACHE_ENTRIES
];
378 static RTL_CRITICAL_SECTION cache_section
;
379 static RTL_CRITICAL_SECTION_DEBUG critsect_debug
=
381 0, 0, &cache_section
,
382 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
383 0, 0, { (DWORD_PTR
)(__FILE__
": cache_section") }
385 static RTL_CRITICAL_SECTION cache_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
387 /* Proposed media change function: not really needed at this time */
388 /* This is a 1 or 0 type of function */
390 static int CDROM_MediaChanged(int dev
)
394 struct cdrom_tochdr hdr
;
395 struct cdrom_tocentry entry
;
397 if (dev
< 0 || dev
>= MAX_CACHE_ENTRIES
)
399 if ( ioctl(cdrom_cache
[dev
].fd
, CDROMREADTOCHDR
, &hdr
) == -1 )
402 if ( memcmp(&hdr
, &cdrom_cache
[dev
].hdr
, sizeof(struct cdrom_tochdr
)) )
405 for (i
=hdr
.cdth_trk0
; i
<=hdr
.cdth_trk1
+1; i
++)
407 if (i
== hdr
.cdth_trk1
+ 1)
409 entry
.cdte_track
= CDROM_LEADOUT
;
411 entry
.cdte_track
= i
;
413 entry
.cdte_format
= CDROM_MSF
;
414 if ( ioctl(cdrom_cache
[dev
].fd
, CDROMREADTOCENTRY
, &entry
) == -1)
416 if ( memcmp(&entry
, cdrom_cache
[dev
].entry
+i
-hdr
.cdth_trk0
,
417 sizeof(struct cdrom_tocentry
)) )
424 /******************************************************************
425 * CDROM_SyncCache [internal]
427 * Read the TOC in and store it in the cdrom_cache structure.
428 * Further requests for the TOC will be copied from the cache
429 * unless certain events like disk ejection is detected, in which
430 * case the cache will be cleared, causing it to be resynced.
431 * The cache section must be held by caller.
433 static int CDROM_SyncCache(int dev
, int fd
)
437 struct cdrom_tochdr hdr
;
438 struct cdrom_tocentry entry
;
439 #elif defined(__FreeBSD__) || defined(__NetBSD__)
440 struct ioc_toc_header hdr
;
441 struct ioc_read_toc_entry entry
;
442 struct cd_toc_entry toc_buffer
;
444 CDROM_TOC
*toc
= &cdrom_cache
[dev
].toc
;
445 cdrom_cache
[dev
].toc_good
= 0;
449 io
= ioctl(fd
, CDROMREADTOCHDR
, &hdr
);
452 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
456 toc
->FirstTrack
= hdr
.cdth_trk0
;
457 toc
->LastTrack
= hdr
.cdth_trk1
;
458 tsz
= sizeof(toc
->FirstTrack
) + sizeof(toc
->LastTrack
)
459 + sizeof(TRACK_DATA
) * (toc
->LastTrack
-toc
->FirstTrack
+2);
460 toc
->Length
[0] = tsz
>> 8;
461 toc
->Length
[1] = tsz
;
463 TRACE("caching toc from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
465 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
467 if (i
== toc
->LastTrack
+ 1)
468 entry
.cdte_track
= CDROM_LEADOUT
;
470 entry
.cdte_track
= i
;
471 entry
.cdte_format
= CDROM_MSF
;
472 io
= ioctl(fd
, CDROMREADTOCENTRY
, &entry
);
474 WARN("error read entry (%s)\n", strerror(errno
));
477 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= entry
.cdte_ctrl
;
478 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= entry
.cdte_adr
;
479 /* marking last track with leadout value as index */
480 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.cdte_track
;
481 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
482 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = entry
.cdte_addr
.msf
.minute
;
483 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = entry
.cdte_addr
.msf
.second
;
484 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = entry
.cdte_addr
.msf
.frame
;
486 cdrom_cache
[dev
].toc_good
= 1;
488 #elif defined(__FreeBSD__) || defined(__NetBSD__)
490 io
= ioctl(fd
, CDIOREADTOCHEADER
, &hdr
);
493 WARN("(%d) -- Error occurred (%s)!\n", dev
, strerror(errno
));
496 toc
->FirstTrack
= hdr
.starting_track
;
497 toc
->LastTrack
= hdr
.ending_track
;
498 tsz
= sizeof(toc
->FirstTrack
) + sizeof(toc
->LastTrack
)
499 + sizeof(TRACK_DATA
) * (toc
->LastTrack
-toc
->FirstTrack
+2);
500 toc
->Length
[0] = tsz
>> 8;
501 toc
->Length
[1] = tsz
;
503 TRACE("caching toc from=%d to=%d\n", toc
->FirstTrack
, toc
->LastTrack
);
505 for (i
= toc
->FirstTrack
; i
<= toc
->LastTrack
+ 1; i
++)
507 if (i
== toc
->LastTrack
+ 1)
510 entry
.starting_track
= LEADOUT
;
512 entry
.starting_track
= i
;
514 memset((char *)&toc_buffer
, 0, sizeof(toc_buffer
));
515 entry
.address_format
= CD_MSF_FORMAT
;
516 entry
.data_len
= sizeof(toc_buffer
);
517 entry
.data
= &toc_buffer
;
518 io
= ioctl(fd
, CDIOREADTOCENTRYS
, &entry
);
520 WARN("error read entry (%s)\n", strerror(errno
));
523 toc
->TrackData
[i
- toc
->FirstTrack
].Control
= toc_buffer
.control
;
524 toc
->TrackData
[i
- toc
->FirstTrack
].Adr
= toc_buffer
.addr_type
;
525 /* marking last track with leadout value as index */
526 toc
->TrackData
[i
- toc
->FirstTrack
].TrackNumber
= entry
.starting_track
;
527 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[0] = 0;
528 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[1] = toc_buffer
.addr
.msf
.minute
;
529 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[2] = toc_buffer
.addr
.msf
.second
;
530 toc
->TrackData
[i
- toc
->FirstTrack
].Address
[3] = toc_buffer
.addr
.msf
.frame
;
532 cdrom_cache
[dev
].toc_good
= 1;
535 return STATUS_NOT_SUPPORTED
;
538 return CDROM_GetStatusCode(io
);
541 static void CDROM_ClearCacheEntry(int dev
)
543 RtlEnterCriticalSection( &cache_section
);
544 cdrom_cache
[dev
].toc_good
= 0;
545 RtlLeaveCriticalSection( &cache_section
);
550 /******************************************************************
551 * CDROM_GetInterfaceInfo
553 * Determines the ide interface (the number after the ide), and the
554 * number of the device on that interface for ide cdroms (*iface <= 1).
555 * Determines the scsi information for scsi cdroms (*iface >= 2).
556 * Returns false if the info cannot not be obtained.
558 static int CDROM_GetInterfaceInfo(int fd
, UCHAR
* iface
, UCHAR
* port
, UCHAR
* device
, UCHAR
* lun
)
562 if ( fstat(fd
, &st
) == -1 || ! S_ISBLK(st
.st_mode
)) return 0;
567 switch (major(st
.st_rdev
)) {
568 case IDE0_MAJOR
: *iface
= 0; break;
569 case IDE1_MAJOR
: *iface
= 1; break;
570 case IDE2_MAJOR
: *iface
= 2; break;
571 case IDE3_MAJOR
: *iface
= 3; break;
572 case IDE4_MAJOR
: *iface
= 4; break;
573 case IDE5_MAJOR
: *iface
= 5; break;
574 case IDE6_MAJOR
: *iface
= 6; break;
575 case IDE7_MAJOR
: *iface
= 7; break;
576 default: *port
= 1; break;
580 *device
= (minor(st
.st_rdev
) >> 6);
583 #ifdef SCSI_IOCTL_GET_IDLUN
585 if (ioctl(fd
, SCSI_IOCTL_GET_IDLUN
, &idlun
) != -1)
587 *port
= (idlun
[0] >> 24) & 0xff;
588 *iface
= ((idlun
[0] >> 16) & 0xff) + 2;
589 *device
= idlun
[0] & 0xff;
590 *lun
= (idlun
[0] >> 8) & 0xff;
595 WARN("CD-ROM device (%d, %d) not supported\n", major(st
.st_rdev
), minor(st
.st_rdev
));
600 #elif defined(__NetBSD__)
601 struct scsi_addr addr
;
602 if (ioctl(fd
, SCIOCIDENTIFY
, &addr
) != -1)
606 case TYPE_SCSI
: *port
= 1;
607 *iface
= addr
.addr
.scsi
.scbus
;
608 *device
= addr
.addr
.scsi
.target
;
609 *lun
= addr
.addr
.scsi
.lun
;
611 case TYPE_ATAPI
: *port
= 0;
612 *iface
= addr
.addr
.atapi
.atbus
;
613 *device
= addr
.addr
.atapi
.drive
;
620 #elif defined(__FreeBSD__)
621 FIXME("not implemented for BSD\n");
624 FIXME("not implemented for nonlinux\n");
630 /******************************************************************
634 static NTSTATUS
CDROM_Open(int fd
, int* dev
)
637 NTSTATUS ret
= STATUS_SUCCESS
;
642 RtlEnterCriticalSection( &cache_section
);
643 for (*dev
= 0; *dev
< MAX_CACHE_ENTRIES
; (*dev
)++)
646 cdrom_cache
[*dev
].device
== 0 &&
647 cdrom_cache
[*dev
].inode
== 0)
649 else if (cdrom_cache
[*dev
].device
== st
.st_dev
&&
650 cdrom_cache
[*dev
].inode
== st
.st_ino
)
653 if (*dev
== MAX_CACHE_ENTRIES
)
655 if (empty
== -1) ret
= STATUS_NOT_IMPLEMENTED
;
659 cdrom_cache
[*dev
].device
= st
.st_dev
;
660 cdrom_cache
[*dev
].inode
= st
.st_ino
;
663 RtlLeaveCriticalSection( &cache_section
);
665 TRACE("%d, %d\n", *dev
, fd
);
669 /******************************************************************
670 * CDROM_GetStatusCode
674 static NTSTATUS
CDROM_GetStatusCode(int io
)
676 if (io
== 0) return STATUS_SUCCESS
;
677 return FILE_GetNtStatus();
680 /******************************************************************
684 static NTSTATUS
CDROM_GetControl(int dev
, CDROM_AUDIO_CONTROL
* cac
)
686 cac
->LbaFormat
= 0; /* FIXME */
687 cac
->LogicalBlocksPerSecond
= 1; /* FIXME */
688 return STATUS_NOT_SUPPORTED
;
691 /******************************************************************
692 * CDROM_GetDeviceNumber
695 static NTSTATUS
CDROM_GetDeviceNumber(int dev
, STORAGE_DEVICE_NUMBER
* devnum
)
697 return STATUS_NOT_SUPPORTED
;
700 /******************************************************************
701 * CDROM_GetDriveGeometry
704 static NTSTATUS
CDROM_GetDriveGeometry(int dev
, int fd
, DISK_GEOMETRY
* dg
)
710 if ((ret
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return ret
;
712 fsize
= FRAME_OF_TOC(toc
, toc
.LastTrack
+1)
713 - FRAME_OF_TOC(toc
, 1); /* Total size in frames */
715 dg
->Cylinders
.u
.LowPart
= fsize
/ (64 * 32);
716 dg
->Cylinders
.u
.HighPart
= 0;
717 dg
->MediaType
= RemovableMedia
;
718 dg
->TracksPerCylinder
= 64;
719 dg
->SectorsPerTrack
= 32;
720 dg
->BytesPerSector
= 2048;
724 /**************************************************************************
725 * CDROM_Reset [internal]
727 static NTSTATUS
CDROM_ResetAudio(int fd
)
730 return CDROM_GetStatusCode(ioctl(fd
, CDROMRESET
));
731 #elif defined(__FreeBSD__) || defined(__NetBSD__)
732 return CDROM_GetStatusCode(ioctl(fd
, CDIOCRESET
, NULL
));
734 return STATUS_NOT_SUPPORTED
;
738 /******************************************************************
743 static NTSTATUS
CDROM_SetTray(int fd
, BOOL doEject
)
746 return CDROM_GetStatusCode(ioctl(fd
, doEject
? CDROMEJECT
: CDROMCLOSETRAY
));
747 #elif defined(__FreeBSD__) || defined(__NetBSD__)
748 return CDROM_GetStatusCode((ioctl(fd
, CDIOCALLOW
, NULL
)) ||
749 (ioctl(fd
, doEject
? CDIOCEJECT
: CDIOCCLOSE
, NULL
)) ||
750 (ioctl(fd
, CDIOCPREVENT
, NULL
)));
752 return STATUS_NOT_SUPPORTED
;
756 /******************************************************************
757 * CDROM_ControlEjection
761 static NTSTATUS
CDROM_ControlEjection(int fd
, const PREVENT_MEDIA_REMOVAL
* rmv
)
764 return CDROM_GetStatusCode(ioctl(fd
, CDROM_LOCKDOOR
, rmv
->PreventMediaRemoval
));
765 #elif defined(__FreeBSD__) || defined(__NetBSD__)
766 return CDROM_GetStatusCode(ioctl(fd
, (rmv
->PreventMediaRemoval
) ? CDIOCPREVENT
: CDIOCALLOW
, NULL
));
768 return STATUS_NOT_SUPPORTED
;
772 /******************************************************************
777 static NTSTATUS
CDROM_ReadTOC(int dev
, int fd
, CDROM_TOC
* toc
)
779 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
781 if (dev
< 0 || dev
>= MAX_CACHE_ENTRIES
)
782 return STATUS_INVALID_PARAMETER
;
784 RtlEnterCriticalSection( &cache_section
);
785 if (cdrom_cache
[dev
].toc_good
|| !(ret
= CDROM_SyncCache(dev
, fd
)))
787 *toc
= cdrom_cache
[dev
].toc
;
788 ret
= STATUS_SUCCESS
;
790 RtlLeaveCriticalSection( &cache_section
);
794 /******************************************************************
799 static NTSTATUS
CDROM_GetDiskData(int dev
, int fd
, CDROM_DISK_DATA
* data
)
805 if ((ret
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return ret
;
807 for (i
= toc
.FirstTrack
; i
<= toc
.LastTrack
; i
++) {
808 if (toc
.TrackData
[i
-toc
.FirstTrack
].Control
& 0x04)
809 data
->DiskData
|= CDROM_DISK_DATA_TRACK
;
811 data
->DiskData
|= CDROM_DISK_AUDIO_TRACK
;
813 return STATUS_SUCCESS
;
816 /******************************************************************
821 static NTSTATUS
CDROM_ReadQChannel(int dev
, int fd
, const CDROM_SUB_Q_DATA_FORMAT
* fmt
,
822 SUB_Q_CHANNEL_DATA
* data
)
824 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
827 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
829 struct cdrom_subchnl sc
;
830 sc
.cdsc_format
= CDROM_MSF
;
832 io
= ioctl(fd
, CDROMSUBCHNL
, &sc
);
835 TRACE("opened or no_media (%s)!\n", strerror(errno
));
836 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
837 CDROM_ClearCacheEntry(dev
);
841 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
843 switch (sc
.cdsc_audiostatus
) {
844 case CDROM_AUDIO_INVALID
:
845 CDROM_ClearCacheEntry(dev
);
846 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
848 case CDROM_AUDIO_NO_STATUS
:
849 CDROM_ClearCacheEntry(dev
);
850 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
852 case CDROM_AUDIO_PLAY
:
853 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
855 case CDROM_AUDIO_PAUSED
:
856 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
858 case CDROM_AUDIO_COMPLETED
:
859 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
861 case CDROM_AUDIO_ERROR
:
862 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
865 TRACE("status=%02X !\n", sc
.cdsc_audiostatus
);
870 case IOCTL_CDROM_CURRENT_POSITION
:
871 size
= sizeof(SUB_Q_CURRENT_POSITION
);
872 RtlEnterCriticalSection( &cache_section
);
873 if (hdr
->AudioStatus
==AUDIO_STATUS_IN_PROGRESS
) {
874 data
->CurrentPosition
.FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
875 data
->CurrentPosition
.Control
= sc
.cdsc_ctrl
;
876 data
->CurrentPosition
.ADR
= sc
.cdsc_adr
;
877 data
->CurrentPosition
.TrackNumber
= sc
.cdsc_trk
;
878 data
->CurrentPosition
.IndexNumber
= sc
.cdsc_ind
;
880 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
881 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.cdsc_absaddr
.msf
.minute
;
882 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.cdsc_absaddr
.msf
.second
;
883 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.cdsc_absaddr
.msf
.frame
;
885 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
886 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.cdsc_reladdr
.msf
.minute
;
887 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.cdsc_reladdr
.msf
.second
;
888 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.cdsc_reladdr
.msf
.frame
;
890 cdrom_cache
[dev
].CurrentPosition
= data
->CurrentPosition
;
892 else /* not playing */
894 cdrom_cache
[dev
].CurrentPosition
.Header
= *hdr
; /* Preserve header info */
895 data
->CurrentPosition
= cdrom_cache
[dev
].CurrentPosition
;
897 RtlLeaveCriticalSection( &cache_section
);
899 case IOCTL_CDROM_MEDIA_CATALOG
:
900 size
= sizeof(SUB_Q_MEDIA_CATALOG_NUMBER
);
901 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
903 struct cdrom_mcn mcn
;
904 if ((io
= ioctl(fd
, CDROM_GET_MCN
, &mcn
)) == -1) goto end
;
906 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
907 data
->MediaCatalog
.Mcval
= 0; /* FIXME */
908 memcpy(data
->MediaCatalog
.MediaCatalog
, mcn
.medium_catalog_number
, 14);
909 data
->MediaCatalog
.MediaCatalog
[14] = 0;
912 case IOCTL_CDROM_TRACK_ISRC
:
913 size
= sizeof(SUB_Q_CURRENT_POSITION
);
914 FIXME("TrackIsrc: NIY on linux\n");
915 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
916 data
->TrackIsrc
.Tcval
= 0;
922 ret
= CDROM_GetStatusCode(io
);
923 #elif defined(__FreeBSD__) || defined(__NetBSD__)
925 SUB_Q_HEADER
* hdr
= (SUB_Q_HEADER
*)data
;
927 struct ioc_read_subchannel read_sc
;
928 struct cd_sub_channel_info sc
;
930 read_sc
.address_format
= CD_MSF_FORMAT
;
932 read_sc
.data_len
= sizeof(sc
);
936 case IOCTL_CDROM_CURRENT_POSITION
:
937 read_sc
.data_format
= CD_CURRENT_POSITION
;
939 case IOCTL_CDROM_MEDIA_CATALOG
:
940 read_sc
.data_format
= CD_MEDIA_CATALOG
;
942 case IOCTL_CDROM_TRACK_ISRC
:
943 read_sc
.data_format
= CD_TRACK_INFO
;
944 sc
.what
.track_info
.track_number
= data
->TrackIsrc
.Track
;
947 io
= ioctl(fd
, CDIOCREADSUBCHANNEL
, &read_sc
);
950 TRACE("opened or no_media (%s)!\n", strerror(errno
));
951 CDROM_ClearCacheEntry(dev
);
952 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
956 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
958 switch (sc
.header
.audio_status
) {
959 case CD_AS_AUDIO_INVALID
:
960 CDROM_ClearCacheEntry(dev
);
961 hdr
->AudioStatus
= AUDIO_STATUS_NOT_SUPPORTED
;
963 case CD_AS_NO_STATUS
:
964 CDROM_ClearCacheEntry(dev
);
965 hdr
->AudioStatus
= AUDIO_STATUS_NO_STATUS
;
967 case CD_AS_PLAY_IN_PROGRESS
:
968 hdr
->AudioStatus
= AUDIO_STATUS_IN_PROGRESS
;
970 case CD_AS_PLAY_PAUSED
:
971 hdr
->AudioStatus
= AUDIO_STATUS_PAUSED
;
973 case CD_AS_PLAY_COMPLETED
:
974 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_COMPLETE
;
976 case CD_AS_PLAY_ERROR
:
977 hdr
->AudioStatus
= AUDIO_STATUS_PLAY_ERROR
;
980 TRACE("status=%02X !\n", sc
.header
.audio_status
);
984 case IOCTL_CDROM_CURRENT_POSITION
:
985 size
= sizeof(SUB_Q_CURRENT_POSITION
);
986 RtlEnterCriticalSection( &cache_section
);
987 if (hdr
->AudioStatus
==AUDIO_STATUS_IN_PROGRESS
) {
988 data
->CurrentPosition
.FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
989 data
->CurrentPosition
.Control
= sc
.what
.position
.control
;
990 data
->CurrentPosition
.ADR
= sc
.what
.position
.addr_type
;
991 data
->CurrentPosition
.TrackNumber
= sc
.what
.position
.track_number
;
992 data
->CurrentPosition
.IndexNumber
= sc
.what
.position
.index_number
;
994 data
->CurrentPosition
.AbsoluteAddress
[0] = 0;
995 data
->CurrentPosition
.AbsoluteAddress
[1] = sc
.what
.position
.absaddr
.msf
.minute
;
996 data
->CurrentPosition
.AbsoluteAddress
[2] = sc
.what
.position
.absaddr
.msf
.second
;
997 data
->CurrentPosition
.AbsoluteAddress
[3] = sc
.what
.position
.absaddr
.msf
.frame
;
998 data
->CurrentPosition
.TrackRelativeAddress
[0] = 0;
999 data
->CurrentPosition
.TrackRelativeAddress
[1] = sc
.what
.position
.reladdr
.msf
.minute
;
1000 data
->CurrentPosition
.TrackRelativeAddress
[2] = sc
.what
.position
.reladdr
.msf
.second
;
1001 data
->CurrentPosition
.TrackRelativeAddress
[3] = sc
.what
.position
.reladdr
.msf
.frame
;
1002 cdrom_cache
[dev
].CurrentPosition
= data
->CurrentPosition
;
1004 else { /* not playing */
1005 cdrom_cache
[dev
].CurrentPosition
.Header
= *hdr
; /* Preserve header info */
1006 data
->CurrentPosition
= cdrom_cache
[dev
].CurrentPosition
;
1008 RtlLeaveCriticalSection( &cache_section
);
1010 case IOCTL_CDROM_MEDIA_CATALOG
:
1011 size
= sizeof(SUB_Q_MEDIA_CATALOG_NUMBER
);
1012 data
->MediaCatalog
.FormatCode
= IOCTL_CDROM_MEDIA_CATALOG
;
1013 data
->MediaCatalog
.Mcval
= sc
.what
.media_catalog
.mc_valid
;
1014 memcpy(data
->MediaCatalog
.MediaCatalog
, sc
.what
.media_catalog
.mc_number
, 15);
1016 case IOCTL_CDROM_TRACK_ISRC
:
1017 size
= sizeof(SUB_Q_CURRENT_POSITION
);
1018 data
->TrackIsrc
.FormatCode
= IOCTL_CDROM_TRACK_ISRC
;
1019 data
->TrackIsrc
.Tcval
= sc
.what
.track_info
.ti_valid
;
1020 memcpy(data
->TrackIsrc
.TrackIsrc
, sc
.what
.track_info
.ti_number
, 15);
1025 ret
= CDROM_GetStatusCode(io
);
1030 /******************************************************************
1032 * Implements: IOCTL_STORAGE_CHECK_VERIFY
1033 * IOCTL_CDROM_CHECK_VERIFY
1034 * IOCTL_DISK_CHECK_VERIFY
1037 static NTSTATUS
CDROM_Verify(int dev
, int fd
)
1042 ret
= ioctl(fd
, CDROM_DRIVE_STATUS
, NULL
);
1044 TRACE("ioctl CDROM_DRIVE_STATUS failed(%s)!\n", strerror(errno
));
1045 return CDROM_GetStatusCode(ret
);
1048 if(ret
== CDS_DISC_OK
)
1049 return STATUS_SUCCESS
;
1051 return STATUS_NO_MEDIA_IN_DEVICE
;
1053 FIXME("not implemented for non-linux\n");
1054 return STATUS_NOT_SUPPORTED
;
1057 /******************************************************************
1058 * CDROM_PlayAudioMSF
1062 static NTSTATUS
CDROM_PlayAudioMSF(int fd
, const CDROM_PLAY_AUDIO_MSF
* audio_msf
)
1064 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1066 struct cdrom_msf msf
;
1069 msf
.cdmsf_min0
= audio_msf
->StartingM
;
1070 msf
.cdmsf_sec0
= audio_msf
->StartingS
;
1071 msf
.cdmsf_frame0
= audio_msf
->StartingF
;
1072 msf
.cdmsf_min1
= audio_msf
->EndingM
;
1073 msf
.cdmsf_sec1
= audio_msf
->EndingS
;
1074 msf
.cdmsf_frame1
= audio_msf
->EndingF
;
1076 io
= ioctl(fd
, CDROMSTART
);
1079 WARN("motor doesn't start !\n");
1082 io
= ioctl(fd
, CDROMPLAYMSF
, &msf
);
1085 WARN("device doesn't play !\n");
1088 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1089 msf
.cdmsf_min0
, msf
.cdmsf_sec0
, msf
.cdmsf_frame0
,
1090 msf
.cdmsf_min1
, msf
.cdmsf_sec1
, msf
.cdmsf_frame1
);
1092 ret
= CDROM_GetStatusCode(io
);
1093 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1094 struct ioc_play_msf msf
;
1097 msf
.start_m
= audio_msf
->StartingM
;
1098 msf
.start_s
= audio_msf
->StartingS
;
1099 msf
.start_f
= audio_msf
->StartingF
;
1100 msf
.end_m
= audio_msf
->EndingM
;
1101 msf
.end_s
= audio_msf
->EndingS
;
1102 msf
.end_f
= audio_msf
->EndingF
;
1104 io
= ioctl(fd
, CDIOCSTART
, NULL
);
1107 WARN("motor doesn't start !\n");
1110 io
= ioctl(fd
, CDIOCPLAYMSF
, &msf
);
1113 WARN("device doesn't play !\n");
1116 TRACE("msf = %d:%d:%d %d:%d:%d\n",
1117 msf
.start_m
, msf
.start_s
, msf
.start_f
,
1118 msf
.end_m
, msf
.end_s
, msf
.end_f
);
1120 ret
= CDROM_GetStatusCode(io
);
1125 /******************************************************************
1126 * CDROM_SeekAudioMSF
1130 static NTSTATUS
CDROM_SeekAudioMSF(int dev
, int fd
, const CDROM_SEEK_AUDIO_MSF
* audio_msf
)
1134 SUB_Q_CURRENT_POSITION
*cp
;
1136 struct cdrom_msf0 msf
;
1137 struct cdrom_subchnl sc
;
1138 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1139 struct ioc_play_msf msf
;
1140 struct ioc_read_subchannel read_sc
;
1141 struct cd_sub_channel_info sc
;
1145 /* Use the information on the TOC to compute the new current
1146 * position, which is shadowed on the cache. [Portable]. */
1147 frame
= FRAME_OF_MSF(*audio_msf
);
1149 if ((io
= CDROM_ReadTOC(dev
, fd
, &toc
)) != 0) return io
;
1151 for(i
=toc
.FirstTrack
;i
<=toc
.LastTrack
+1;i
++)
1152 if (FRAME_OF_TOC(toc
,i
)>frame
) break;
1153 if (i
<= toc
.FirstTrack
|| i
> toc
.LastTrack
+1)
1154 return STATUS_INVALID_PARAMETER
;
1156 RtlEnterCriticalSection( &cache_section
);
1157 cp
= &cdrom_cache
[dev
].CurrentPosition
;
1158 cp
->FormatCode
= IOCTL_CDROM_CURRENT_POSITION
;
1159 cp
->Control
= toc
.TrackData
[i
-toc
.FirstTrack
].Control
;
1160 cp
->ADR
= toc
.TrackData
[i
-toc
.FirstTrack
].Adr
;
1161 cp
->TrackNumber
= toc
.TrackData
[i
-toc
.FirstTrack
].TrackNumber
;
1162 cp
->IndexNumber
= 0; /* FIXME: where do they keep these? */
1163 cp
->AbsoluteAddress
[0] = 0;
1164 cp
->AbsoluteAddress
[1] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[1];
1165 cp
->AbsoluteAddress
[2] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[2];
1166 cp
->AbsoluteAddress
[3] = toc
.TrackData
[i
-toc
.FirstTrack
].Address
[3];
1167 frame
-= FRAME_OF_TOC(toc
,i
);
1168 cp
->TrackRelativeAddress
[0] = 0;
1169 MSF_OF_FRAME(cp
->TrackRelativeAddress
[1], frame
);
1170 RtlLeaveCriticalSection( &cache_section
);
1172 /* If playing, then issue a seek command, otherwise do nothing */
1174 sc
.cdsc_format
= CDROM_MSF
;
1176 io
= ioctl(fd
, CDROMSUBCHNL
, &sc
);
1179 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1180 CDROM_ClearCacheEntry(dev
);
1181 return CDROM_GetStatusCode(io
);
1183 if (sc
.cdsc_audiostatus
==CDROM_AUDIO_PLAY
)
1185 msf
.minute
= audio_msf
->M
;
1186 msf
.second
= audio_msf
->S
;
1187 msf
.frame
= audio_msf
->F
;
1188 return CDROM_GetStatusCode(ioctl(fd
, CDROMSEEK
, &msf
));
1190 return STATUS_SUCCESS
;
1191 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1192 read_sc
.address_format
= CD_MSF_FORMAT
;
1194 read_sc
.data_len
= sizeof(sc
);
1196 read_sc
.data_format
= CD_CURRENT_POSITION
;
1198 io
= ioctl(fd
, CDIOCREADSUBCHANNEL
, &read_sc
);
1201 TRACE("opened or no_media (%s)!\n", strerror(errno
));
1202 CDROM_ClearCacheEntry(dev
);
1203 return CDROM_GetStatusCode(io
);
1205 if (sc
.header
.audio_status
==CD_AS_PLAY_IN_PROGRESS
)
1208 msf
.start_m
= audio_msf
->M
;
1209 msf
.start_s
= audio_msf
->S
;
1210 msf
.start_f
= audio_msf
->F
;
1211 final_frame
= FRAME_OF_TOC(toc
,toc
.LastTrack
+1)-1;
1212 MSF_OF_FRAME(msf
.end_m
, final_frame
);
1214 return CDROM_GetStatusCode(ioctl(fd
, CDIOCPLAYMSF
, &msf
));
1216 return STATUS_SUCCESS
;
1218 return STATUS_NOT_SUPPORTED
;
1222 /******************************************************************
1227 static NTSTATUS
CDROM_PauseAudio(int fd
)
1230 return CDROM_GetStatusCode(ioctl(fd
, CDROMPAUSE
));
1231 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1232 return CDROM_GetStatusCode(ioctl(fd
, CDIOCPAUSE
, NULL
));
1234 return STATUS_NOT_SUPPORTED
;
1238 /******************************************************************
1243 static NTSTATUS
CDROM_ResumeAudio(int fd
)
1246 return CDROM_GetStatusCode(ioctl(fd
, CDROMRESUME
));
1247 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1248 return CDROM_GetStatusCode(ioctl(fd
, CDIOCRESUME
, NULL
));
1250 return STATUS_NOT_SUPPORTED
;
1254 /******************************************************************
1259 static NTSTATUS
CDROM_StopAudio(int fd
)
1262 return CDROM_GetStatusCode(ioctl(fd
, CDROMSTOP
));
1263 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1264 return CDROM_GetStatusCode(ioctl(fd
, CDIOCSTOP
, NULL
));
1266 return STATUS_NOT_SUPPORTED
;
1270 /******************************************************************
1275 static NTSTATUS
CDROM_GetVolume(int fd
, VOLUME_CONTROL
* vc
)
1278 struct cdrom_volctrl volc
;
1281 io
= ioctl(fd
, CDROMVOLREAD
, &volc
);
1284 vc
->PortVolume
[0] = volc
.channel0
;
1285 vc
->PortVolume
[1] = volc
.channel1
;
1286 vc
->PortVolume
[2] = volc
.channel2
;
1287 vc
->PortVolume
[3] = volc
.channel3
;
1289 return CDROM_GetStatusCode(io
);
1290 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1291 struct ioc_vol volc
;
1294 io
= ioctl(fd
, CDIOCGETVOL
, &volc
);
1297 vc
->PortVolume
[0] = volc
.vol
[0];
1298 vc
->PortVolume
[1] = volc
.vol
[1];
1299 vc
->PortVolume
[2] = volc
.vol
[2];
1300 vc
->PortVolume
[3] = volc
.vol
[3];
1302 return CDROM_GetStatusCode(io
);
1304 return STATUS_NOT_SUPPORTED
;
1308 /******************************************************************
1313 static NTSTATUS
CDROM_SetVolume(int fd
, const VOLUME_CONTROL
* vc
)
1316 struct cdrom_volctrl volc
;
1318 volc
.channel0
= vc
->PortVolume
[0];
1319 volc
.channel1
= vc
->PortVolume
[1];
1320 volc
.channel2
= vc
->PortVolume
[2];
1321 volc
.channel3
= vc
->PortVolume
[3];
1323 return CDROM_GetStatusCode(ioctl(fd
, CDROMVOLCTRL
, &volc
));
1324 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1325 struct ioc_vol volc
;
1327 volc
.vol
[0] = vc
->PortVolume
[0];
1328 volc
.vol
[1] = vc
->PortVolume
[1];
1329 volc
.vol
[2] = vc
->PortVolume
[2];
1330 volc
.vol
[3] = vc
->PortVolume
[3];
1332 return CDROM_GetStatusCode(ioctl(fd
, CDIOCSETVOL
, &volc
));
1334 return STATUS_NOT_SUPPORTED
;
1338 /******************************************************************
1343 static NTSTATUS
CDROM_RawRead(int fd
, const RAW_READ_INFO
* raw
, void* buffer
, DWORD len
, DWORD
* sz
)
1345 int ret
= STATUS_NOT_SUPPORTED
;
1349 TRACE("RAW_READ_INFO: DiskOffset=%li,%li SectorCount=%li TrackMode=%i\n buffer=%p len=%li sz=%p\n",
1350 raw
->DiskOffset
.u
.HighPart
, raw
->DiskOffset
.u
.LowPart
, raw
->SectorCount
, raw
->TrackMode
, buffer
, len
, sz
);
1352 switch (raw
->TrackMode
)
1354 case YellowMode2
: sectSize
= 2336; break;
1355 case XAForm2
: sectSize
= 2328; break;
1356 case CDDA
: sectSize
= 2352; break;
1357 default: return STATUS_INVALID_PARAMETER
;
1359 if (len
< raw
->SectorCount
* sectSize
) return STATUS_BUFFER_TOO_SMALL
;
1360 /* strangely enough, it seems that sector offsets are always indicated with a size of 2048,
1361 * even if a larger size if read...
1365 struct cdrom_read_audio cdra
;
1366 struct cdrom_msf
* msf
;
1368 LONGLONG t
= ((LONGLONG
)raw
->DiskOffset
.u
.HighPart
<< 32) +
1369 raw
->DiskOffset
.u
.LowPart
+ CD_MSF_OFFSET
;
1371 switch (raw
->TrackMode
)
1374 /* Linux reads only one sector at a time.
1375 * ioctl CDROMREADMODE2 takes struct cdrom_msf as an argument
1376 * on the contrary to what header comments state.
1378 for (i
= 0; i
< raw
->SectorCount
; i
++, t
+= sectSize
)
1380 msf
= (struct cdrom_msf
*)buffer
+ i
* sectSize
;
1381 msf
->cdmsf_min0
= t
/ CD_FRAMES
/ CD_SECS
;
1382 msf
->cdmsf_sec0
= t
/ CD_FRAMES
% CD_SECS
;
1383 msf
->cdmsf_frame0
= t
% CD_FRAMES
;
1384 io
= ioctl(fd
, CDROMREADMODE2
, msf
);
1388 return CDROM_GetStatusCode(io
);
1393 FIXME("XAForm2: NIY\n");
1396 /* FIXME: the output doesn't seem 100% correct... in fact output is shifted
1397 * between by NT2K box and this... should check on the same drive...
1398 * otherwise, I fear a 2352/2368 mismatch somewhere in one of the drivers
1400 * Anyway, that's not critical at all. We're talking of 16/32 bytes, we're
1401 * talking of 0.2 ms of sound
1403 /* 2048 = 2 ** 11 */
1404 if (raw
->DiskOffset
.u
.HighPart
& ~2047) FIXME("Unsupported value\n");
1405 cdra
.addr
.lba
= ((raw
->DiskOffset
.u
.LowPart
>> 11) |
1406 (raw
->DiskOffset
.u
.HighPart
<< (32 - 11))) - 1;
1407 FIXME("reading at %u\n", cdra
.addr
.lba
);
1408 cdra
.addr_format
= CDROM_LBA
;
1409 cdra
.nframes
= raw
->SectorCount
;
1411 io
= ioctl(fd
, CDROMREADAUDIO
, &cdra
);
1414 FIXME("NIY: %d\n", raw
->TrackMode
);
1420 switch (raw
->TrackMode
)
1423 FIXME("YellowMode2: NIY\n");
1426 FIXME("XAForm2: NIY\n");
1429 FIXME("CDDA: NIY\n");
1435 *sz
= sectSize
* raw
->SectorCount
;
1436 ret
= CDROM_GetStatusCode(io
);
1440 /******************************************************************
1441 * CDROM_ScsiPassThroughDirect
1442 * Implements IOCTL_SCSI_PASS_THROUGH_DIRECT
1445 static NTSTATUS
CDROM_ScsiPassThroughDirect(int fd
, PSCSI_PASS_THROUGH_DIRECT pPacket
)
1447 int ret
= STATUS_NOT_SUPPORTED
;
1448 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1451 #elif defined HAVE_SCSIREQ_T_CMD
1456 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH_DIRECT
))
1457 return STATUS_BUFFER_TOO_SMALL
;
1459 if (pPacket
->CdbLength
> 16)
1460 return STATUS_INVALID_PARAMETER
;
1463 if (pPacket
->SenseInfoLength
> SENSEBUFLEN
)
1464 return STATUS_INVALID_PARAMETER
;
1465 #elif defined HAVE_REQUEST_SENSE
1466 if (pPacket
->SenseInfoLength
> sizeof(struct request_sense
))
1467 return STATUS_INVALID_PARAMETER
;
1470 if (pPacket
->DataTransferLength
> 0 && !pPacket
->DataBuffer
)
1471 return STATUS_INVALID_PARAMETER
;
1473 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1474 RtlZeroMemory(&cmd
, sizeof(cmd
));
1476 cmd
.interface_id
= 'S';
1477 cmd
.cmd_len
= pPacket
->CdbLength
;
1478 cmd
.mx_sb_len
= pPacket
->SenseInfoLength
;
1479 cmd
.dxfer_len
= pPacket
->DataTransferLength
;
1480 cmd
.dxferp
= pPacket
->DataBuffer
;
1481 cmd
.cmdp
= pPacket
->Cdb
;
1482 cmd
.sbp
= (unsigned char*)pPacket
+ pPacket
->SenseInfoOffset
;
1483 cmd
.timeout
= pPacket
->TimeOutValue
*1000;
1485 switch (pPacket
->DataIn
)
1487 case SCSI_IOCTL_DATA_IN
:
1488 cmd
.dxfer_direction
= SG_DXFER_FROM_DEV
;
1490 case SCSI_IOCTL_DATA_OUT
:
1491 cmd
.dxfer_direction
= SG_DXFER_TO_DEV
;
1493 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1494 cmd
.dxfer_direction
= SG_DXFER_NONE
;
1497 return STATUS_INVALID_PARAMETER
;
1500 io
= ioctl(fd
, SG_IO
, &cmd
);
1502 pPacket
->ScsiStatus
= cmd
.status
;
1503 pPacket
->DataTransferLength
= cmd
.resid
;
1504 pPacket
->SenseInfoLength
= cmd
.sb_len_wr
;
1506 ret
= CDROM_GetStatusCode(io
);
1508 #elif defined HAVE_SCSIREQ_T_CMD
1510 memset(&cmd
, 0, sizeof(cmd
));
1511 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1513 cmd
.cmdlen
= pPacket
->CdbLength
;
1514 cmd
.databuf
= pPacket
->DataBuffer
;
1515 cmd
.datalen
= pPacket
->DataTransferLength
;
1516 cmd
.senselen
= pPacket
->SenseInfoLength
;
1517 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1519 switch (pPacket
->DataIn
)
1521 case SCSI_IOCTL_DATA_OUT
:
1522 cmd
.flags
|= SCCMD_WRITE
;
1524 case SCSI_IOCTL_DATA_IN
:
1525 cmd
.flags
|= SCCMD_READ
;
1527 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1531 return STATUS_INVALID_PARAMETER
;
1534 io
= ioctl(fd
, SCIOCCOMMAND
, &cmd
);
1538 case SCCMD_OK
: break;
1539 case SCCMD_TIMEOUT
: return STATUS_TIMEOUT
;
1541 case SCCMD_BUSY
: return STATUS_DEVICE_BUSY
;
1543 case SCCMD_SENSE
: break;
1544 case SCCMD_UNKNOWN
: return STATUS_UNSUCCESSFUL
;
1548 if (pPacket
->SenseInfoLength
!= 0)
1550 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1551 cmd
.sense
, pPacket
->SenseInfoLength
);
1554 pPacket
->ScsiStatus
= cmd
.status
;
1556 ret
= CDROM_GetStatusCode(io
);
1561 /******************************************************************
1562 * CDROM_ScsiPassThrough
1563 * Implements IOCTL_SCSI_PASS_THROUGH
1566 static NTSTATUS
CDROM_ScsiPassThrough(int fd
, PSCSI_PASS_THROUGH pPacket
)
1568 int ret
= STATUS_NOT_SUPPORTED
;
1569 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1572 #elif defined HAVE_SCSIREQ_T_CMD
1577 if (pPacket
->Length
< sizeof(SCSI_PASS_THROUGH
))
1578 return STATUS_BUFFER_TOO_SMALL
;
1580 if (pPacket
->CdbLength
> 16)
1581 return STATUS_INVALID_PARAMETER
;
1584 if (pPacket
->SenseInfoLength
> SENSEBUFLEN
)
1585 return STATUS_INVALID_PARAMETER
;
1586 #elif defined HAVE_REQUEST_SENSE
1587 if (pPacket
->SenseInfoLength
> sizeof(struct request_sense
))
1588 return STATUS_INVALID_PARAMETER
;
1591 if (pPacket
->DataTransferLength
> 0 && pPacket
->DataBufferOffset
< sizeof(SCSI_PASS_THROUGH
))
1592 return STATUS_INVALID_PARAMETER
;
1594 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1595 RtlZeroMemory(&cmd
, sizeof(cmd
));
1597 cmd
.interface_id
= 'S';
1598 cmd
.dxfer_len
= pPacket
->DataTransferLength
;
1599 cmd
.dxferp
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1600 cmd
.cmd_len
= pPacket
->CdbLength
;
1601 cmd
.cmdp
= pPacket
->Cdb
;
1602 cmd
.mx_sb_len
= pPacket
->SenseInfoLength
;
1603 cmd
.timeout
= pPacket
->TimeOutValue
*1000;
1605 if(cmd
.mx_sb_len
> 0)
1606 cmd
.sbp
= (unsigned char*)pPacket
+ pPacket
->SenseInfoOffset
;
1608 switch (pPacket
->DataIn
)
1610 case SCSI_IOCTL_DATA_IN
:
1611 cmd
.dxfer_direction
= SG_DXFER_FROM_DEV
;
1613 case SCSI_IOCTL_DATA_OUT
:
1614 cmd
.dxfer_direction
= SG_DXFER_TO_DEV
;
1616 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1617 cmd
.dxfer_direction
= SG_DXFER_NONE
;
1620 return STATUS_INVALID_PARAMETER
;
1623 io
= ioctl(fd
, SG_IO
, &cmd
);
1625 pPacket
->ScsiStatus
= cmd
.status
;
1626 pPacket
->DataTransferLength
= cmd
.resid
;
1627 pPacket
->SenseInfoLength
= cmd
.sb_len_wr
;
1629 ret
= CDROM_GetStatusCode(io
);
1631 #elif defined HAVE_SCSIREQ_T_CMD
1633 memset(&cmd
, 0, sizeof(cmd
));
1634 memcpy(&(cmd
.cmd
), &(pPacket
->Cdb
), pPacket
->CdbLength
);
1636 if ( pPacket
->DataBufferOffset
> 0x1000 )
1638 cmd
.databuf
= (void*)pPacket
->DataBufferOffset
;
1642 cmd
.databuf
= (char*)pPacket
+ pPacket
->DataBufferOffset
;
1645 cmd
.cmdlen
= pPacket
->CdbLength
;
1646 cmd
.datalen
= pPacket
->DataTransferLength
;
1647 cmd
.senselen
= pPacket
->SenseInfoLength
;
1648 cmd
.timeout
= pPacket
->TimeOutValue
*1000; /* in milliseconds */
1650 switch (pPacket
->DataIn
)
1652 case SCSI_IOCTL_DATA_OUT
:
1653 cmd
.flags
|= SCCMD_WRITE
;
1655 case SCSI_IOCTL_DATA_IN
:
1656 cmd
.flags
|= SCCMD_READ
;
1658 case SCSI_IOCTL_DATA_UNSPECIFIED
:
1662 return STATUS_INVALID_PARAMETER
;
1665 io
= ioctl(fd
, SCIOCCOMMAND
, &cmd
);
1669 case SCCMD_OK
: break;
1670 case SCCMD_TIMEOUT
: return STATUS_TIMEOUT
;
1672 case SCCMD_BUSY
: return STATUS_DEVICE_BUSY
;
1674 case SCCMD_SENSE
: break;
1675 case SCCMD_UNKNOWN
: return STATUS_UNSUCCESSFUL
;
1679 if (pPacket
->SenseInfoLength
!= 0)
1681 memcpy((char*)pPacket
+ pPacket
->SenseInfoOffset
,
1682 cmd
.sense
, pPacket
->SenseInfoLength
);
1685 pPacket
->ScsiStatus
= cmd
.status
;
1687 ret
= CDROM_GetStatusCode(io
);
1692 /******************************************************************
1697 static NTSTATUS
CDROM_ScsiGetCaps(PIO_SCSI_CAPABILITIES caps
)
1699 NTSTATUS ret
= STATUS_NOT_IMPLEMENTED
;
1701 caps
->Length
= sizeof(*caps
);
1702 #ifdef SG_SCATTER_SZ
1703 caps
->MaximumTransferLength
= SG_SCATTER_SZ
; /* FIXME */
1704 caps
->MaximumPhysicalPages
= SG_SCATTER_SZ
/ getpagesize();
1705 caps
->SupportedAsynchronousEvents
= TRUE
;
1706 caps
->AlignmentMask
= getpagesize();
1707 caps
->TaggedQueuing
= FALSE
; /* we could check that it works and answer TRUE */
1708 caps
->AdapterScansDown
= FALSE
; /* FIXME ? */
1709 caps
->AdapterUsesPio
= FALSE
; /* FIXME ? */
1710 ret
= STATUS_SUCCESS
;
1712 FIXME("Unimplemented\n");
1717 /******************************************************************
1720 * implements IOCTL_SCSI_GET_ADDRESS
1722 static NTSTATUS
CDROM_GetAddress(int fd
, SCSI_ADDRESS
* address
)
1724 UCHAR portnum
, busid
, targetid
, lun
;
1726 address
->Length
= sizeof(SCSI_ADDRESS
);
1727 if ( ! CDROM_GetInterfaceInfo(fd
, &portnum
, &busid
, &targetid
, &lun
))
1728 return STATUS_NOT_SUPPORTED
;
1730 address
->PortNumber
= portnum
; /* primary=0 secondary=1 for ide */
1731 address
->PathId
= busid
; /* always 0 for ide */
1732 address
->TargetId
= targetid
; /* master=0 slave=1 for ide */
1734 return STATUS_SUCCESS
;
1737 /******************************************************************
1742 static NTSTATUS
DVD_StartSession(int fd
, PDVD_SESSION_ID sid_in
, PDVD_SESSION_ID sid_out
)
1745 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1746 dvd_authinfo auth_info
;
1748 memset( &auth_info
, 0, sizeof( auth_info
) );
1749 auth_info
.type
= DVD_LU_SEND_AGID
;
1750 if (sid_in
) auth_info
.lsa
.agid
= *(int*)sid_in
; /* ?*/
1752 TRACE("fd 0x%08x\n",fd
);
1753 ret
=CDROM_GetStatusCode(ioctl(fd
, DVD_AUTH
, &auth_info
));
1754 *sid_out
= auth_info
.lsa
.agid
;
1756 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1757 return STATUS_NOT_SUPPORTED
;
1759 return STATUS_NOT_SUPPORTED
;
1763 /******************************************************************
1768 static NTSTATUS
DVD_EndSession(int fd
, PDVD_SESSION_ID sid
)
1771 dvd_authinfo auth_info
;
1773 memset( &auth_info
, 0, sizeof( auth_info
) );
1774 auth_info
.type
= DVD_INVALIDATE_AGID
;
1775 auth_info
.lsa
.agid
= *(int*)sid
;
1778 return CDROM_GetStatusCode(ioctl(fd
, DVD_AUTH
, &auth_info
));
1779 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1780 return STATUS_NOT_SUPPORTED
;
1782 return STATUS_NOT_SUPPORTED
;
1786 /******************************************************************
1791 static NTSTATUS
DVD_SendKey(int fd
, PDVD_COPY_PROTECT_KEY key
)
1794 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1795 dvd_authinfo auth_info
;
1797 memset( &auth_info
, 0, sizeof( auth_info
) );
1798 switch (key
->KeyType
)
1800 case DvdChallengeKey
:
1801 auth_info
.type
= DVD_HOST_SEND_CHALLENGE
;
1802 auth_info
.hsc
.agid
= (int)key
->SessionId
;
1803 TRACE("DvdChallengeKey ioc 0x%x\n", DVD_AUTH
);
1804 memcpy( auth_info
.hsc
.chal
, key
->KeyData
, DVD_CHALLENGE_SIZE
);
1805 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1808 auth_info
.type
= DVD_HOST_SEND_KEY2
;
1809 auth_info
.hsk
.agid
= (int)key
->SessionId
;
1811 memcpy( auth_info
.hsk
.key
, key
->KeyData
, DVD_KEY_SIZE
);
1813 TRACE("DvdBusKey2\n");
1814 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1818 FIXME("Unknown Keytype 0x%x\n",key
->KeyType
);
1822 FIXME("unsupported on this platform\n");
1823 return STATUS_NOT_SUPPORTED
;
1827 /******************************************************************
1832 static NTSTATUS
DVD_ReadKey(int fd
, PDVD_COPY_PROTECT_KEY key
)
1835 NTSTATUS ret
= STATUS_NOT_SUPPORTED
;
1837 dvd_authinfo auth_info
;
1839 memset( &dvd
, 0, sizeof( dvd_struct
) );
1840 memset( &auth_info
, 0, sizeof( auth_info
) );
1841 switch (key
->KeyType
)
1845 dvd
.type
= DVD_STRUCT_DISCKEY
;
1846 dvd
.disckey
.agid
= (int)key
->SessionId
;
1847 memset( dvd
.disckey
.value
, 0, DVD_DISCKEY_SIZE
);
1849 TRACE("DvdDiskKey\n");
1850 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_READ_STRUCT
, &dvd
));
1851 if (ret
== STATUS_SUCCESS
)
1852 memcpy(key
->KeyData
,dvd
.disckey
.value
,DVD_DISCKEY_SIZE
);
1855 auth_info
.type
= DVD_LU_SEND_TITLE_KEY
;
1856 auth_info
.lstk
.agid
= (int)key
->SessionId
;
1857 auth_info
.lstk
.lba
= (int)(key
->Parameters
.TitleOffset
.QuadPart
>>11);
1858 TRACE("DvdTitleKey session %d Quadpart 0x%08lx offset 0x%08x\n",
1859 (int)key
->SessionId
, (long)key
->Parameters
.TitleOffset
.QuadPart
,
1860 auth_info
.lstk
.lba
);
1861 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1862 if (ret
== STATUS_SUCCESS
)
1863 memcpy(key
->KeyData
, auth_info
.lstk
.title_key
, DVD_KEY_SIZE
);
1865 case DvdChallengeKey
:
1867 auth_info
.type
= DVD_LU_SEND_CHALLENGE
;
1868 auth_info
.lsc
.agid
= (int)key
->SessionId
;
1870 TRACE("DvdChallengeKey\n");
1871 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1872 if (ret
== STATUS_SUCCESS
)
1873 memcpy( key
->KeyData
, auth_info
.lsc
.chal
, DVD_CHALLENGE_SIZE
);
1876 auth_info
.type
= DVD_LU_SEND_ASF
;
1878 auth_info
.lsasf
.asf
=((PDVD_ASF
)key
->KeyData
)->SuccessFlag
;
1879 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1880 ((PDVD_ASF
)key
->KeyData
)->SuccessFlag
= auth_info
.lsasf
.asf
;
1883 auth_info
.type
= DVD_LU_SEND_KEY1
;
1884 auth_info
.lsk
.agid
= (int)key
->SessionId
;
1886 TRACE("DvdBusKey1\n");
1887 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1889 if (ret
== STATUS_SUCCESS
)
1890 memcpy( key
->KeyData
, auth_info
.lsk
.key
, DVD_KEY_SIZE
);
1893 auth_info
.type
= DVD_LU_SEND_RPC_STATE
;
1895 TRACE("DvdGetRpcKey\n");
1896 ret
= CDROM_GetStatusCode(ioctl( fd
, DVD_AUTH
, &auth_info
));
1898 if (ret
== STATUS_SUCCESS
)
1900 ((PDVD_RPC_KEY
)key
->KeyData
)->TypeCode
= auth_info
.lrpcs
.type
;
1901 ((PDVD_RPC_KEY
)key
->KeyData
)->RegionMask
= auth_info
.lrpcs
.region_mask
;
1902 ((PDVD_RPC_KEY
)key
->KeyData
)->RpcScheme
= auth_info
.lrpcs
.rpc_scheme
;
1906 FIXME("Unknown keytype 0x%x\n",key
->KeyType
);
1909 #elif defined(__FreeBSD__) || defined(__NetBSD__)
1911 return STATUS_NOT_SUPPORTED
;
1914 return STATUS_NOT_SUPPORTED
;
1916 TRACE("not reached\n");
1919 /******************************************************************
1924 static NTSTATUS
DVD_GetRegion(int dev
, PDVD_REGION region
)
1927 return STATUS_SUCCESS
;
1931 /******************************************************************
1936 static NTSTATUS
DVD_ReadStructure(int dev
, PDVD_READ_STRUCTURE structure
, PDVD_LAYER_DESCRIPTOR layer
)
1939 return STATUS_SUCCESS
;
1943 /******************************************************************
1945 * Implements the IOCTL_GET_INQUIRY_DATA ioctl.
1946 * Returns Inquiry data for all devices on the specified scsi bus
1947 * Returns STATUS_BUFFER_TOO_SMALL if the output buffer is too small,
1948 * STATUS_INVALID_DEVICE_REQUEST if the given handle isn't to a SCSI device,
1949 * or STATUS_NOT_SUPPORTED if the OS driver is too old
1951 static NTSTATUS
GetInquiryData(int fd
, PSCSI_ADAPTER_BUS_INFO BufferOut
, DWORD OutBufferSize
)
1953 #ifdef HAVE_SG_IO_HDR_T_INTERFACE_ID
1954 PSCSI_INQUIRY_DATA pInquiryData
= NULL
;
1955 UCHAR sense_buffer
[32];
1958 UCHAR inquiry
[INQ_CMD_LEN
] = {INQUIRY
, 0, 0, 0, INQ_REPLY_LEN
, 0};
1960 /* Check we have a SCSI device and a supported driver */
1961 if(ioctl(fd
, SG_GET_VERSION_NUM
, &version
) != 0)
1963 WARN("IOCTL_SCSI_GET_INQUIRY_DATA sg driver is not loaded\n");
1964 return STATUS_INVALID_DEVICE_REQUEST
;
1966 if(version
< 30000 )
1967 return STATUS_NOT_SUPPORTED
;
1969 /* FIXME: Enumerate devices on the bus */
1970 BufferOut
->NumberOfBuses
= 1;
1971 BufferOut
->BusData
[0].NumberOfLogicalUnits
= 1;
1972 BufferOut
->BusData
[0].InquiryDataOffset
= sizeof(SCSI_ADAPTER_BUS_INFO
);
1974 pInquiryData
= (PSCSI_INQUIRY_DATA
)(BufferOut
+ 1);
1976 RtlZeroMemory(&iocmd
, sizeof(iocmd
));
1977 iocmd
.interface_id
= 'S';
1978 iocmd
.cmd_len
= sizeof(inquiry
);
1979 iocmd
.mx_sb_len
= sizeof(sense_buffer
);
1980 iocmd
.dxfer_direction
= SG_DXFER_FROM_DEV
;
1981 iocmd
.dxfer_len
= INQ_REPLY_LEN
;
1982 iocmd
.dxferp
= pInquiryData
->InquiryData
;
1983 iocmd
.cmdp
= inquiry
;
1984 iocmd
.sbp
= sense_buffer
;
1985 iocmd
.timeout
= 1000;
1987 iochk
= ioctl(fd
, SG_IO
, &iocmd
);
1989 WARN("ioctl SG_IO returned %d, error (%s)\n", iochk
, strerror(errno
));
1991 CDROM_GetInterfaceInfo(fd
, &BufferOut
->BusData
[0].InitiatorBusId
, &pInquiryData
->PathId
, &pInquiryData
->TargetId
, &pInquiryData
->Lun
);
1992 pInquiryData
->DeviceClaimed
= TRUE
;
1993 pInquiryData
->InquiryDataLength
= INQ_REPLY_LEN
;
1994 pInquiryData
->NextInquiryDataOffset
= 0;
1995 return STATUS_SUCCESS
;
1997 FIXME("not implemented for nonlinux\n");
1998 return STATUS_NOT_SUPPORTED
;
2002 /******************************************************************
2003 * CDROM_DeviceIoControl
2007 NTSTATUS
CDROM_DeviceIoControl(HANDLE hDevice
,
2008 HANDLE hEvent
, PIO_APC_ROUTINE UserApcRoutine
,
2009 PVOID UserApcContext
,
2010 PIO_STATUS_BLOCK piosb
,
2011 ULONG dwIoControlCode
,
2012 LPVOID lpInBuffer
, DWORD nInBufferSize
,
2013 LPVOID lpOutBuffer
, DWORD nOutBufferSize
)
2016 NTSTATUS status
= STATUS_SUCCESS
;
2019 TRACE("%p %s %p %ld %p %ld %p\n",
2020 hDevice
, iocodex(dwIoControlCode
), lpInBuffer
, nInBufferSize
,
2021 lpOutBuffer
, nOutBufferSize
, piosb
);
2023 piosb
->Information
= 0;
2025 if ((status
= wine_server_handle_to_fd( hDevice
, 0, &fd
, NULL
))) goto error
;
2026 if ((status
= CDROM_Open(fd
, &dev
)))
2028 wine_server_release_fd( hDevice
, fd
);
2032 switch (dwIoControlCode
)
2034 case IOCTL_STORAGE_CHECK_VERIFY
:
2035 case IOCTL_CDROM_CHECK_VERIFY
:
2036 case IOCTL_DISK_CHECK_VERIFY
:
2038 CDROM_ClearCacheEntry(dev
);
2039 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2040 status
= STATUS_INVALID_PARAMETER
;
2041 else status
= CDROM_Verify(dev
, fd
);
2044 /* EPP case IOCTL_STORAGE_CHECK_VERIFY2: */
2046 /* EPP case IOCTL_STORAGE_FIND_NEW_DEVICES: */
2047 /* EPP case IOCTL_CDROM_FIND_NEW_DEVICES: */
2049 case IOCTL_STORAGE_LOAD_MEDIA
:
2050 case IOCTL_CDROM_LOAD_MEDIA
:
2052 CDROM_ClearCacheEntry(dev
);
2053 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2054 status
= STATUS_INVALID_PARAMETER
;
2055 else status
= CDROM_SetTray(fd
, FALSE
);
2057 case IOCTL_STORAGE_EJECT_MEDIA
:
2059 CDROM_ClearCacheEntry(dev
);
2060 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2061 status
= STATUS_INVALID_PARAMETER
;
2062 else status
= CDROM_SetTray(fd
, TRUE
);
2065 case IOCTL_CDROM_MEDIA_REMOVAL
:
2066 case IOCTL_DISK_MEDIA_REMOVAL
:
2067 case IOCTL_STORAGE_MEDIA_REMOVAL
:
2068 case IOCTL_STORAGE_EJECTION_CONTROL
:
2069 /* FIXME the last ioctl:s is not the same as the two others...
2070 * lockcount/owner should be handled */
2072 CDROM_ClearCacheEntry(dev
);
2073 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2074 else if (nInBufferSize
< sizeof(PREVENT_MEDIA_REMOVAL
)) status
= STATUS_BUFFER_TOO_SMALL
;
2075 else status
= CDROM_ControlEjection(fd
, (const PREVENT_MEDIA_REMOVAL
*)lpInBuffer
);
2078 /* EPP case IOCTL_STORAGE_GET_MEDIA_TYPES: */
2080 case IOCTL_STORAGE_GET_DEVICE_NUMBER
:
2081 sz
= sizeof(STORAGE_DEVICE_NUMBER
);
2082 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2083 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2084 else status
= CDROM_GetDeviceNumber(dev
, (STORAGE_DEVICE_NUMBER
*)lpOutBuffer
);
2087 case IOCTL_STORAGE_RESET_DEVICE
:
2089 CDROM_ClearCacheEntry(dev
);
2090 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2091 status
= STATUS_INVALID_PARAMETER
;
2092 else status
= CDROM_ResetAudio(fd
);
2095 case IOCTL_CDROM_GET_CONTROL
:
2096 sz
= sizeof(CDROM_AUDIO_CONTROL
);
2097 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2098 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2099 else status
= CDROM_GetControl(dev
, (CDROM_AUDIO_CONTROL
*)lpOutBuffer
);
2102 case IOCTL_CDROM_GET_DRIVE_GEOMETRY
:
2103 sz
= sizeof(DISK_GEOMETRY
);
2104 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2105 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2106 else status
= CDROM_GetDriveGeometry(dev
, fd
, (DISK_GEOMETRY
*)lpOutBuffer
);
2109 case IOCTL_CDROM_DISK_TYPE
:
2110 sz
= sizeof(CDROM_DISK_DATA
);
2111 /* CDROM_ClearCacheEntry(dev); */
2112 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2113 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2114 else status
= CDROM_GetDiskData(dev
, fd
, (CDROM_DISK_DATA
*)lpOutBuffer
);
2117 /* EPP case IOCTL_CDROM_GET_LAST_SESSION: */
2119 case IOCTL_CDROM_READ_Q_CHANNEL
:
2120 sz
= sizeof(SUB_Q_CHANNEL_DATA
);
2121 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(CDROM_SUB_Q_DATA_FORMAT
))
2122 status
= STATUS_INVALID_PARAMETER
;
2123 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2124 else status
= CDROM_ReadQChannel(dev
, fd
, (const CDROM_SUB_Q_DATA_FORMAT
*)lpInBuffer
,
2125 (SUB_Q_CHANNEL_DATA
*)lpOutBuffer
);
2128 case IOCTL_CDROM_READ_TOC
:
2129 sz
= sizeof(CDROM_TOC
);
2130 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2131 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2132 else status
= CDROM_ReadTOC(dev
, fd
, (CDROM_TOC
*)lpOutBuffer
);
2135 /* EPP case IOCTL_CDROM_READ_TOC_EX: */
2137 case IOCTL_CDROM_PAUSE_AUDIO
:
2139 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2140 status
= STATUS_INVALID_PARAMETER
;
2141 else status
= CDROM_PauseAudio(fd
);
2143 case IOCTL_CDROM_PLAY_AUDIO_MSF
:
2145 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2146 else if (nInBufferSize
< sizeof(CDROM_PLAY_AUDIO_MSF
)) status
= STATUS_BUFFER_TOO_SMALL
;
2147 else status
= CDROM_PlayAudioMSF(fd
, (const CDROM_PLAY_AUDIO_MSF
*)lpInBuffer
);
2149 case IOCTL_CDROM_RESUME_AUDIO
:
2151 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2152 status
= STATUS_INVALID_PARAMETER
;
2153 else status
= CDROM_ResumeAudio(fd
);
2155 case IOCTL_CDROM_SEEK_AUDIO_MSF
:
2157 if (lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2158 else if (nInBufferSize
< sizeof(CDROM_SEEK_AUDIO_MSF
)) status
= STATUS_BUFFER_TOO_SMALL
;
2159 else status
= CDROM_SeekAudioMSF(dev
, fd
, (const CDROM_SEEK_AUDIO_MSF
*)lpInBuffer
);
2161 case IOCTL_CDROM_STOP_AUDIO
:
2163 CDROM_ClearCacheEntry(dev
); /* Maybe intention is to change media */
2164 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0 || lpOutBuffer
!= NULL
|| nOutBufferSize
!= 0)
2165 status
= STATUS_INVALID_PARAMETER
;
2166 else status
= CDROM_StopAudio(fd
);
2168 case IOCTL_CDROM_GET_VOLUME
:
2169 sz
= sizeof(VOLUME_CONTROL
);
2170 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2171 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2172 else status
= CDROM_GetVolume(fd
, (VOLUME_CONTROL
*)lpOutBuffer
);
2174 case IOCTL_CDROM_SET_VOLUME
:
2176 CDROM_ClearCacheEntry(dev
);
2177 if (lpInBuffer
== NULL
|| nInBufferSize
< sizeof(VOLUME_CONTROL
) || lpOutBuffer
!= NULL
)
2178 status
= STATUS_INVALID_PARAMETER
;
2179 else status
= CDROM_SetVolume(fd
, (const VOLUME_CONTROL
*)lpInBuffer
);
2181 case IOCTL_CDROM_RAW_READ
:
2183 if (nInBufferSize
< sizeof(RAW_READ_INFO
)) status
= STATUS_INVALID_PARAMETER
;
2184 else if (lpOutBuffer
== NULL
) status
= STATUS_BUFFER_TOO_SMALL
;
2185 else status
= CDROM_RawRead(fd
, (const RAW_READ_INFO
*)lpInBuffer
,
2186 lpOutBuffer
, nOutBufferSize
, &sz
);
2188 case IOCTL_SCSI_GET_ADDRESS
:
2189 sz
= sizeof(SCSI_ADDRESS
);
2190 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2191 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2192 else status
= CDROM_GetAddress(fd
, (SCSI_ADDRESS
*)lpOutBuffer
);
2194 case IOCTL_SCSI_PASS_THROUGH_DIRECT
:
2195 sz
= sizeof(SCSI_PASS_THROUGH_DIRECT
);
2196 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2197 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH_DIRECT
)) status
= STATUS_BUFFER_TOO_SMALL
;
2198 else status
= CDROM_ScsiPassThroughDirect(fd
, (PSCSI_PASS_THROUGH_DIRECT
)lpOutBuffer
);
2200 case IOCTL_SCSI_PASS_THROUGH
:
2201 sz
= sizeof(SCSI_PASS_THROUGH
);
2202 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2203 else if (nOutBufferSize
< sizeof(SCSI_PASS_THROUGH
)) status
= STATUS_BUFFER_TOO_SMALL
;
2204 else status
= CDROM_ScsiPassThrough(fd
, (PSCSI_PASS_THROUGH
)lpOutBuffer
);
2206 case IOCTL_SCSI_GET_CAPABILITIES
:
2207 sz
= sizeof(IO_SCSI_CAPABILITIES
);
2208 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2209 else if (nOutBufferSize
< sizeof(IO_SCSI_CAPABILITIES
)) status
= STATUS_BUFFER_TOO_SMALL
;
2210 else status
= CDROM_ScsiGetCaps((PIO_SCSI_CAPABILITIES
)lpOutBuffer
);
2212 case IOCTL_DVD_START_SESSION
:
2213 sz
= sizeof(DVD_SESSION_ID
);
2214 if (lpOutBuffer
== NULL
) status
= STATUS_INVALID_PARAMETER
;
2215 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2218 TRACE("before in 0x%08lx out 0x%08lx\n",(lpInBuffer
)?*(PDVD_SESSION_ID
)lpInBuffer
:0,
2219 *(PDVD_SESSION_ID
)lpOutBuffer
);
2220 status
= DVD_StartSession(fd
, (PDVD_SESSION_ID
)lpInBuffer
, (PDVD_SESSION_ID
)lpOutBuffer
);
2221 TRACE("before in 0x%08lx out 0x%08lx\n",(lpInBuffer
)?*(PDVD_SESSION_ID
)lpInBuffer
:0,
2222 *(PDVD_SESSION_ID
)lpOutBuffer
);
2225 case IOCTL_DVD_END_SESSION
:
2226 sz
= sizeof(DVD_SESSION_ID
);
2227 if ((lpInBuffer
== NULL
) || (nInBufferSize
< sz
))status
= STATUS_INVALID_PARAMETER
;
2228 else status
= DVD_EndSession(fd
, (PDVD_SESSION_ID
)lpInBuffer
);
2230 case IOCTL_DVD_SEND_KEY
:
2233 (((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
!= nInBufferSize
))
2234 status
= STATUS_INVALID_PARAMETER
;
2237 TRACE("doing DVD_SendKey\n");
2238 status
= DVD_SendKey(fd
, (PDVD_COPY_PROTECT_KEY
)lpInBuffer
);
2241 case IOCTL_DVD_READ_KEY
:
2243 (((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
!= nInBufferSize
))
2244 status
= STATUS_INVALID_PARAMETER
;
2245 else if (lpInBuffer
!=lpOutBuffer
) status
= STATUS_BUFFER_TOO_SMALL
;
2248 TRACE("doing DVD_READ_KEY\n");
2249 sz
= ((PDVD_COPY_PROTECT_KEY
)lpInBuffer
)->KeyLength
;
2250 status
= DVD_ReadKey(fd
, (PDVD_COPY_PROTECT_KEY
)lpInBuffer
);
2253 case IOCTL_DVD_GET_REGION
:
2254 sz
= sizeof(DVD_REGION
);
2255 if (lpInBuffer
!= NULL
|| nInBufferSize
!= 0) status
= STATUS_INVALID_PARAMETER
;
2256 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2257 TRACE("doing DVD_Get_REGION\n");
2258 status
= DVD_GetRegion(fd
, (PDVD_REGION
)lpOutBuffer
);
2260 case IOCTL_DVD_READ_STRUCTURE
:
2261 sz
= sizeof(DVD_LAYER_DESCRIPTOR
);
2262 if (lpInBuffer
== NULL
|| nInBufferSize
!= sizeof(DVD_READ_STRUCTURE
)) status
= STATUS_INVALID_PARAMETER
;
2263 else if (nOutBufferSize
< sz
) status
= STATUS_BUFFER_TOO_SMALL
;
2264 TRACE("doing DVD_READ_STRUCTURE\n");
2265 status
= DVD_ReadStructure(fd
, (PDVD_READ_STRUCTURE
)lpInBuffer
, (PDVD_LAYER_DESCRIPTOR
)lpOutBuffer
);
2268 case IOCTL_SCSI_GET_INQUIRY_DATA
:
2270 status
= GetInquiryData(fd
, (PSCSI_ADAPTER_BUS_INFO
)lpOutBuffer
, nOutBufferSize
);
2274 FIXME("Unsupported IOCTL %lx (type=%lx access=%lx func=%lx meth=%lx)\n",
2275 dwIoControlCode
, dwIoControlCode
>> 16, (dwIoControlCode
>> 14) & 3,
2276 (dwIoControlCode
>> 2) & 0xFFF, dwIoControlCode
& 3);
2278 status
= STATUS_INVALID_PARAMETER
;
2281 wine_server_release_fd( hDevice
, fd
);
2283 piosb
->u
.Status
= status
;
2284 piosb
->Information
= sz
;
2285 if (hEvent
) NtSetEvent(hEvent
, NULL
);