notaz.gp2x.de
/
pcsx_rearmed.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #558 from gameblabla/cdrom_fixes_libretro_popo
[pcsx_rearmed.git]
/
libpcsxcore
/
cdriso.c
diff --git
a/libpcsxcore/cdriso.c
b/libpcsxcore/cdriso.c
index
6c6d835
..
549b62f
100644
(file)
--- a/
libpcsxcore/cdriso.c
+++ b/
libpcsxcore/cdriso.c
@@
-43,6
+43,14
@@
#include <unistd.h>
#endif
#include <unistd.h>
#endif
+#ifdef USE_LIBRETRO_VFS
+#include <streams/file_stream_transforms.h>
+#undef fseeko
+#undef ftello
+#define ftello rftell
+#define fseeko rfseek
+#endif
+
#define OFF_T_MSB ((off_t)1 << (sizeof(off_t) * 8 - 1))
unsigned int cdrIsoMultidiskCount;
#define OFF_T_MSB ((off_t)1 << (sizeof(off_t) * 8 - 1))
unsigned int cdrIsoMultidiskCount;
@@
-352,11
+360,12
@@
static int parsetoc(const char *isofile) {
}
}
// check if it's really a TOC named as a .cue
}
}
// check if it's really a TOC named as a .cue
- fgets(linebuf, sizeof(linebuf), fi);
- token = strtok(linebuf, " ");
- if (token && strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) {
- fclose(fi);
- return -1;
+ if (fgets(linebuf, sizeof(linebuf), fi) != NULL) {
+ token = strtok(linebuf, " ");
+ if (token && strncmp(token, "CD", 2) != 0 && strcmp(token, "CATALOG") != 0) {
+ fclose(fi);
+ return -1;
+ }
}
fseek(fi, 0, SEEK_SET);
}
}
fseek(fi, 0, SEEK_SET);
}
@@
-477,7
+486,10
@@
static int parsecue(const char *isofile) {
strncpy(cuename, isofile, sizeof(cuename));
cuename[MAXPATHLEN - 1] = '\0';
if (strlen(cuename) >= 4) {
strncpy(cuename, isofile, sizeof(cuename));
cuename[MAXPATHLEN - 1] = '\0';
if (strlen(cuename) >= 4) {
- strcpy(cuename + strlen(cuename) - 4, ".cue");
+ // If 'isofile' is a '.cd<X>' file, use it as a .cue file
+ // and don't try to search the additional .cue file
+ if (strncasecmp(cuename + strlen(cuename) - 4, ".cd", 3) != 0 )
+ strcpy(cuename + strlen(cuename) - 4, ".cue");
}
else {
return -1;
}
else {
return -1;
@@
-604,9
+616,9
@@
static int parsecue(const char *isofile) {
file_len = ftell(ti[numtracks + 1].handle) / 2352;
if (numtracks == 0 && strlen(isofile) >= 4 &&
file_len = ftell(ti[numtracks + 1].handle) / 2352;
if (numtracks == 0 && strlen(isofile) >= 4 &&
- strcmp(isofile + strlen(isofile) - 4, ".cue") == 0)
- {
- // user selected .cue as image file, use it's data track instead
+ (strcmp(isofile + strlen(isofile) - 4, ".cue") == 0 ||
+
strncasecmp(isofile + strlen(isofile) - 4, ".cd", 3) == 0))
{
+ // user selected .cue
/.cdX
as image file, use it's data track instead
fclose(cdHandle);
cdHandle = fopen(filepath, "rb");
}
fclose(cdHandle);
cdHandle = fopen(filepath, "rb");
}
@@
-615,6
+627,10
@@
static int parsecue(const char *isofile) {
fclose(fi);
fclose(fi);
+ // if there are no tracks detected, then it's not a cue file
+ if (!numtracks)
+ return -1;
+
return 0;
}
return 0;
}
@@
-704,7
+720,8
@@
static int parsemds(const char *isofile) {
memset(&ti, 0, sizeof(ti));
// check if it's a valid mds file
memset(&ti, 0, sizeof(ti));
// check if it's a valid mds file
- fread(&i, 1, sizeof(unsigned int), fi);
+ if (fread(&i, 1, sizeof(i), fi) != sizeof(i))
+ goto fail_io;
i = SWAP32(i);
if (i != 0x4944454D) {
// not an valid mds file
i = SWAP32(i);
if (i != 0x4944454D) {
// not an valid mds file
@@
-714,19
+731,22
@@
static int parsemds(const char *isofile) {
// get offset to session block
fseek(fi, 0x50, SEEK_SET);
// get offset to session block
fseek(fi, 0x50, SEEK_SET);
- fread(&offset, 1, sizeof(unsigned int), fi);
+ if (fread(&offset, 1, sizeof(offset), fi) != sizeof(offset))
+ goto fail_io;
offset = SWAP32(offset);
// get total number of tracks
offset += 14;
fseek(fi, offset, SEEK_SET);
offset = SWAP32(offset);
// get total number of tracks
offset += 14;
fseek(fi, offset, SEEK_SET);
- fread(&s, 1, sizeof(unsigned short), fi);
+ if (fread(&s, 1, sizeof(s), fi) != sizeof(s))
+ goto fail_io;
s = SWAP16(s);
numtracks = s;
// get offset to track blocks
fseek(fi, 4, SEEK_CUR);
s = SWAP16(s);
numtracks = s;
// get offset to track blocks
fseek(fi, 4, SEEK_CUR);
- fread(&offset, 1, sizeof(unsigned int), fi);
+ if (fread(&offset, 1, sizeof(offset), fi) != sizeof(offset))
+ goto fail_io;
offset = SWAP32(offset);
// skip lead-in data
offset = SWAP32(offset);
// skip lead-in data
@@
-755,32
+775,41
@@
static int parsemds(const char *isofile) {
ti[i].start[1] = fgetc(fi);
ti[i].start[2] = fgetc(fi);
ti[i].start[1] = fgetc(fi);
ti[i].start[2] = fgetc(fi);
- fread(&extra_offset, 1, sizeof(unsigned int), fi);
+ if (fread(&extra_offset, 1, sizeof(extra_offset), fi) != sizeof(extra_offset))
+ goto fail_io;
extra_offset = SWAP32(extra_offset);
// get track start offset (in .mdf)
fseek(fi, offset + 0x28, SEEK_SET);
extra_offset = SWAP32(extra_offset);
// get track start offset (in .mdf)
fseek(fi, offset + 0x28, SEEK_SET);
- fread(&l, 1, sizeof(unsigned int), fi);
+ if (fread(&l, 1, sizeof(l), fi) != sizeof(l))
+ goto fail_io;
l = SWAP32(l);
ti[i].start_offset = l;
// get pregap
fseek(fi, extra_offset, SEEK_SET);
l = SWAP32(l);
ti[i].start_offset = l;
// get pregap
fseek(fi, extra_offset, SEEK_SET);
- fread(&l, 1, sizeof(unsigned int), fi);
+ if (fread(&l, 1, sizeof(l), fi) != sizeof(l))
+ goto fail_io;
l = SWAP32(l);
if (l != 0 && i > 1)
pregapOffset = msf2sec(ti[i].start);
// get the track length
l = SWAP32(l);
if (l != 0 && i > 1)
pregapOffset = msf2sec(ti[i].start);
// get the track length
- fread(&l, 1, sizeof(unsigned int), fi);
+ if (fread(&l, 1, sizeof(l), fi) != sizeof(l))
+ goto fail_io;
l = SWAP32(l);
sec2msf(l, ti[i].length);
offset += 0x50;
}
l = SWAP32(l);
sec2msf(l, ti[i].length);
offset += 0x50;
}
-
fclose(fi);
return 0;
fclose(fi);
return 0;
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ fclose(fi);
+ return -1;
}
static int handlepbp(const char *isofile) {
}
static int handlepbp(const char *isofile) {
@@
-831,7
+860,8
@@
static int handlepbp(const char *isofile) {
}
psisoimg_offs = pbp_hdr.psar_offs;
}
psisoimg_offs = pbp_hdr.psar_offs;
- fread(psar_sig, 1, sizeof(psar_sig), cdHandle);
+ if (fread(psar_sig, 1, sizeof(psar_sig), cdHandle) != sizeof(psar_sig))
+ goto fail_io;
psar_sig[10] = 0;
if (strcmp(psar_sig, "PSTITLEIMG") == 0) {
// multidisk image?
psar_sig[10] = 0;
if (strcmp(psar_sig, "PSTITLEIMG") == 0) {
// multidisk image?
@@
-867,7
+897,8
@@
static int handlepbp(const char *isofile) {
goto fail_io;
}
goto fail_io;
}
- fread(psar_sig, 1, sizeof(psar_sig), cdHandle);
+ if (fread(psar_sig, 1, sizeof(psar_sig), cdHandle) != sizeof(psar_sig))
+ goto fail_io;
psar_sig[10] = 0;
}
psar_sig[10] = 0;
}
@@
-885,15
+916,18
@@
static int handlepbp(const char *isofile) {
// first 3 entries are special
fseek(cdHandle, sizeof(toc_entry), SEEK_CUR);
// first 3 entries are special
fseek(cdHandle, sizeof(toc_entry), SEEK_CUR);
- fread(&toc_entry, 1, sizeof(toc_entry), cdHandle);
+ if (fread(&toc_entry, 1, sizeof(toc_entry), cdHandle) != sizeof(toc_entry))
+ goto fail_io;
numtracks = btoi(toc_entry.index1[0]);
numtracks = btoi(toc_entry.index1[0]);
- fread(&toc_entry, 1, sizeof(toc_entry), cdHandle);
+ if (fread(&toc_entry, 1, sizeof(toc_entry), cdHandle) != sizeof(toc_entry))
+ goto fail_io;
cd_length = btoi(toc_entry.index1[0]) * 60 * 75 +
btoi(toc_entry.index1[1]) * 75 + btoi(toc_entry.index1[2]);
for (i = 1; i <= numtracks; i++) {
cd_length = btoi(toc_entry.index1[0]) * 60 * 75 +
btoi(toc_entry.index1[1]) * 75 + btoi(toc_entry.index1[2]);
for (i = 1; i <= numtracks; i++) {
- fread(&toc_entry, 1, sizeof(toc_entry), cdHandle);
+ if (fread(&toc_entry, 1, sizeof(toc_entry), cdHandle) != sizeof(toc_entry))
+ goto fail_io;
ti[i].type = (toc_entry.type == 1) ? CDDA : DATA;
ti[i].type = (toc_entry.type == 1) ? CDDA : DATA;
@@
-951,7
+985,14
@@
static int handlepbp(const char *isofile) {
fail_index:
free(compr_img->index_table);
compr_img->index_table = NULL;
fail_index:
free(compr_img->index_table);
compr_img->index_table = NULL;
+ goto done;
+
fail_io:
fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+
+done:
if (compr_img != NULL) {
free(compr_img);
compr_img = NULL;
if (compr_img != NULL) {
free(compr_img);
compr_img = NULL;
@@
-1050,7
+1091,10
@@
static int handlechd(const char *isofile) {
goto fail_io;
if(chd_open(isofile, CHD_OPEN_READ, NULL, &chd_img->chd) != CHDERR_NONE)
goto fail_io;
if(chd_open(isofile, CHD_OPEN_READ, NULL, &chd_img->chd) != CHDERR_NONE)
- goto fail_io;
+ goto fail_io;
+
+ if (Config.CHD_Precache && (chd_precache(chd_img->chd) != CHDERR_NONE))
+ goto fail_io;
chd_img->header = chd_get_header(chd_img->chd);
chd_img->header = chd_get_header(chd_img->chd);
@@
-1064,7
+1108,8
@@
static int handlechd(const char *isofile) {
cddaBigEndian = TRUE;
numtracks = 0;
cddaBigEndian = TRUE;
numtracks = 0;
- int frame_offset = 150;
+ int frame_offset = 0;
+ int file_offset = 0;
memset(ti, 0, sizeof(ti));
while (1)
memset(ti, 0, sizeof(ti));
while (1)
@@
-1089,18
+1134,20
@@
static int handlechd(const char *isofile) {
else
break;
else
break;
- ti[md.track].type = !strncmp(md.type, "AUDIO", 5) ? CDDA : DATA;
+ if(md.track == 1)
+ md.pregap = 150;
+ else
+ sec2msf(msf2sec(ti[md.track-1].length) + md.pregap, ti[md.track-1].length);
- sec2msf(frame_offset + md.pregap, ti[md.track].start);
- sec2msf(md.frames - md.pregap, ti[md.track].length);
+ ti[md.track].type = !strncmp(md.type, "AUDIO", 5) ? CDDA : DATA;
- if (!strcmp(md.type, md.pgtype))
-
frame_offset += md.pregap
;
+ sec2msf(frame_offset + md.pregap, ti[md.track].start);
+
sec2msf(md.frames, ti[md.track].length)
;
-
ti[md.track].start_offset = frame_offset * CD_FRAMESIZE_RAW
;
+
ti[md.track].start_offset = file_offset
;
- frame_offset += md.
frames
;
- f
rame_offset +=
md.postgap;
+ frame_offset += md.
pregap + md.frames + md.postgap
;
+ f
ile_offset += md.frames +
md.postgap;
numtracks++;
}
numtracks++;
}
@@
-1368,10
+1415,18
@@
static int cdread_sub_mixed(FILE *f, unsigned int base, void *dest, int sector)
fseek(f, base + sector * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE), SEEK_SET);
ret = fread(dest, 1, CD_FRAMESIZE_RAW, f);
fseek(f, base + sector * (CD_FRAMESIZE_RAW + SUB_FRAMESIZE), SEEK_SET);
ret = fread(dest, 1, CD_FRAMESIZE_RAW, f);
- fread(subbuffer, 1, SUB_FRAMESIZE, f);
+ if (fread(subbuffer, 1, SUB_FRAMESIZE, f) != SUB_FRAMESIZE)
+ goto fail_io;
if (subChanRaw) DecodeRawSubData();
if (subChanRaw) DecodeRawSubData();
+ goto done;
+
+fail_io:
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+done:
return ret;
}
return ret;
}
@@
-1482,19
+1537,17
@@
static int cdread_chd(FILE *f, unsigned int base, void *dest, int sector)
int hunk;
if (base)
int hunk;
if (base)
- sector += base
/ CD_FRAMESIZE_RAW
;
+ sector += base;
hunk = sector / chd_img->sectors_per_hunk;
chd_img->sector_in_hunk = sector % chd_img->sectors_per_hunk;
hunk = sector / chd_img->sectors_per_hunk;
chd_img->sector_in_hunk = sector % chd_img->sectors_per_hunk;
- if (hunk == chd_img->current_hunk)
- goto finish;
-
- chd_read(chd_img->chd, hunk, chd_img->buffer);
-
- chd_img->current_hunk = hunk;
+ if (hunk != chd_img->current_hunk)
+ {
+ chd_read(chd_img->chd, hunk, chd_img->buffer);
+ chd_img->current_hunk = hunk;
+ }
-finish:
if (dest != cdbuffer) // copy avoid HACK
memcpy(dest, chd_img->buffer[chd_img->sector_in_hunk],
CD_FRAMESIZE_RAW);
if (dest != cdbuffer) // copy avoid HACK
memcpy(dest, chd_img->buffer[chd_img->sector_in_hunk],
CD_FRAMESIZE_RAW);
@@
-1701,7
+1754,12
@@
static long CALLBACK ISOopen(void) {
if (ftello(cdHandle) % 2048 == 0) {
unsigned int modeTest = 0;
fseek(cdHandle, 0, SEEK_SET);
if (ftello(cdHandle) % 2048 == 0) {
unsigned int modeTest = 0;
fseek(cdHandle, 0, SEEK_SET);
- fread(&modeTest, 4, 1, cdHandle);
+ if (!fread(&modeTest, sizeof(modeTest), 1, cdHandle)) {
+#ifndef NDEBUG
+ SysPrintf(_("File IO error in <%s:%s>.\n"), __FILE__, __func__);
+#endif
+ return -1;
+ }
if (SWAP32(modeTest) != 0xffffff00) {
strcat(image_str, "[2048]");
isMode1ISO = TRUE;
if (SWAP32(modeTest) != 0xffffff00) {
strcat(image_str, "[2048]");
isMode1ISO = TRUE;
@@
-1857,12
+1915,12
@@
static void DecodeRawSubData(void) {
// read track
// time: byte 0 - minute; byte 1 - second; byte 2 - frame
// uses bcd format
// read track
// time: byte 0 - minute; byte 1 - second; byte 2 - frame
// uses bcd format
-static
long
CALLBACK ISOreadTrack(unsigned char *time) {
+static
boolean
CALLBACK ISOreadTrack(unsigned char *time) {
int sector = MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2]));
long ret;
if (cdHandle == NULL) {
int sector = MSF2SECT(btoi(time[0]), btoi(time[1]), btoi(time[2]));
long ret;
if (cdHandle == NULL) {
- return
-1
;
+ return
0
;
}
if (pregapOffset) {
}
if (pregapOffset) {
@@
-1876,16
+1934,18
@@
static long CALLBACK ISOreadTrack(unsigned char *time) {
ret = cdimg_read_func(cdHandle, 0, cdbuffer, sector);
if (ret < 0)
ret = cdimg_read_func(cdHandle, 0, cdbuffer, sector);
if (ret < 0)
- return
-1
;
+ return
0
;
if (subHandle != NULL) {
fseek(subHandle, sector * SUB_FRAMESIZE, SEEK_SET);
if (subHandle != NULL) {
fseek(subHandle, sector * SUB_FRAMESIZE, SEEK_SET);
- fread(subbuffer, 1, SUB_FRAMESIZE, subHandle);
+ if (fread(subbuffer, 1, SUB_FRAMESIZE, subHandle) != SUB_FRAMESIZE)
+ /* Faulty subchannel data shouldn't cause a read failure */
+ return 0;
if (subChanRaw) DecodeRawSubData();
}
if (subChanRaw) DecodeRawSubData();
}
- return
0
;
+ return
1
;
}
// plays cdda audio
}
// plays cdda audio