Exemple #1
0
int INIReadLine(ACTUALHANDLE infile, char *buffer)
{
	int charcount;
	int i;
	char tempin[2];
	int retflag;
	int retval;
#ifdef VERBOSE_FUNCTION_INI
	PrintLog("CDVDiso ini: ReadLine()");
#endif /* VERBOSE_FUNCTION_INI */
	charcount = 0;
	i = 0;
	tempin[1] = 0;
	retflag = 0;
	while ((i < INIMAXLEN) && (retflag < 2)) {
		retval = ActualFileRead(infile, 1, tempin);
		charcount++;
		if (retval != 1) {
			retflag = 2;
			charcount--;
		} else if (tempin[0] == '\n')
			retflag = 2;
		else if (tempin[0] >= ' ') {
			*(buffer + i) = tempin[0];
			i++;
		} // ENDLONGIF- How do we react to the next character?
	} // ENDWHILE- Loading up on characters until an End-of-Line appears
	*(buffer + i) = 0; // And 0-terminate
#ifdef VERBOSE_FUNCTION_INI
	PrintLog("CDVDiso ini:   Line: %s", buffer);
#endif /* VERBOSE_FUNCTION_INI */
	return (charcount);
} // END INIReadLine()
Exemple #2
0
int INICopy(ACTUALHANDLE infile, ACTUALHANDLE outfile, int charcount)
{
	char buffer[4096];
	int i;
	int chunk;
	int retval;
#ifdef VERBOSE_FUNCTION_INI
	PrintLog("CDVDiso ini: Copy(%i)", charcount);
#endif /* VERBOSE_FUNCTION_INI */
	i = charcount;
	chunk = 4096;
	if (i < chunk)  chunk = i;
	while (chunk > 0) {
		retval = ActualFileRead(infile, chunk, buffer);
		if (retval <= 0)  return (i); // Trouble? Stop here.
		if (retval < chunk)  chunk = retval; // Short block? Note it.
		retval = ActualFileWrite(outfile, chunk, buffer);
		if (retval <= 0)  return (i); // Trouble? Stop here.
		i -= retval;
		if (retval < chunk)  return (i); // Short block written? Stop here.
		chunk = 4096;
		if (i < chunk)  chunk = i;
	} // ENDWHILE- Copying a section of file across, one chunk at a time.
	return (0);
} // END INICopyToPos()
Exemple #3
0
int IsoFileRead(struct IsoFile *file, char *block)
{
	int retval;

	if (file == NULL)  return(-1);
	if (block == NULL)  return(-1);
	if (file->openforread == 0)  return(-1);

#ifdef VERBOSE_FUNCTION_ISOFILE
	PrintLog("CDVD isofile: IsoFileRead(%i)", file->blocksize);
#endif /* VERBOSE_FUNCTION_ISOFILE */

	if (file->multi > 0)
	{
		retval = MultiFileRead(file, block);
	}
	else if (file->compress > 0)
	{
		retval = CompressRead(file, block);
	}
	else
	{
		if (file->sectorpos >= file->filesectorsize)  return(-1);
		retval = ActualFileRead(file->handle,
		                        file->blocksize,
		                        block);
		if (retval > 0)  file->filebytepos += retval;
		if (retval == file->blocksize)  file->filesectorpos++;
	} // ENDLONGIF- Read right file? Or compressed block? Or Raw block?
	if (retval < 0)
	{
#ifdef VERBOSE_FUNCTION_ISOFILE
		PrintLog("CDVD isofile:   Trouble reading the sector!");
#endif /* VERBOSE_FUNCTION_ISOFILE */
		return(-1);
	} // ENDIF- Trouble reading the block? Say so!

	if (retval < file->blocksize)
	{
#ifdef VERBOSE_FUNCTION_ISOFILE
		PrintLog("CDVD isofile:   Short block! Got %i out of %i bytes",
		         retval, file->blocksize);
#endif /* VERBOSE_FUNCTION_ISOFILE */
		return(-1);
	} // ENDIF- Didn't get enough bytes? Say so!

	file->sectorpos++;
	return(0);
} // END IsoFileRead()
Exemple #4
0
extern int IsoLoadTOC(struct IsoFile *isofile)
{
	char tocext[] = ".toc\0";
	char tocheader[5];
	ACTUALHANDLE tochandle;
	char tocname[256];
	int i;
	int j;
	int retval;
	unsigned char cdvdtype;
	struct tocTN toctn;
	struct tocTD toctd;
	if (isofile == NULL)  return(-1);
	i = 0;
	while ((i < 256) && (isofile->name[i] != 0))
	{
		tocname[i] = isofile->name[i];
		i++;
	} // ENDWHILE- Copying the data name to the toc name
	j = 0;
	while ((i < 256) && (tocext[j] != 0))
	{
		tocname[i] = tocext[j];
		i++;
		j++;
	} // ENDWHILE- Append ".toc" to end of name
	tocname[i] = 0; // And 0-terminate
	tochandle = ActualFileOpenForRead(tocname);
	if (tochandle == ACTUALHANDLENULL)  return(-1);

	retval = ActualFileRead(tochandle, 4, tocheader);
	if (retval < 4)
	{
		ActualFileClose(tochandle);
		tochandle = ACTUALHANDLENULL;
		return(-1);
	} // ENDIF- Trouble reading the 'toc' file?
	if ((tocheader[0] != 'T') ||
	        (tocheader[1] != 'O') ||
	        (tocheader[2] != 'C') ||
	        (tocheader[3] != '1'))
	{
		ActualFileClose(tochandle);
		tochandle = ACTUALHANDLENULL;
		return(-1);
	} // ENDIF- Not a 'toc' file after all?
#ifdef VERBOSE_FUNCTION_TOC
	PrintLog("CDVDiso TOC: IsoLoadTOC(%s)", tocname);
#endif /* VERBOSE_FUNCTION_TOC */
	retval = ActualFileRead(tochandle, 1, (char *) & cdvdtype);
	if (retval < 1)
	{
		ActualFileClose(tochandle);
		tochandle = ACTUALHANDLENULL;
		return(-1);
	} // ENDIF- Trouble reading the 'toc' file?
	isofile->cdvdtype = cdvdtype;
	IsoInitTOC(isofile);

	if ((cdvdtype != CDVD_TYPE_PS2DVD) && (cdvdtype != CDVD_TYPE_DVDV))
	{
		retval = ActualFileRead(tochandle, sizeof(struct tocTN), (char *) & toctn);
		if (retval < sizeof(struct tocTN))
		{
			ActualFileClose(tochandle);
			tochandle = ACTUALHANDLENULL;
			return(-1);
		} // ENDIF- Trouble reading the 'toc' file?

		if ((toctn.strack > 99) || (toctn.etrack > 99))
		{
			ActualFileClose(tochandle);
			tochandle = ACTUALHANDLENULL;
			return(-1);
		} // ENDIF- Track numbers out of range?
#ifdef VERBOSE_FUNCTION_TOC
		PrintLog("CDVDiso TOC:   Start Track %u   End Track %u",
		         toctn.strack, toctn.etrack);
#endif /* VERBOSE_FUNCTION_TOC */
		IsoAddTNToTOC(isofile, toctn);
		retval = ActualFileRead(tochandle, sizeof(struct tocTD), (char *) & toctd);
		if (retval < sizeof(struct tocTD))
		{
			ActualFileClose(tochandle);
			tochandle = ACTUALHANDLENULL;
			return(-1);
		} // ENDIF- Trouble reading the 'toc' file?
		if (toctd.type != 0)
		{
			ActualFileClose(tochandle);
			tochandle = ACTUALHANDLENULL;
			return(-1);
		} // ENDIF- Track numbers out of range?
#ifdef VERBOSE_FUNCTION_TOC
		PrintLog("CDVDiso TOC:   Total Sectors: %lu", toctd.lsn);
#endif /* VERBOSE_FUNCTION_TOC */
		IsoAddTDToTOC(isofile, 0xAA, toctd);
		for (i = toctn.strack; i <= toctn.etrack; i++)
		{
			retval = ActualFileRead(tochandle, sizeof(struct tocTD), (char *) & toctd);
			if (retval < sizeof(struct tocTD))
			{
				ActualFileClose(tochandle);
				tochandle = ACTUALHANDLENULL;
				return(-1);
			} // ENDIF- Trouble reading the 'toc' file?
#ifdef VERBOSE_FUNCTION_TOC
			PrintLog("CDVDiso TOC:   Track %u  Type %u  Sector Start: %lu",
			         i, toctd.type, toctd.lsn);
#endif /* VERBOSE_FUNCTION_TOC */
			IsoAddTDToTOC(isofile, i, toctd);
		} // NEXT i- read in each track
	} // ENDIF- Not a DVD? (Then read in CD track data)
	ActualFileClose(tochandle);
	tochandle = ACTUALHANDLENULL;
	return(0);
} // END IsoLoadTOC()
Exemple #5
0
int DetectImageType(struct IsoFile *isofile) {

    char comparestr[] = "CD001";

    int newtype;

    off64_t targetpos;

    char teststr[2448];

    int dataoffset;

    int i;

    int retval;



    newtype = 0;

    if(isofile->compress > 0) {

        IsoFileSeek(isofile, 16);

        IsoFileRead(isofile, teststr);



        while(imagedata[newtype].name != NULL) {

            if((isofile->blocksize == imagedata[newtype].blocksize) &&

                    (isofile->imageheader == imagedata[newtype].fileoffset)) {

                dataoffset = imagedata[newtype].dataoffset + 1;

                i = 0;

                while((i < 5) && (teststr[dataoffset + i] == comparestr[i])) i++;

                if(i == 5) {

                    GetImageType(isofile, newtype);

                    return(newtype);

                } // ENDIF- Did we find a match?

            } // ENDIF- Do these pieces match the compression storage pieces?

            newtype++;

        } // ENDWHILE- looking for the image type that fits the stats



    } else {

        while(imagedata[newtype].name != NULL) {

            targetpos = (16 * imagedata[newtype].blocksize)

                        + imagedata[newtype].fileoffset

                        + imagedata[newtype].dataoffset

                        + 1; // Moves to start of string

            retval = ActualFileSeek(isofile->handle, targetpos);

            if(retval == 0) {

                retval = ActualFileRead(isofile->handle, 5, teststr);

                if(retval == 5) {

                    i = 0;

                    while((i < 5) && (teststr[i] == comparestr[i]))  i++;

                    if(i == 5) {

                        ActualFileSeek(isofile->handle, isofile->imageheader);

                        GetImageType(isofile, newtype);

                        return(newtype);

                    } // ENDIF- Did we find a match?

                } // ENDIF- Could we read in the test string? Cool! Test it.

            } // ENDIF- Could actually get to this point?

            newtype++;

        } // ENDWHILE- looking for the directory header string "CD001"

        ActualFileSeek(isofile->handle, isofile->imageheader);

    } // ENDIF- Do we match type to compression stats? (Or search against raw data?)



    GetImageType(isofile, REDBOOK2352);

    return(REDBOOK2352); // Couldn't find it? Guess it's RAW 2352, then. (Audio CD?)

} // END ImageDetect()