Example #1
0
int cdReadSectors(int lba, int num, void *dest, CdRMode *rmode) {
	int err;
	if (CdRead(lba, num, dest, rmode) == 1) {
		CdSync(0);
		err = CdGetError();
		return (err > 0) ? -err : err;
	}
	return -0xFF;
}
Example #2
0
void read_manage(void)
{
	int		ret;

	switch (read_stat) {
		case	0 :		/* not reading any data */
			break;
		case	1 :		/* command: set location */
			CdControlF(CdlSetloc, (u_char *)&fp[read_file_num].pos);
			read_stat++;
			break;
		case	2 :		/* waiting: setting location */
			if ((ret = CdSync(1, 0)) == CdlComplete) {
				read_stat++;
			}
			else if (ret == CdlDiskError) {
				read_stat = 1;
				errcnt++;
			}
			break;
		case	3 :		/* command: read data */
			if (CdRead(READ_SECTORS, read_des_addr, CdlModeSpeed) == 0) {
				errcnt++;
			}
			else {
				read_stat++;
			}
			break;
		case	4 :		/* waiting: reading data */
			read_remain_sector = CdReadSync(1, 0);
			if (read_remain_sector == 0) {
				read_stat++;
			}
			else if (read_remain_sector == -1) {
				read_stat = 1;
				errcnt++;
			}
			break;
		case	5 :		/* done */
			break;
		default :
			break;
	}
}
Example #3
0
int CDVD_GetVolumeDescriptor(void){
	// Read until we find the last valid Volume Descriptor
	int volDescSector;

	static struct cdVolDesc localVolDesc;

#ifdef DEBUG
	printf("CDVD_GetVolumeDescriptor called\n");
#endif

	for (volDescSector = 16; volDescSector<20; volDescSector++)
	{
		CdRead(volDescSector,1,&localVolDesc,&cdReadMode);
//		CdSync(0x00);

		// If this is still a volume Descriptor
		if (strncmp(localVolDesc.volID, "CD001", 5) == 0)
		{
			if ((localVolDesc.filesystemType == 1) ||
				(localVolDesc.filesystemType == 2))
			{
				memcpy(&CDVolDesc, &localVolDesc, sizeof(struct cdVolDesc));
			}
		}
		else
			break;
	}

#ifdef DEBUG
	if (CDVolDesc.filesystemType == 1)
		printf("CD FileSystem is ISO9660\n");
	else if (CDVolDesc.filesystemType == 2)
		printf("CD FileSystem is Joliet\n");
	else printf("Could not detect CD FileSystem type\n");
#endif
//	CdStop();

	return TRUE;
}
Example #4
0
// This function can be called repeatedly after CDVD_GetDir_RPC_request to get the actual entries
// buffer (tocEntry) must be 18KB in size, and this will be filled with a maximum of 128 entries in one go
int CDVD_GetDir_RPC_get_entries(struct TocEntry tocEntry[], int req_entries){
	static char toc[2048];
	int toc_entry_num;

	struct dirTocEntry* tocEntryPointer;

	if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
#ifdef RPC_LOG
		RPC_LOG("[RPC:cdvd]	Couldn't Read from CD !\n");
#endif
		return -1;
	}
	//CdSync(0x00);

	if (getDirTocData.current_entry == 0){
		// if this is the first read then make sure we point to the first real entry
		(char*)tocEntryPointer = toc;
		(char*)tocEntryPointer += tocEntryPointer->length;
		(char*)tocEntryPointer += tocEntryPointer->length;

		getDirTocData.current_sector_offset = (char*)tocEntryPointer - toc;
	}
	else{
		(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
	}

	if (req_entries > 128)
		req_entries = 128;

	for (toc_entry_num=0; toc_entry_num < req_entries;){
		if ((tocEntryPointer->length == 0) || (getDirTocData.current_sector_offset >= 2048)){
			// decrease the number of dirs remaining
			getDirTocData.num_sectors--;

			if (getDirTocData.num_sectors > 0){
				// If we've run out of entries, but arent on the last sector
				// then load another sector
				getDirTocData.current_sector++;

				if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
#ifdef RPC_LOG
					RPC_LOG("[RPC:cdvd]	Couldn't Read from CD !\n");
#endif
					return -1;
				}
				//CdSync(0x00);

				getDirTocData.current_sector_offset = 0;
				(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;

//				continue;
			}
			else{
				return (toc_entry_num);
			}
		}

		// This must be incremented even if the filename doesnt match extension list
		getDirTocData.current_entry++;

		// We've found a file in this directory
		// now check if it matches our extension list (if there is one)

		// Copy the entry regardless, as it makes the comparison easier
		// if it doesn't match then it will just be overwritten
		TocEntryCopy(&tocEntry[toc_entry_num], tocEntryPointer);

		if (tocEntry[toc_entry_num].fileProperties & 0x02){
			// If this is a subdir, then check if we want to include subdirs
			if (getDirTocData.inc_dirs)	{
				toc_entry_num++;
			}

			getDirTocData.current_sector_offset += tocEntryPointer->length;
			(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
		}
		else{
			if (strlen(getDirTocData.extension_list) > 0){
				if (TocEntryCompare(tocEntry[toc_entry_num].filename, getDirTocData.extension_list) == TRUE){
					// increment the number of matching entries counter
					toc_entry_num++;
				}

				getDirTocData.current_sector_offset += tocEntryPointer->length;
				(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;

			}
			else{
				toc_entry_num++;
				getDirTocData.current_sector_offset += tocEntryPointer->length;
				(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
			}
		}
/*
		if (strlen(getDirTocData.extension_list) > 0)
		{
			if (TocEntryCompare(tocEntry[toc_entry_num].filename, getDirTocData.extension_list) == TRUE)
			{

				// increment this here, rather than in the main for loop
				// since this should count the number of matching entries
				toc_entry_num++;
			}

			getDirTocData.current_sector_offset += tocEntryPointer->length;
			(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
		}
		else
		{
			toc_entry_num++;
			getDirTocData.current_sector_offset += tocEntryPointer->length;
			(char*)tocEntryPointer = toc + getDirTocData.current_sector_offset;
		}
*/
	}
	return (toc_entry_num);
}
Example #5
0
// This is the RPC-ready function which takes the request to start the tocEntry retrieval
int CDVD_GetDir_RPC_request(char* pathname, char* extensions, unsigned int inc_dirs){
//	int dir_depth = 1;
	static char toc[2048];
	char* dirname;
	int found_dir;
	int num_dir_sectors;
	unsigned int toc_entry_num;
	struct dirTocEntry* tocEntryPointer;
	static struct TocEntry localTocEntry;
	int current_sector;

	// store the extension list statically for the retrieve function
	strncpy(getDirTocData.extension_list, extensions, 128);
	getDirTocData.extension_list[128]=0;

	getDirTocData.inc_dirs = inc_dirs;

	// Find the TOC for a specific directory
	if (CDVD_GetVolumeDescriptor() != TRUE){
#ifdef RPC_LOG
		RPC_LOG("[RPC:cdvd] Could not get CD Volume Descriptor\n");
#endif
		return -1;
	}

#ifdef RPC_LOG
	RPC_LOG("[RPC:cdvd] Getting Directory Listing for: \"%s\"\n", pathname);
#endif

	// Read the TOC of the root directory
	if (CdRead(CDVolDesc.rootToc.tocLBA,1,toc,&cdReadMode) != TRUE){
#ifdef RPC_LOG
	RPC_LOG("[RPC:    ] Couldn't Read from CD !\n");
#endif
		return -1;
	}
	//CdSync(0x00);

	// point the tocEntryPointer at the first real toc entry
	(char*)tocEntryPointer = toc;

	num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11;
	current_sector = tocEntryPointer->fileLBA;

	(char*)tocEntryPointer += tocEntryPointer->length;
	(char*)tocEntryPointer += tocEntryPointer->length;

	// use strtok to get the next dir name

	// if there isnt one, then assume we want the LBA
	// for the current one, and exit the while loop

	// if there is another dir name then increment dir_depth
	// and look through dir table entries until we find the right name
	// if we dont find the right name
	// before finding an entry at a higher level (lower num), then return nothing

	localTocEntry.fileLBA = CDVolDesc.rootToc.tocLBA;

	// while (there are more dir names in the path)
	dirname = strtok( pathname, "\\/" );
	while( dirname != NULL ){
		found_dir = FALSE;

		while(1){
			if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048))	{
				num_dir_sectors--;

				if (num_dir_sectors > 0){
					// If we've run out of entries, but arent on the last sector
					// then load another sector

					current_sector++;
					if (CdRead(current_sector,1,toc,&cdReadMode) != TRUE){
#ifdef RPC_LOG
						RPC_LOG("[RPC:    ] Couldn't Read from CD !\n");
#endif
						return -1;
					}
					//CdSync(0x00);

					(char*)tocEntryPointer = toc;
				}
				else{
					// Couldnt find the directory, and got to end of directory
					return -1;
				}
			}

			if (tocEntryPointer->fileProperties & 0x02){
				TocEntryCopy(&localTocEntry, tocEntryPointer);

				// If this TOC Entry is a directory,
				// then see if it has the right name
				if (strcmp(dirname,localTocEntry.filename) == 0){
					// if the name matches then we've found the directory
					found_dir = TRUE;
#ifdef RPC_LOG
					RPC_LOG("[RPC:    ] Found directory %s in subdir at sector %d\n",dirname,current_sector);
					RPC_LOG("[RPC:    ] LBA of found subdirectory = %d\n",localTocEntry.fileLBA);
#endif
					break;
				}
			}

			// point to the next entry
			(char*)tocEntryPointer += tocEntryPointer->length;
		}

		// If we havent found the directory name we wanted then fail
		if (found_dir != TRUE)
			return -1;

		// Get next directory name
		dirname = strtok( NULL, "\\/" );

		// Read the TOC of the found subdirectory
		if (CdRead(localTocEntry.fileLBA,1,toc,&cdReadMode) != TRUE){
#ifdef RPC_LOG
			RPC_LOG("[RPC:    ] Couldn't Read from CD !\n");
#endif
			return -1;
		}
		//CdSync(0x00);

		num_dir_sectors = (localTocEntry.fileSize+2047) >> 11;
		current_sector = localTocEntry.fileLBA;

		// and point the tocEntryPointer at the first real toc entry
		(char*)tocEntryPointer = toc;
		(char*)tocEntryPointer += tocEntryPointer->length;
		(char*)tocEntryPointer += tocEntryPointer->length;
	}

	// We know how much data we need to read in from the DirTocHeader
	// but we need to read in at least 1 sector before we can get this value

	// Now we need to COUNT the number of entries (dont do anything with info at this point)
	// so set the tocEntryPointer to point to the first actual file entry

	// This is a bit of a waste of reads since we're not actually copying the data out yet,
	// but we dont know how big this TOC might be, so we cant allocate a specific size

	(char*)tocEntryPointer = toc;

	// Need to STORE the start LBA and number of Sectors, for use by the retrieve func.
	getDirTocData.start_LBA = localTocEntry.fileLBA;
	getDirTocData.num_sectors = (tocEntryPointer->fileSize+2047) >> 11;
	getDirTocData.num_entries = 0;
	getDirTocData.current_entry = 0;
	getDirTocData.current_sector = getDirTocData.start_LBA;
	getDirTocData.current_sector_offset = 0;

	num_dir_sectors = getDirTocData.num_sectors;

	(char*)tocEntryPointer = toc;
	(char*)tocEntryPointer += tocEntryPointer->length;
	(char*)tocEntryPointer += tocEntryPointer->length;

	toc_entry_num=0;

	while(1){
		if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048)){
			// decrease the number of dirs remaining
			num_dir_sectors--;

			if (num_dir_sectors > 0){
				// If we've run out of entries, but arent on the last sector
				// then load another sector
				getDirTocData.current_sector++;

				if (CdRead(getDirTocData.current_sector,1,toc,&cdReadMode) != TRUE){
#ifdef RPC_LOG
			RPC_LOG("[RPC:    ] Couldn't Read from CD !\n");
#endif
					return -1;
				}
				//CdSync(0x00);

				(char*)tocEntryPointer = toc;

//				continue;
			}
			else{
				getDirTocData.num_entries = toc_entry_num;
				getDirTocData.current_sector = getDirTocData.start_LBA;
				return (toc_entry_num);
			}
		}

		// We've found a file/dir in this directory
		// now check if it matches our extension list (if there is one)
		TocEntryCopy(&localTocEntry, tocEntryPointer);

		if (localTocEntry.fileProperties & 0x02){
			// If this is a subdir, then check if we want to include subdirs
			if (getDirTocData.inc_dirs){
				toc_entry_num++;
			}
		}
		else{
			if (strlen(getDirTocData.extension_list) > 0){
				if (TocEntryCompare(localTocEntry.filename, getDirTocData.extension_list) == TRUE){
					// increment the number of matching entries counter
					toc_entry_num++;
				}
			}
			else{
				toc_entry_num++;
			}
		}

		(char*)tocEntryPointer += tocEntryPointer->length;

	}


	// THIS SHOULD BE UNREACHABLE -
	// since we are trying to count ALL matching entries, rather than upto a limit


	// STORE total number of TOC entries
	getDirTocData.num_entries = toc_entry_num;
	getDirTocData.current_sector = getDirTocData.start_LBA;


	// we've reached the toc entry limit, so return how many we've done
	return (toc_entry_num);

}
Example #6
0
int CDVD_findfile(char* fname, struct TocEntry* tocEntry){
	static char filename[128+1];
	static char pathname[1024+1];
	static char toc[2048];
	char* dirname;


	static struct TocEntry localTocEntry;	// used for internal checking only

	int found_dir;

	int num_dir_sectors;
	int current_sector;

	int dir_lba;

	struct dirTocEntry* tocEntryPointer;

#ifdef DEBUG
	printf("CDVD_findfile called\n");
#endif

	//make sure we have good cdReadMode
	cdReadMode.trycount = 0;
	cdReadMode.spindlctrl = CdSpinStm;
	cdReadMode.datapattern = CdSecS2048;

	_splitpath2(fname, pathname, filename);

	// Find the TOC for a specific directory
	if (CDVD_GetVolumeDescriptor() != TRUE){
#ifdef RPC_LOG
		RPC_LOG("Could not get CD Volume Descriptor\n");
#endif
		return -1;
	}

	// Read the TOC of the root directory
	if (CdRead(CDVolDesc.rootToc.tocLBA,1,toc,&cdReadMode) != TRUE){
#ifdef RPC_LOG
		RPC_LOG("Couldn't Read from CD !\n");
#endif
		return -1;
	}
	//CdSync(0x00);

	// point the tocEntryPointer at the first real toc entry
	(char*)tocEntryPointer = toc;

	num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11;	//round up fix
	current_sector = tocEntryPointer->fileLBA;

	(char*)tocEntryPointer += tocEntryPointer->length;
	(char*)tocEntryPointer += tocEntryPointer->length;


	localTocEntry.fileLBA = CDVolDesc.rootToc.tocLBA;
	// while (there are more dir names in the path)
	dirname = strtok( pathname, "\\/" );

	while( dirname != NULL )
	{
		found_dir = FALSE;
/*
		while(tocEntryPointer->length > 0)
		{
			// while there are still more directory entries then search through
			// for the one we want

			if (tocEntryPointer->fileProperties & 0x02)
			{
				// Copy the CD format TOC Entry to our format
				TocEntryCopy(&localTocEntry, tocEntryPointer);

				// If this TOC Entry is a directory,
				// then see if it has the right name
				if (strcasecmp(dirname,localTocEntry.filename) == 0)
				{
					// if the name matches then we've found the directory
					found_dir = TRUE;
					break;
				}
			}

			// point to the next entry
			(char*)tocEntryPointer += tocEntryPointer->length;
		}
*/
		while(1)
		{
			if ((tocEntryPointer->length == 0) || (((char*)tocEntryPointer-toc)>=2048))
			{
				num_dir_sectors--;

				if (num_dir_sectors > 0)
				{
					// If we've run out of entries, but arent on the last sector
					// then load another sector

					current_sector++;
					if (CdRead(current_sector,1,toc,&cdReadMode) != TRUE)
					{
						return -1;
					}
//					CdSync(0x00);

					(char*)tocEntryPointer = toc;
				}
				else
				{
					// Couldnt find the directory, and got to end of directory
					return -1;
				}
			}


			if (tocEntryPointer->fileProperties & 0x02)
			{
				TocEntryCopy(&localTocEntry, tocEntryPointer);

				// If this TOC Entry is a directory,
				// then see if it has the right name
				if (strcmp(dirname,localTocEntry.filename) == 0)
				{
					// if the name matches then we've found the directory
					found_dir = TRUE;
					break;
				}
			}

			// point to the next entry
			(char*)tocEntryPointer += tocEntryPointer->length;
		}

		// If we havent found the directory name we wanted then fail
		if (found_dir != TRUE)
		{
			return -1;
		}

		// Get next directory name
		dirname = strtok( NULL, "\\/" );

		// Read the TOC of the found subdirectory
		if (CdRead(localTocEntry.fileLBA,1,toc,&cdReadMode) != TRUE)
		{
			return -1;
		}
//		CdSync(0x00);

		num_dir_sectors = (localTocEntry.fileSize+2047) >> 11;	//round up fix
		current_sector = localTocEntry.fileLBA;

		// and point the tocEntryPointer at the first real toc entry
		(char*)tocEntryPointer = toc;
		(char*)tocEntryPointer += tocEntryPointer->length;
		(char*)tocEntryPointer += tocEntryPointer->length;
	}

	(char*)tocEntryPointer = toc;

	num_dir_sectors = (tocEntryPointer->fileSize+2047) >> 11;	//round up fix
	dir_lba = tocEntryPointer->fileLBA;

	(char*)tocEntryPointer = toc;
	(char*)tocEntryPointer += tocEntryPointer->length;
	(char*)tocEntryPointer += tocEntryPointer->length;

	while (num_dir_sectors > 0)
	{
		while(tocEntryPointer->length != 0)
		{
			// Copy the CD format TOC Entry to our format
			TocEntryCopy(&localTocEntry, tocEntryPointer);

			if ((strnicmp(localTocEntry.filename, filename, strlen(filename)) == 0) ||
				((filename[strlen(filename)-2] == ';') &&
				 (localTocEntry.filename[strlen(localTocEntry.filename)-2] == ';') &&
				 (strnicmp(localTocEntry.filename, filename, strlen(filename)-2) == 0)))
			{
				// if the filename matches then copy the toc Entry
				tocEntry->fileLBA = localTocEntry.fileLBA;
				tocEntry->fileProperties = localTocEntry.fileProperties;
				tocEntry->fileSize = localTocEntry.fileSize;

				strcpy(tocEntry->filename, localTocEntry.filename);
				memcpy(tocEntry->date, localTocEntry.date, 7);

#ifdef DEBUG
				printf("CDVD_findfile: found file\n");
#endif

				return TRUE;
			}

			(char*)tocEntryPointer += tocEntryPointer->length;
		}

		num_dir_sectors--;

		if (num_dir_sectors > 0)
		{
			dir_lba++;

			if (CdRead(dir_lba,1,toc,&cdReadMode) != TRUE){
				return -1;
			}
//			CdSync(0x00);

			(char*)tocEntryPointer = toc;
		}
	}

	return FALSE;
}