These are working pretty good for me. Hope they are fine now.
W.
Eric Pouech wrote:
the code in cdrom.diff is still wrong. you cannot use the dev variable
in most of the inner functions as an index in the cdrom_cache array.
the index you need is in fact the low word of client-id in
CDROM_DeviceIoControl
I'd suggest that you change CDROM_Open to return a pointer to the
relevant cdrom_cache structure instead of dev
mcicda.diff looks better now
A+
Index: wine/dlls/ntdll/cdrom.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/cdrom.c,v
retrieving revision 1.24
diff -u -p -r1.24 cdrom.c
--- wine/dlls/ntdll/cdrom.c 23 Jan 2003 21:32:36 -0000 1.24
+++ wine/dlls/ntdll/cdrom.c 18 Feb 2003 05:01:35 -0000
@@ -72,8 +72,57 @@
#include "file.h"
#include "wine/debug.h"
+
+static struct iocodexs
+{
+ DWORD code;
+ char *codex;
+} iocodextable[] = {
+{IOCTL_CDROM_UNLOAD_DRIVER, "IOCTL_CDROM_UNLOAD_DRIVER"},
+{IOCTL_CDROM_READ_TOC, "IOCTL_CDROM_READ_TOC"},
+{IOCTL_CDROM_GET_CONTROL, "IOCTL_CDROM_GET_CONTROL"},
+{IOCTL_CDROM_PLAY_AUDIO_MSF, "IOCTL_CDROM_PLAY_AUDIO_MSF"},
+{IOCTL_CDROM_SEEK_AUDIO_MSF, "IOCTL_CDROM_SEEK_AUDIO_MSF"},
+{IOCTL_CDROM_STOP_AUDIO, "IOCTL_CDROM_STOP_AUDIO"},
+{IOCTL_CDROM_PAUSE_AUDIO, "IOCTL_CDROM_PAUSE_AUDIO"},
+{IOCTL_CDROM_RESUME_AUDIO, "IOCTL_CDROM_RESUME_AUDIO"},
+{IOCTL_CDROM_GET_VOLUME, "IOCTL_CDROM_GET_VOLUME"},
+{IOCTL_CDROM_SET_VOLUME, "IOCTL_CDROM_SET_VOLUME"},
+{IOCTL_CDROM_READ_Q_CHANNEL, "IOCTL_CDROM_READ_Q_CHANNEL"},
+{IOCTL_CDROM_GET_LAST_SESSION, "IOCTL_CDROM_GET_LAST_SESSION"},
+{IOCTL_CDROM_RAW_READ, "IOCTL_CDROM_RAW_READ"},
+{IOCTL_CDROM_DISK_TYPE, "IOCTL_CDROM_DISK_TYPE"},
+{IOCTL_CDROM_GET_DRIVE_GEOMETRY, "IOCTL_CDROM_GET_DRIVE_GEOMETRY"},
+{IOCTL_CDROM_CHECK_VERIFY, "IOCTL_CDROM_CHECK_VERIFY"},
+{IOCTL_CDROM_MEDIA_REMOVAL, "IOCTL_CDROM_MEDIA_REMOVAL"},
+{IOCTL_CDROM_EJECT_MEDIA, "IOCTL_CDROM_EJECT_MEDIA"},
+{IOCTL_CDROM_LOAD_MEDIA, "IOCTL_CDROM_LOAD_MEDIA"},
+{IOCTL_CDROM_RESERVE, "IOCTL_CDROM_RESERVE"},
+{IOCTL_CDROM_RELEASE, "IOCTL_CDROM_RELEASE"},
+{IOCTL_CDROM_FIND_NEW_DEVICES, "IOCTL_CDROM_FIND_NEW_DEVICES"}
+};
+char *iocodex(DWORD code)
+{
+ int i;
+ static char buffer[25];
+ for(i=0; i<sizeof(iocodextable)/sizeof(struct iocodexs); i++)
+ if (code==iocodextable[i].code)
+ return iocodextable[i].codex;
+ sprintf(buffer, "IOCTL_CODE_%x", (int)code);
+ return buffer;
+}
+
WINE_DEFAULT_DEBUG_CHANNEL(cdrom);
+#define FRAME_OF_ADDR(a) (((int)(a)[1] * CD_SECS + (a)[2]) * CD_FRAMES + (a)[3])
+#define FRAME_OF_MSF(a) (((int)(a).M * CD_SECS + (a).S) * CD_FRAMES + (a).F)
+#define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
+#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;}
+
+static DWORD CDROM_ReadTOC(int, CDROM_TOC*);
+static DWORD CDROM_GetStatusCode(int);
+
+
#ifdef linux
# ifndef IDE6_MAJOR
@@ -105,13 +154,183 @@ struct linux_cdrom_generic_command
/* FIXME: this is needed because we can't open simultaneously several times /dev/cdrom
* this should be removed when a proper device interface is implemented
+ *
+ * (WS) We need this to keep track of current position and to safely
+ * detect media changes. Besides this should provide a great speed up
+ * for toc inquiries.
*/
struct cdrom_cache {
int fd;
int count;
+ char toc_good; /* if false, will reread TOC from disk */
+ CDROM_TOC toc;
+ SUB_Q_CURRENT_POSITION CurrentPosition;
};
static struct cdrom_cache cdrom_cache[26];
+/* Proposed media change function: not really needed at this time */
+/* This is a 1 or 0 type of function */
+#if 0
+static int CDROM_MediaChanged(int dev)
+{
+ int i;
+
+ struct cdrom_tochdr hdr;
+ struct cdrom_tocentry entry;
+
+ if (dev < 0 || dev >= 26)
+ return 0;
+ if ( ioctl(cdrom_cache[dev].fd, CDROMREADTOCHDR, &hdr) == -1 )
+ return 0;
+
+ if ( memcmp(&hdr, &cdrom_cache[dev].hdr, sizeof(struct cdrom_tochdr)) )
+ return 1;
+
+ for (i=hdr.cdth_trk0; i<=hdr.cdth_trk1+1; i++)
+ {
+ if (i == hdr.cdth_trk1 + 1)
+ {
+ entry.cdte_track = CDROM_LEADOUT;
+ } else {
+ entry.cdte_track = i;
+ }
+ entry.cdte_format = CDROM_MSF;
+ if ( ioctl(cdrom_cache[dev].fd, CDROMREADTOCENTRY, &entry) == -1)
+ return 0;
+ if ( memcmp(&entry, cdrom_cache[dev].entry+i-hdr.cdth_trk0,
+ sizeof(struct cdrom_tocentry)) )
+ return 1;
+ }
+ return 0;
+}
+#endif
+
+/******************************************************************
+ * CDROM_SyncCache [internal]
+ *
+ * Read the TOC in and store it in the cdrom_cache structure.
+ * Further requests for the TOC will be copied from the cache
+ * unless certain events like disk ejection is detected, in which
+ * case the cache will be cleared, causing it to be resynced.
+ *
+ */
+static int CDROM_SyncCache(int dev)
+{
+ int i, io = 0, tsz;
+#ifdef linux
+ struct cdrom_tochdr hdr;
+ struct cdrom_tocentry entry;
+#elif defined(__FreeBSD__) || defined(__NetBSD__)
+ struct ioc_toc_header hdr;
+ struct ioc_read_toc_entry entry;
+ struct cd_toc_entry toc_buffer;
+#endif
+ CDROM_TOC *toc = &cdrom_cache[dev].toc;
+ cdrom_cache[dev].toc_good = 0;
+
+#ifdef linux
+
+ io = ioctl(cdrom_cache[dev].fd, CDROMREADTOCHDR, &hdr);
+ if (io == -1)
+ {
+ WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
+ goto end;
+ }
+
+ TRACE("caching toc from=%d to=%d\n", hdr.cdth_trk0, hdr.cdth_trk1);
+
+ toc->FirstTrack = hdr.cdth_trk0;
+ toc->LastTrack = hdr.cdth_trk1;
+ tsz = sizeof(toc->FirstTrack) + sizeof(toc->LastTrack)
+ + sizeof(TRACK_DATA) * (toc->LastTrack-toc->FirstTrack+2);
+ toc->Length[0] = tsz >> 8;
+ toc->Length[1] = tsz;
+
+ TRACE("from=%d to=%d\n", toc->FirstTrack, toc->LastTrack);
+
+ for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
+ {
+ if (i == toc->LastTrack + 1)
+ entry.cdte_track = CDROM_LEADOUT;
+ else
+ entry.cdte_track = i;
+ entry.cdte_format = CDROM_MSF;
+ io = ioctl(cdrom_cache[dev].fd, CDROMREADTOCENTRY, &entry);
+ if (io == -1) {
+ WARN("error read entry (%s)\n", strerror(errno));
+ goto end;
+ }
+ toc->TrackData[i - toc->FirstTrack].Control = entry.cdte_ctrl;
+ toc->TrackData[i - toc->FirstTrack].Adr = entry.cdte_adr;
+ /* marking last track with leadout value as index */
+ toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.cdte_track;
+ toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
+ toc->TrackData[i - toc->FirstTrack].Address[1] = entry.cdte_addr.msf.minute;
+ toc->TrackData[i - toc->FirstTrack].Address[2] = entry.cdte_addr.msf.second;
+ toc->TrackData[i - toc->FirstTrack].Address[3] = entry.cdte_addr.msf.frame;
+ }
+ cdrom_cache[dev].toc_good = 1;
+ io = 0;
+#elif defined(__FreeBSD__) || defined(__NetBSD__)
+
+ io = ioctl(cdrom_cache[dev].fd, CDIOREADTOCHEADER, &hdr);
+ if (io == -1)
+ {
+ WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
+ goto end;
+ }
+ toc->FirstTrack = hdr.starting_track;
+ toc->LastTrack = hdr.ending_track;
+ tsz = sizeof(toc->FirstTrack) + sizeof(toc->LastTrack)
+ + sizeof(TRACK_DATA) * (toc->LastTrack-toc->FirstTrack+2);
+ toc->Length[0] = tsz >> 8;
+ toc->Length[1] = tsz;
+
+ TRACE("caching toc from=%d to=%d\n", hdr.cdth_trk0, hdr.cdth_trk1);
+
+ for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
+ {
+ if (i == toc->LastTrack + 1)
+ {
+#define LEADOUT 0xaa
+ entry.starting_track = LEADOUT;
+ } else {
+ entry.starting_track = i;
+ }
+ memset((char *)&toc_buffer, 0, sizeof(toc_buffer));
+ entry.address_format = CD_MSF_FORMAT;
+ entry.data_len = sizeof(toc_buffer);
+ entry.data = &toc_buffer;
+ io = ioctl(cdrom_cache[dev].fd, CDIOREADTOCENTRYS, &entry);
+ if (io == -1) {
+ WARN("error read entry (%s)\n", strerror(errno));
+ goto end;
+ }
+ toc->TrackData[i - toc->FirstTrack].Control = toc_buffer.control;
+ toc->TrackData[i - toc->FirstTrack].Adr = toc_buffer.addr_type;
+ /* marking last track with leadout value as index */
+ toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.starting_track;
+ toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
+ toc->TrackData[i - toc->FirstTrack].Address[1] = toc_buffer.addr.msf.minute;
+ toc->TrackData[i - toc->FirstTrack].Address[2] = toc_buffer.addr.msf.second;
+ toc->TrackData[i - toc->FirstTrack].Address[3] = toc_buffer.addr.msf.frame;
+ }
+ cdrom_cache[dev].toc_good = 1;
+ io = 0;
+#else
+ io = STATUS_NOT_SUPPORTED;
+#endif
+end:
+ return CDROM_GetStatusCode(io);
+}
+
+static void CDROM_ClearCacheEntry(int dev)
+{
+ cdrom_cache[dev].toc_good = 0;
+}
+
+
+
/******************************************************************
* CDROM_GetIdeInterface
*
@@ -121,18 +340,18 @@ static struct cdrom_cache cdrom_cache[26
*
* NOTE: this function is used in CDROM_InitRegistry and CDROM_GetAddress
*/
-static int CDROM_GetIdeInterface(int dev, int* iface, int* device)
+static int CDROM_GetIdeInterface(int fd, int* iface, int* device)
{
#if defined(linux)
{
struct stat st;
#ifdef SG_EMULATED_HOST
- if (ioctl(dev, SG_EMULATED_HOST) != -1) {
+ if (ioctl(fd, SG_EMULATED_HOST) != -1) {
FIXME("not implemented for true scsi drives\n");
return 0;
}
#endif
- if ( fstat(dev, &st) == -1 || ! S_ISBLK(st.st_mode)) {
+ if ( fstat(fd, &st) == -1 || ! S_ISBLK(st.st_mode)) {
FIXME("cdrom not a block device!!!\n");
return 0;
}
@@ -172,7 +391,7 @@ static int CDROM_GetIdeInterface(int dev
* NOTE: programs usually read these registry entries after sending the
* IOCTL_SCSI_GET_ADDRESS ioctl to the cdrom
*/
-void CDROM_InitRegistry(int dev)
+void CDROM_InitRegistry(int fd)
{
int portnum, targetid;
OBJECT_ATTRIBUTES attr;
@@ -195,7 +414,7 @@ void CDROM_InitRegistry(int dev)
attr.SecurityDescriptor = NULL;
attr.SecurityQualityOfService = NULL;
- if ( ! CDROM_GetIdeInterface(dev, &portnum, &targetid))
+ if ( ! CDROM_GetIdeInterface(fd, &portnum, &targetid))
return;
/* Ensure there is Scsi key */
@@ -232,7 +451,7 @@ void CDROM_InitRegistry(int dev)
#ifdef HDIO_GET_DMA
{
int dma;
- if (ioctl(dev,HDIO_GET_DMA, &dma) != -1) {
+ if (ioctl(fd,HDIO_GET_DMA, &dma) != -1) {
value = dma;
TRACE("setting dma to %lx\n", value);
}
@@ -327,7 +546,9 @@ static int CDROM_Open(HANDLE hDevice, DW
}
}
cdrom_cache[dev].count++;
- return cdrom_cache[dev].fd;
+ TRACE("%d, %d, %d\n", dev, cdrom_cache[dev].fd, cdrom_cache[dev].count);
+ /* return cdrom_cache[dev].fd; */
+ return dev; /* can still find fd by using dev */
}
/******************************************************************
@@ -335,13 +556,15 @@ static int CDROM_Open(HANDLE hDevice, DW
*
*
*/
-static void CDROM_Close(DWORD clientID, int fd)
+static void CDROM_Close(DWORD clientID)
{
int dev = LOWORD(clientID);
- if (dev >= 26 || fd != cdrom_cache[dev].fd) FIXME("how come\n");
- if (--cdrom_cache[dev].count == 0)
- close(cdrom_cache[dev].fd);
+ if (dev >= 26 /*|| fd != cdrom_cache[dev].fd*/) FIXME("how come\n");
+ if (--cdrom_cache[dev].count == 0) {
+ close(cdrom_cache[dev].fd);
+ cdrom_cache[dev].fd = 0;
+ }
}
/******************************************************************
@@ -361,6 +584,9 @@ static DWORD CDROM_GetStatusCode(int io)
return STATUS_NO_MEDIA_IN_DEVICE;
case EPERM:
return STATUS_ACCESS_DENIED;
+ case EINVAL:
+ return STATUS_INVALID_PARAMETER;
+ /* case EBADF: Bad file descriptor */
}
FIXME("Unmapped error code %d: %s\n", errno, strerror(errno));
return STATUS_IO_DEVICE_ERROR;
@@ -380,15 +606,22 @@ static DWORD CDROM_GetDeviceNumber(int d
static DWORD CDROM_GetDriveGeometry(int dev, DISK_GEOMETRY* dg)
{
-#if 0
- dg->Cylinders.s.LowPart = 1; /* FIXME */
- dg->Cylinders.s.HighPart = 0; /* FIXME */
- dg->MediaType = 1; /* FIXME */
- dg->TracksPerCylinder = 1; /* FIXME */
- dg->SectorsPerTrack = 1; /* FIXME */
- dg->BytesPerSector= 1; /* FIXME */
-#endif
- return STATUS_NOT_SUPPORTED;
+ CDROM_TOC toc;
+ DWORD ret = 0;
+ int fsize=0;
+
+ if ((ret = CDROM_ReadTOC(dev, &toc)) != 0) return ret;
+
+ fsize = FRAME_OF_TOC(toc, toc.LastTrack+1)
+ - FRAME_OF_TOC(toc, 1); /* Total size in frames */
+
+ dg->Cylinders.s.LowPart = fsize / (64 * 32);
+ dg->Cylinders.s.HighPart = 0;
+ dg->MediaType = RemovableMedia;
+ dg->TracksPerCylinder = 64;
+ dg->SectorsPerTrack = 32;
+ dg->BytesPerSector= 2048;
+ return ret;
}
/**************************************************************************
@@ -397,9 +630,9 @@ static DWORD CDROM_GetDriveGeometry(int
static DWORD CDROM_ResetAudio(int dev)
{
#if defined(linux)
- return CDROM_GetStatusCode(ioctl(dev, CDROMRESET));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDROMRESET));
#elif defined(__FreeBSD__) || defined(__NetBSD__)
- return CDROM_GetStatusCode(ioctl(dev, CDIOCRESET, NULL));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDIOCRESET, NULL));
#else
return STATUS_NOT_SUPPORTED;
#endif
@@ -413,11 +646,11 @@ static DWORD CDROM_ResetAudio(int dev)
static DWORD CDROM_SetTray(int dev, BOOL doEject)
{
#if defined(linux)
- return CDROM_GetStatusCode(ioctl(dev, doEject ? CDROMEJECT : CDROMCLOSETRAY));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, doEject ? CDROMEJECT : CDROMCLOSETRAY));
#elif defined(__FreeBSD__) || defined(__NetBSD__)
- return CDROM_GetStatusCode((ioctl(dev, CDIOCALLOW, NULL)) ||
- (ioctl(dev, doEject ? CDIOCEJECT : CDIOCCLOSE, NULL)) ||
- (ioctl(dev, CDIOCPREVENT, NULL)));
+ return CDROM_GetStatusCode((ioctl(cdrom_cache[dev].fd, CDIOCALLOW, NULL)) ||
+ (ioctl(cdrom_cache[dev].fd, doEject ? CDIOCEJECT : CDIOCCLOSE, NULL)) ||
+ (ioctl(cdrom_cache[dev].fd, CDIOCPREVENT, NULL)));
#else
return STATUS_NOT_SUPPORTED;
#endif
@@ -431,9 +664,9 @@ static DWORD CDROM_SetTray(int dev, BOOL
static DWORD CDROM_ControlEjection(int dev, const PREVENT_MEDIA_REMOVAL* rmv)
{
#if defined(linux)
- return CDROM_GetStatusCode(ioctl(dev, CDROM_LOCKDOOR, rmv->PreventMediaRemoval));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDROM_LOCKDOOR, rmv->PreventMediaRemoval));
#elif defined(__FreeBSD__) || defined(__NetBSD__)
- return CDROM_GetStatusCode(ioctl(dev, (rmv->PreventMediaRemoval) ? CDIOCPREVENT : CDIOCALLOW, NULL));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, (rmv->PreventMediaRemoval) ? CDIOCPREVENT : CDIOCALLOW, NULL));
#else
return STATUS_NOT_SUPPORTED;
#endif
@@ -448,97 +681,15 @@ static DWORD CDROM_ReadTOC(int dev, CDRO
{
DWORD ret = STATUS_NOT_SUPPORTED;
-#if defined(linux)
- int i, io = -1;
- struct cdrom_tochdr hdr;
- struct cdrom_tocentry entry;
-
- io = ioctl(dev, CDROMREADTOCHDR, &hdr);
- if (io == -1)
- {
- WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
- goto end;
- }
- toc->FirstTrack = hdr.cdth_trk0;
- toc->LastTrack = hdr.cdth_trk1;
-
- TRACE("from=%d to=%d\n", toc->FirstTrack, toc->LastTrack);
-
- for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
- {
- if (i == toc->LastTrack + 1)
- {
- entry.cdte_track = CDROM_LEADOUT;
- } else {
- entry.cdte_track = i;
- }
- entry.cdte_format = CDROM_MSF;
- io = ioctl(dev, CDROMREADTOCENTRY, &entry);
- if (io == -1) {
- WARN("error read entry (%s)\n", strerror(errno));
- goto end;
- }
- toc->TrackData[i - toc->FirstTrack].Control = entry.cdte_ctrl;
- toc->TrackData[i - toc->FirstTrack].Adr = entry.cdte_adr;
- /* marking last track with leadout value as index */
- toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.cdte_track;
- toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
- toc->TrackData[i - toc->FirstTrack].Address[1] = entry.cdte_addr.msf.minute;
- toc->TrackData[i - toc->FirstTrack].Address[2] = entry.cdte_addr.msf.second;
- toc->TrackData[i - toc->FirstTrack].Address[3] = entry.cdte_addr.msf.frame;
- }
-end:
- ret = CDROM_GetStatusCode(io);
-#elif defined(__FreeBSD__) || defined(__NetBSD__)
- int i, io = -1;
- struct ioc_toc_header hdr;
- struct ioc_read_toc_entry entry;
- struct cd_toc_entry toc_buffer;
-
- io = ioctl(dev, CDIOREADTOCHEADER, &hdr);
- if (io == -1)
- {
- WARN("(%d) -- Error occurred (%s)!\n", dev, strerror(errno));
- goto end;
- }
- toc->FirstTrack = hdr.starting_track;
- toc->LastTrack = hdr.ending_track;
-
- TRACE("from=%d to=%d\n", toc->FirstTrack, toc->LastTrack);
-
- for (i = toc->FirstTrack; i <= toc->LastTrack + 1; i++)
- {
- if (i == toc->LastTrack + 1)
- {
-#define LEADOUT 0xaa
- entry.starting_track = LEADOUT;
- } else {
- entry.starting_track = i;
- }
- memset((char *)&toc_buffer, 0, sizeof(toc_buffer));
- entry.address_format = CD_MSF_FORMAT;
- entry.data_len = sizeof(toc_buffer);
- entry.data = &toc_buffer;
- io = ioctl(dev, CDIOREADTOCENTRYS, &entry);
- if (io == -1) {
- WARN("error read entry (%s)\n", strerror(errno));
- goto end;
- }
- toc->TrackData[i - toc->FirstTrack].Control = toc_buffer.control;
- toc->TrackData[i - toc->FirstTrack].Adr = toc_buffer.addr_type;
- /* marking last track with leadout value as index */
- toc->TrackData[i - toc->FirstTrack].TrackNumber = entry.starting_track;
- toc->TrackData[i - toc->FirstTrack].Address[0] = 0;
- toc->TrackData[i - toc->FirstTrack].Address[1] = toc_buffer.addr.msf.minute;
- toc->TrackData[i - toc->FirstTrack].Address[2] = toc_buffer.addr.msf.second;
- toc->TrackData[i - toc->FirstTrack].Address[3] = toc_buffer.addr.msf.frame;
+ if (dev < 0 || dev >= 26)
+ return STATUS_INVALID_PARAMETER;
+ if ( !cdrom_cache[dev].toc_good ) {
+ ret = CDROM_SyncCache(dev);
+ if ( ret )
+ return ret;
}
-end:
- ret = CDROM_GetStatusCode(io);
-#else
- ret = STATUS_NOT_SUPPORTED;
-#endif
- return ret;
+ *toc = cdrom_cache[dev].toc;
+ return 0;
}
/******************************************************************
@@ -555,7 +706,7 @@ static DWORD CDROM_GetDiskData(int dev,
if ((ret = CDROM_ReadTOC(dev, &toc)) != 0) return ret;
data->DiskData = 0;
for (i = toc.FirstTrack; i <= toc.LastTrack; i++) {
- if (toc.TrackData[i].Control & 0x04)
+ if (toc.TrackData[i-toc.FirstTrack].Control & 0x04)
data->DiskData |= CDROM_DISK_DATA_TRACK;
else
data->DiskData |= CDROM_DISK_AUDIO_TRACK;
@@ -579,11 +730,12 @@ static DWORD CDROM_ReadQChannel(int dev,
struct cdrom_subchnl sc;
sc.cdsc_format = CDROM_MSF;
- io = ioctl(dev, CDROMSUBCHNL, &sc);
+ io = ioctl(cdrom_cache[dev].fd, CDROMSUBCHNL, &sc);
if (io == -1)
{
TRACE("opened or no_media (%s)!\n", strerror(errno));
hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
+ CDROM_ClearCacheEntry(dev);
goto end;
}
@@ -591,9 +743,11 @@ static DWORD CDROM_ReadQChannel(int dev,
switch (sc.cdsc_audiostatus) {
case CDROM_AUDIO_INVALID:
+ CDROM_ClearCacheEntry(dev);
hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
break;
case CDROM_AUDIO_NO_STATUS:
+ CDROM_ClearCacheEntry(dev);
hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
break;
case CDROM_AUDIO_PLAY:
@@ -616,28 +770,37 @@ static DWORD CDROM_ReadQChannel(int dev,
{
case IOCTL_CDROM_CURRENT_POSITION:
size = sizeof(SUB_Q_CURRENT_POSITION);
- data->CurrentPosition.FormatCode = sc.cdsc_format;
- data->CurrentPosition.Control = sc.cdsc_ctrl;
- data->CurrentPosition.ADR = sc.cdsc_adr;
- data->CurrentPosition.TrackNumber = sc.cdsc_trk;
- data->CurrentPosition.IndexNumber = sc.cdsc_ind;
-
- data->CurrentPosition.AbsoluteAddress[0] = 0;
- data->CurrentPosition.AbsoluteAddress[1] = sc.cdsc_absaddr.msf.minute;
- data->CurrentPosition.AbsoluteAddress[2] = sc.cdsc_absaddr.msf.second;
- data->CurrentPosition.AbsoluteAddress[3] = sc.cdsc_absaddr.msf.frame;
-
- data->CurrentPosition.TrackRelativeAddress[0] = 0;
- data->CurrentPosition.TrackRelativeAddress[1] = sc.cdsc_reladdr.msf.minute;
- data->CurrentPosition.TrackRelativeAddress[2] = sc.cdsc_reladdr.msf.second;
- data->CurrentPosition.TrackRelativeAddress[3] = sc.cdsc_reladdr.msf.frame;
+ if (hdr->AudioStatus==AUDIO_STATUS_IN_PROGRESS) {
+ data->CurrentPosition.FormatCode = sc.cdsc_format;
+ data->CurrentPosition.Control = sc.cdsc_ctrl;
+ data->CurrentPosition.ADR = sc.cdsc_adr;
+ data->CurrentPosition.TrackNumber = sc.cdsc_trk;
+ data->CurrentPosition.IndexNumber = sc.cdsc_ind;
+
+ data->CurrentPosition.AbsoluteAddress[0] = 0;
+ data->CurrentPosition.AbsoluteAddress[1] = sc.cdsc_absaddr.msf.minute;
+ data->CurrentPosition.AbsoluteAddress[2] = sc.cdsc_absaddr.msf.second;
+ data->CurrentPosition.AbsoluteAddress[3] = sc.cdsc_absaddr.msf.frame;
+
+ data->CurrentPosition.TrackRelativeAddress[0] = 0;
+ data->CurrentPosition.TrackRelativeAddress[1] = sc.cdsc_reladdr.msf.minute;
+ data->CurrentPosition.TrackRelativeAddress[2] = sc.cdsc_reladdr.msf.second;
+ data->CurrentPosition.TrackRelativeAddress[3] = sc.cdsc_reladdr.msf.frame;
+
+ cdrom_cache[dev].CurrentPosition = data->CurrentPosition;
+ }
+ else /* not playing */
+ {
+ cdrom_cache[dev].CurrentPosition.Header = *hdr; /* Preserve header info */
+ data->CurrentPosition = cdrom_cache[dev].CurrentPosition;
+ }
break;
case IOCTL_CDROM_MEDIA_CATALOG:
size = sizeof(SUB_Q_MEDIA_CATALOG_NUMBER);
data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
{
struct cdrom_mcn mcn;
- if ((io = ioctl(dev, CDROM_GET_MCN, &mcn)) == -1) goto end;
+ if ((io = ioctl(cdrom_cache[dev].fd, CDROM_GET_MCN, &mcn)) == -1) goto end;
data->MediaCatalog.FormatCode = IOCTL_CDROM_MEDIA_CATALOG;
data->MediaCatalog.Mcval = 0; /* FIXME */
@@ -680,10 +843,11 @@ static DWORD CDROM_ReadQChannel(int dev,
sc.what.track_info.track_number = data->TrackIsrc.Track;
break;
}
- io = ioctl(dev, CDIOCREADSUBCHANNEL, &read_sc);
+ io = ioctl(cdrom_cache[dev].fd, CDIOCREADSUBCHANNEL, &read_sc);
if (io == -1)
{
TRACE("opened or no_media (%s)!\n", strerror(errno));
+ CDROM_ClearCacheEntry(dev);
hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
goto end;
}
@@ -692,9 +856,11 @@ static DWORD CDROM_ReadQChannel(int dev,
switch (sc.header.audio_status) {
case CD_AS_AUDIO_INVALID:
+ CDROM_ClearCacheEntry(dev);
hdr->AudioStatus = AUDIO_STATUS_NOT_SUPPORTED;
break;
case CD_AS_NO_STATUS:
+ CDROM_ClearCacheEntry(dev);
hdr->AudioStatus = AUDIO_STATUS_NO_STATUS;
break;
case CD_AS_PLAY_IN_PROGRESS:
@@ -716,20 +882,27 @@ static DWORD CDROM_ReadQChannel(int dev,
{
case IOCTL_CDROM_CURRENT_POSITION:
size = sizeof(SUB_Q_CURRENT_POSITION);
- data->CurrentPosition.FormatCode = sc.what.position.data_format;
- data->CurrentPosition.Control = sc.what.position.control;
- data->CurrentPosition.ADR = sc.what.position.addr_type;
- data->CurrentPosition.TrackNumber = sc.what.position.track_number;
- data->CurrentPosition.IndexNumber = sc.what.position.index_number;
-
- data->CurrentPosition.AbsoluteAddress[0] = 0;
- data->CurrentPosition.AbsoluteAddress[1] = sc.what.position.absaddr.msf.minute;
- data->CurrentPosition.AbsoluteAddress[2] = sc.what.position.absaddr.msf.second;
- data->CurrentPosition.AbsoluteAddress[3] = sc.what.position.absaddr.msf.frame;
- data->CurrentPosition.TrackRelativeAddress[0] = 0;
- data->CurrentPosition.TrackRelativeAddress[1] = sc.what.position.reladdr.msf.minute;
- data->CurrentPosition.TrackRelativeAddress[2] = sc.what.position.reladdr.msf.second;
- data->CurrentPosition.TrackRelativeAddress[3] = sc.what.position.reladdr.msf.frame;
+ if (hdr->AudioStatus==AUDIO_STATUS_IN_PROGRESS) {
+ data->CurrentPosition.FormatCode = sc.what.position.data_format;
+ data->CurrentPosition.Control = sc.what.position.control;
+ data->CurrentPosition.ADR = sc.what.position.addr_type;
+ data->CurrentPosition.TrackNumber = sc.what.position.track_number;
+ data->CurrentPosition.IndexNumber = sc.what.position.index_number;
+
+ data->CurrentPosition.AbsoluteAddress[0] = 0;
+ data->CurrentPosition.AbsoluteAddress[1] = sc.what.position.absaddr.msf.minute;
+ data->CurrentPosition.AbsoluteAddress[2] = sc.what.position.absaddr.msf.second;
+ data->CurrentPosition.AbsoluteAddress[3] = sc.what.position.absaddr.msf.frame;
+ data->CurrentPosition.TrackRelativeAddress[0] = 0;
+ data->CurrentPosition.TrackRelativeAddress[1] = sc.what.position.reladdr.msf.minute;
+ data->CurrentPosition.TrackRelativeAddress[2] = sc.what.position.reladdr.msf.second;
+ data->CurrentPosition.TrackRelativeAddress[3] = sc.what.position.reladdr.msf.frame;
+ cdrom_cache[dev].CurrentPosition = data->CurrentPosition;
+ }
+ else { /* not playing */
+ cdrom_cache[dev].CurrentPosition.Header = *hdr; /* Preserve header info */
+ data->CurrentPosition = cdrom_cache[dev].CurrentPosition;
+ }
break;
case IOCTL_CDROM_MEDIA_CATALOG:
size = sizeof(SUB_Q_MEDIA_CATALOG_NUMBER);
@@ -785,13 +958,13 @@ static DWORD CDROM_PlayAudioMSF(int dev,
msf.cdmsf_sec1 = audio_msf->EndingS;
msf.cdmsf_frame1 = audio_msf->EndingF;
- io = ioctl(dev, CDROMSTART);
+ io = ioctl(cdrom_cache[dev].fd, CDROMSTART);
if (io == -1)
{
WARN("motor doesn't start !\n");
goto end;
}
- io = ioctl(dev, CDROMPLAYMSF, &msf);
+ io = ioctl(cdrom_cache[dev].fd, CDROMPLAYMSF, &msf);
if (io == -1)
{
WARN("device doesn't play !\n");
@@ -813,13 +986,13 @@ static DWORD CDROM_PlayAudioMSF(int dev,
msf.end_s = audio_msf->EndingS;
msf.end_f = audio_msf->EndingF;
- io = ioctl(dev, CDIOCSTART, NULL);
+ io = ioctl(cdrom_cache[dev].fd, CDIOCSTART, NULL);
if (io == -1)
{
WARN("motor doesn't start !\n");
goto end;
}
- io = ioctl(dev, CDIOCPLAYMSF, &msf);
+ io = ioctl(cdrom_cache[dev].fd, CDIOCPLAYMSF, &msf);
if (io == -1)
{
WARN("device doesn't play !\n");
@@ -841,16 +1014,88 @@ end:
*/
static DWORD CDROM_SeekAudioMSF(int dev, const CDROM_SEEK_AUDIO_MSF* audio_msf)
{
+ CDROM_TOC toc;
+ int i, io, frame;
+ SUB_Q_CURRENT_POSITION *cp;
#if defined(linux)
struct cdrom_msf0 msf;
- msf.minute = audio_msf->M;
- msf.second = audio_msf->S;
- msf.frame = audio_msf->F;
+ struct cdrom_subchnl sc;
+#elif defined(__FreeBSD__) || defined(__NetBSD__)
+ struct ioc_play_msf msf;
+ struct ioc_read_subchannel read_sc;
+ struct cd_sub_channel_info sc;
+ int final_frame;
+#endif
+
+ /* Use the information on the TOC to compute the new current
+ * position, which is shadowed on the cache. [Portable]. */
+ frame = FRAME_OF_MSF(*audio_msf);
+ cp = &cdrom_cache[dev].CurrentPosition;
+ if ((io = CDROM_ReadTOC(dev, &toc)) != 0) return io;
+
+ for(i=toc.FirstTrack;i<=toc.LastTrack+1;i++)
+ if (FRAME_OF_TOC(toc,i)>frame) break;
+ if (i <= toc.FirstTrack || i > toc.LastTrack+1)
+ return STATUS_INVALID_PARAMETER;
+ i--;
+ cp->FormatCode = CDROM_MSF;
+ cp->Control = toc.TrackData[i-toc.FirstTrack].Control;
+ cp->ADR = toc.TrackData[i-toc.FirstTrack].Adr;
+ cp->TrackNumber = toc.TrackData[i-toc.FirstTrack].TrackNumber;
+ cp->IndexNumber = 0; /* FIXME: where do they keep these? */
+ cp->AbsoluteAddress[0] = 0;
+ cp->AbsoluteAddress[1] = toc.TrackData[i-toc.FirstTrack].Address[1];
+ cp->AbsoluteAddress[2] = toc.TrackData[i-toc.FirstTrack].Address[2];
+ cp->AbsoluteAddress[3] = toc.TrackData[i-toc.FirstTrack].Address[3];
+ frame -= FRAME_OF_TOC(toc,i);
+ cp->TrackRelativeAddress[0] = 0;
+ MSF_OF_FRAME(cp->TrackRelativeAddress[1], frame);
+
+ /* If playing, then issue a seek command, otherwise do nothing */
+#ifdef linux
+ sc.cdsc_format = CDROM_MSF;
- return CDROM_GetStatusCode(ioctl(dev, CDROMSEEK, &msf));
+ io = ioctl(cdrom_cache[dev].fd, CDROMSUBCHNL, &sc);
+ if (io == -1)
+ {
+ TRACE("opened or no_media (%s)!\n", strerror(errno));
+ CDROM_ClearCacheEntry(dev);
+ return CDROM_GetStatusCode(io);
+ }
+ if (sc.cdsc_audiostatus==CDROM_AUDIO_PLAY)
+ {
+ msf.minute = audio_msf->M;
+ msf.second = audio_msf->S;
+ msf.frame = audio_msf->F;
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDROMSEEK, &msf));
+ }
+ return 0;
#elif defined(__FreeBSD__) || defined(__NetBSD__)
- FIXME("Could a BSD expert implement the seek function ?\n");
- return STATUS_NOT_SUPPORTED;
+ read_sc.address_format = CD_MSF_FORMAT;
+ read_sc.track = 0;
+ read_sc.data_len = sizeof(sc);
+ read_sc.data = ≻
+ read_sc.data_format = CD_CURRENT_POSITION;
+
+ io = ioctl(cdrom_cache[dev].fd, CDIOCREADSUBCHANNEL, &read_sc);
+ if (io == -1)
+ {
+ TRACE("opened or no_media (%s)!\n", strerror(errno));
+ CDROM_ClearCacheEntry(dev);
+ return CDROM_GetStatusCode(io);
+ }
+ if (sc.header.audio_status==CD_AS_PLAY_IN_PROGRESS)
+ {
+
+ msf.start_m = audio_msf->M;
+ msf.start_s = audio_msf->S;
+ msf.start_f = audio_msf->F;
+ final_frame = FRAME_OF_TOC(toc,toc.LastTrack+1)-1;
+ MSF_OF_FRAME(msf.end_m, final_frame);
+
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDIOCPLAYMSF, &msf));
+ }
+ return 0;
#else
return STATUS_NOT_SUPPORTED;
#endif
@@ -864,9 +1109,9 @@ static DWORD CDROM_SeekAudioMSF(int dev,
static DWORD CDROM_PauseAudio(int dev)
{
#if defined(linux)
- return CDROM_GetStatusCode(ioctl(dev, CDROMPAUSE));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDROMPAUSE));
#elif defined(__FreeBSD__) || defined(__NetBSD__)
- return CDROM_GetStatusCode(ioctl(dev, CDIOCPAUSE, NULL));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDIOCPAUSE, NULL));
#else
return STATUS_NOT_SUPPORTED;
#endif
@@ -880,9 +1125,9 @@ static DWORD CDROM_PauseAudio(int dev)
static DWORD CDROM_ResumeAudio(int dev)
{
#if defined(linux)
- return CDROM_GetStatusCode(ioctl(dev, CDROMRESUME));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDROMRESUME));
#elif defined(__FreeBSD__) || defined(__NetBSD__)
- return CDROM_GetStatusCode(ioctl(dev, CDIOCRESUME, NULL));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDIOCRESUME, NULL));
#else
return STATUS_NOT_SUPPORTED;
#endif
@@ -896,9 +1141,9 @@ static DWORD CDROM_ResumeAudio(int dev)
static DWORD CDROM_StopAudio(int dev)
{
#if defined(linux)
- return CDROM_GetStatusCode(ioctl(dev, CDROMSTOP));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDROMSTOP));
#elif defined(__FreeBSD__) || defined(__NetBSD__)
- return CDROM_GetStatusCode(ioctl(dev, CDIOCSTOP, NULL));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDIOCSTOP, NULL));
#else
return STATUS_NOT_SUPPORTED;
#endif
@@ -915,7 +1160,7 @@ static DWORD CDROM_GetVolume(int dev, VO
struct cdrom_volctrl volc;
int io;
- io = ioctl(dev, CDROMVOLREAD, &volc);
+ io = ioctl(cdrom_cache[dev].fd, CDROMVOLREAD, &volc);
if (io != -1)
{
vc->PortVolume[0] = volc.channel0;
@@ -928,7 +1173,7 @@ static DWORD CDROM_GetVolume(int dev, VO
struct ioc_vol volc;
int io;
- io = ioctl(dev, CDIOCGETVOL, &volc);
+ io = ioctl(cdrom_cache[dev].fd, CDIOCGETVOL, &volc);
if (io != -1)
{
vc->PortVolume[0] = volc.vol[0];
@@ -957,7 +1202,7 @@ static DWORD CDROM_SetVolume(int dev, co
volc.channel2 = vc->PortVolume[2];
volc.channel3 = vc->PortVolume[3];
- return CDROM_GetStatusCode(ioctl(dev, CDROMVOLCTRL, &volc));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDROMVOLCTRL, &volc));
#elif defined(__FreeBSD__) || defined(__NetBSD__)
struct ioc_vol volc;
@@ -966,7 +1211,7 @@ static DWORD CDROM_SetVolume(int dev, co
volc.vol[2] = vc->PortVolume[2];
volc.vol[3] = vc->PortVolume[3];
- return CDROM_GetStatusCode(ioctl(dev, CDIOCSETVOL, &volc));
+ return CDROM_GetStatusCode(ioctl(cdrom_cache[dev].fd, CDIOCSETVOL, &volc));
#else
return STATUS_NOT_SUPPORTED;
#endif
@@ -1006,7 +1251,7 @@ static DWORD CDROM_RawRead(int dev, cons
cdr.cdread_lba = raw->DiskOffset.s.LowPart; /* FIXME ? */
cdr.cdread_bufaddr = buffer;
cdr.cdread_buflen = raw->SectorCount * sectSize;
- io = ioctl(dev, CDROMREADMODE2, &cdr);
+ io = ioctl(cdrom_cache[dev].fd, CDROMREADMODE2, &cdr);
break;
case XAForm2:
FIXME("XAForm2: NIY\n");
@@ -1027,7 +1272,7 @@ static DWORD CDROM_RawRead(int dev, cons
cdra.addr_format = CDROM_LBA;
cdra.nframes = raw->SectorCount;
cdra.buf = buffer;
- io = ioctl(dev, CDROMREADAUDIO, &cdra);
+ io = ioctl(cdrom_cache[dev].fd, CDROMREADAUDIO, &cdra);
break;
}
}
@@ -1051,7 +1296,7 @@ static DWORD CDROM_RawRead(int dev, cons
ira.address_format = CD_LBA_FORMAT;
ira.nframes = raw->SectorCount;
ira.buffer = buffer;
- io = ioctl(dev, CDIOCREADAUDIO, &ira);
+ io = ioctl(cdrom_cache[dev].fd, CDIOCREADAUDIO, &ira);
break;
}
}
@@ -1124,7 +1369,7 @@ static DWORD CDROM_ScsiPassThroughDirect
return STATUS_INVALID_PARAMETER;
}
- io = ioctl(dev, CDROM_SEND_PACKET, &cmd);
+ io = ioctl(cdrom_cache[dev].fd, CDROM_SEND_PACKET, &cmd);
if (pPacket->SenseInfoLength != 0)
{
@@ -1194,7 +1439,7 @@ static DWORD CDROM_ScsiPassThrough(int d
return STATUS_INVALID_PARAMETER;
}
- io = ioctl(dev, CDROM_SEND_PACKET, &cmd);
+ io = ioctl(cdrom_cache[dev].fd, CDROM_SEND_PACKET, &cmd);
if (pPacket->SenseInfoLength != 0)
{
@@ -1221,7 +1466,7 @@ static DWORD CDROM_GetAddress(int dev, S
address->Length = sizeof(SCSI_ADDRESS);
address->PathId = 0; /* bus number */
address->Lun = 0;
- if ( ! CDROM_GetIdeInterface(dev, &portnum, &targetid))
+ if ( ! CDROM_GetIdeInterface(cdrom_cache[dev].fd, &portnum, &targetid))
return STATUS_NOT_SUPPORTED;
address->PortNumber = portnum;
@@ -1243,8 +1488,8 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
DWORD error = 0;
int dev;
- TRACE("%lx[%c] %lx %lx %ld %lx %ld %lx %lx\n",
- (DWORD)hDevice, 'A' + LOWORD(clientID), dwIoControlCode, (DWORD)lpInBuffer, nInBufferSize,
+ TRACE("%lx[%c] %s %lx %ld %lx %ld %lx %lx\n",
+ (DWORD)hDevice, 'A' + LOWORD(clientID), iocodex(dwIoControlCode), (DWORD)lpInBuffer, nInBufferSize,
(DWORD)lpOutBuffer, nOutBufferSize, (DWORD)lpBytesReturned, (DWORD)lpOverlapped);
if (lpBytesReturned) *lpBytesReturned = 0;
@@ -1268,6 +1513,7 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
case IOCTL_STORAGE_CHECK_VERIFY:
case IOCTL_CDROM_CHECK_VERIFY:
sz = 0;
+ CDROM_ClearCacheEntry(dev);
if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
error = STATUS_INVALID_PARAMETER;
else error = CDROM_Verify(dev);
@@ -1281,12 +1527,14 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
case IOCTL_STORAGE_LOAD_MEDIA:
case IOCTL_CDROM_LOAD_MEDIA:
sz = 0;
+ CDROM_ClearCacheEntry(dev);
if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
error = STATUS_INVALID_PARAMETER;
else error = CDROM_SetTray(dev, FALSE);
break;
case IOCTL_STORAGE_EJECT_MEDIA:
sz = 0;
+ CDROM_ClearCacheEntry(dev);
if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
error = STATUS_INVALID_PARAMETER;
else error = CDROM_SetTray(dev, TRUE);
@@ -1299,6 +1547,7 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
/* FIXME the last ioctl:s is not the same as the two others...
* lockcount/owner should be handled */
sz = 0;
+ CDROM_ClearCacheEntry(dev);
if (lpOutBuffer != NULL || nOutBufferSize != 0) error = STATUS_INVALID_PARAMETER;
else if (nInBufferSize < sizeof(PREVENT_MEDIA_REMOVAL)) error = STATUS_BUFFER_TOO_SMALL;
else error = CDROM_ControlEjection(dev, (const PREVENT_MEDIA_REMOVAL*)lpInBuffer);
@@ -1315,6 +1564,7 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
case IOCTL_STORAGE_RESET_DEVICE:
sz = 0;
+ CDROM_ClearCacheEntry(dev);
if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
error = STATUS_INVALID_PARAMETER;
else error = CDROM_ResetAudio(dev);
@@ -1336,6 +1586,7 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
case IOCTL_CDROM_DISK_TYPE:
sz = sizeof(CDROM_DISK_DATA);
+ /* CDROM_ClearCacheEntry(dev); */
if (lpInBuffer != NULL || nInBufferSize != 0) error = STATUS_INVALID_PARAMETER;
else if (nOutBufferSize < sz) error = STATUS_BUFFER_TOO_SMALL;
else error = CDROM_GetDiskData(dev, (CDROM_DISK_DATA*)lpOutBuffer);
@@ -1387,6 +1638,7 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
break;
case IOCTL_CDROM_STOP_AUDIO:
sz = 0;
+ CDROM_ClearCacheEntry(dev); /* Maybe intention is to change media */
if (lpInBuffer != NULL || nInBufferSize != 0 || lpOutBuffer != NULL || nOutBufferSize != 0)
error = STATUS_INVALID_PARAMETER;
else error = CDROM_StopAudio(dev);
@@ -1399,6 +1651,7 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
break;
case IOCTL_CDROM_SET_VOLUME:
sz = 0;
+ CDROM_ClearCacheEntry(dev);
if (lpInBuffer == NULL || nInBufferSize < sizeof(VOLUME_CONTROL) || lpOutBuffer != NULL)
error = STATUS_INVALID_PARAMETER;
else error = CDROM_SetVolume(dev, (const VOLUME_CONTROL*)lpInBuffer);
@@ -1442,6 +1695,6 @@ BOOL CDROM_DeviceIoControl(DWORD clientI
SetLastError(error);
return FALSE;
}
- CDROM_Close(clientID, dev);
+ CDROM_Close(clientID);
return TRUE;
}
Index: wine/dlls/winmm/mcicda/mcicda.c
===================================================================
RCS file: /home/wine/wine/dlls/winmm/mcicda/mcicda.c,v
retrieving revision 1.26
diff -u -p -r1.26 mcicda.c
--- wine/dlls/winmm/mcicda/mcicda.c 17 Oct 2002 16:43:43 -0000 1.26
+++ wine/dlls/winmm/mcicda/mcicda.c 17 Feb 2003 04:23:55 -0000
@@ -187,10 +187,10 @@ static DWORD MCICDA_CalcFrame(WINE_MCICD
MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
addr = toc.TrackData[wTrack - toc.FirstTrack].Address;
TRACE("TMSF trackpos[%u]=%d:%d:%d\n",
- wTrack, addr[0], addr[1], addr[2]);
- dwFrame = CDFRAMES_PERMIN * (addr[0] + MCI_TMSF_MINUTE(dwTime)) +
- CDFRAMES_PERSEC * (addr[1] + MCI_TMSF_SECOND(dwTime)) +
- addr[2] + MCI_TMSF_FRAME(dwTime);
+ wTrack, addr[1], addr[2], addr[3]);
+ dwFrame = CDFRAMES_PERMIN * (addr[1] + MCI_TMSF_MINUTE(dwTime)) +
+ CDFRAMES_PERSEC * (addr[2] + MCI_TMSF_SECOND(dwTime)) +
+ addr[3] + MCI_TMSF_FRAME(dwTime);
break;
}
return dwFrame;
@@ -678,17 +678,51 @@ static DWORD MCICDA_Status(UINT wDevID,
}
/**************************************************************************
+ * MCICDA_SkipDataTracks [internal]
+ */
+static DWORD MCICDA_SkipDataTracks(WINE_MCICDAUDIO* wmcda,DWORD *frame)
+{
+ int i;
+ DWORD br;
+ CDROM_TOC toc;
+ if (!DeviceIoControl(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
+ &toc, sizeof(toc), &br, NULL)) {
+ WARN("error reading TOC !\n");
+ return MCICDA_GetError(wmcda);
+ }
+ /* Locate first track whose starting frame is bigger than frame */
+ for(i=toc.FirstTrack;i<=toc.LastTrack+1;i++)
+ if ( FRAME_OF_TOC(toc, i) > *frame ) break;
+ if (i <= toc.FirstTrack && i>toc.LastTrack+1) {
+ i = 0; /* requested address is out of range: go back to start */
+ *frame = FRAME_OF_TOC(toc,toc.FirstTrack);
+ }
+ else
+ i--;
+ /* i points to last track whose start address is not greater than frame.
+ * Now skip non-audio tracks */
+ for(;i<=toc.LastTrack+1;i++)
+ if ( ! (toc.TrackData[i-toc.FirstTrack].Control & 4) )
+ break;
+ /* The frame will be an address in the next audio track or
+ * address of lead-out. */
+ if ( FRAME_OF_TOC(toc, i) > *frame )
+ *frame = FRAME_OF_TOC(toc, i);
+ return 0;
+}
+
+/**************************************************************************
* MCICDA_Play [internal]
*/
static DWORD MCICDA_Play(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
{
WINE_MCICDAUDIO* wmcda = MCICDA_GetOpenDrv(wDevID);
DWORD ret = 0, start, end;
- CDROM_TOC toc;
DWORD br;
CDROM_PLAY_AUDIO_MSF play;
CDROM_SUB_Q_DATA_FORMAT fmt;
SUB_Q_CHANNEL_DATA data;
+ CDROM_TOC toc;
TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
@@ -700,6 +734,8 @@ static DWORD MCICDA_Play(UINT wDevID, DW
if (dwFlags & MCI_FROM) {
start = MCICDA_CalcFrame(wmcda, lpParms->dwFrom);
+ if ( (ret=MCICDA_SkipDataTracks(wmcda, &start)) )
+ return ret;
TRACE("MCI_FROM=%08lX -> %lu \n", lpParms->dwFrom, start);
} else {
fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
@@ -708,6 +744,8 @@ static DWORD MCICDA_Play(UINT wDevID, DW
return MCICDA_GetError(wmcda);
}
start = FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
+ if ( (ret=MCICDA_SkipDataTracks(wmcda, &start)) )
+ return ret;
}
if (dwFlags & MCI_TO) {
end = MCICDA_CalcFrame(wmcda, lpParms->dwTo);
@@ -817,36 +855,37 @@ static DWORD MCICDA_Seek(UINT wDevID, DW
DWORD at;
WINE_MCICDAUDIO* wmcda = MCICDA_GetOpenDrv(wDevID);
CDROM_SEEK_AUDIO_MSF seek;
- CDROM_TOC toc;
- DWORD br;
+ DWORD br, ret;
+ CDROM_TOC toc;
TRACE("(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
if (wmcda == NULL) return MCIERR_INVALID_DEVICE_ID;
if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
+ if (!DeviceIoControl(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
+ &toc, sizeof(toc), &br, NULL)) {
+ WARN("error reading TOC !\n");
+ return MCICDA_GetError(wmcda);
+ }
switch (dwFlags & ~(MCI_NOTIFY|MCI_WAIT)) {
case MCI_SEEK_TO_START:
TRACE("Seeking to start\n");
- if (!DeviceIoControl(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
- &toc, sizeof(toc), &br, NULL)) {
- WARN("error reading TOC !\n");
- return MCICDA_GetError(wmcda);
- }
- at = FRAME_OF_TOC(toc, toc.FirstTrack);
+ at = FRAME_OF_TOC(toc,toc.FirstTrack);
+ if ( (ret=MCICDA_SkipDataTracks(wmcda, &at)) )
+ return ret;
break;
case MCI_SEEK_TO_END:
TRACE("Seeking to end\n");
- if (!DeviceIoControl(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
- &toc, sizeof(toc), &br, NULL)) {
- WARN("error reading TOC !\n");
- return MCICDA_GetError(wmcda);
- }
at = FRAME_OF_TOC(toc, toc.LastTrack + 1) - 1;
+ if ( (ret=MCICDA_SkipDataTracks(wmcda, &at)) )
+ return ret;
break;
case MCI_TO:
TRACE("Seeking to %lu\n", lpParms->dwTo);
- at = lpParms->dwTo;
+ at = MCICDA_CalcFrame(wmcda, lpParms->dwTo);
+ if ( (ret=MCICDA_SkipDataTracks(wmcda, &at)) )
+ return ret;
break;
default:
TRACE("Unknown seek action %08lX\n",