Beispiel #1
0
int copyRTEELF(void *arg)
{
	DiskType type;
	int rv;

	setEnableDisc(-1);

	if (isDVDVSupported()) {
		type = CDDA_DiskType();
	
		/* Detect disk type, so loading will work. */
		if (type == DiskType_DVDV) {
			CDVD_SetDVDV(1);
		} else {
			CDVD_SetDVDV(0);
		}
	}

	rv = real_copyRTEELF(arg);

	if (isDVDVSupported()) {
		/* Always stop CD/DVD when an error happened. */
		CDVD_Stop();
		CDVD_FlushCache();
	}

	setEnableDisc(0);

	if (getErrorMessage() == NULL) {
		graphic_setPercentage(0, NULL);
	}

	return 0;
}
Beispiel #2
0
void list_path(char *path, list_t *list)
{
	int fd;
	int n = 0;

	iox_dirent_t buf;

	if(!strncmp(path,"cdfs:",5))
	{
		CDVD_FlushCache();
	}

	// Add fake .. directory entry
	add_reg_entry(list->entries, "..", n++);

	// Try to open the path
	if((fd=fileXioDopen(path)) < 0)
	{
		list->num = n;
		return;
	}
	else
	{

		// Add directories first
		while(fileXioDread(fd, &buf) > 0)
		{

			if(buf.stat.mode & FIO_S_IFDIR && (!strcmp(buf.name,".") || !strcmp(buf.name,"..")))
				continue;

			if(buf.stat.mode & FIO_S_IFDIR)
			{
				add_dir_entry(list->entries, buf.name, n++);
			}

			if (buf.stat.mode & FIO_S_IFREG)
			{
				add_reg_entry(list->entries, buf.name, n++);
			}

			// Prevent overflowing the list
			if (n >= list->size)
			{
				break;
			}

		}

		list->num = n;

		fileXioDclose(fd);

	}

}
Beispiel #3
0
FHANDLE FileOpen( const char *filename, int mode )
{
	FHANDLE handle;
	int		c;
	char	*ptr;

	memset( &handle, -1, sizeof(handle) );

	if(!filename)
		return handle;

	if( (ptr = strchr( filename, ':' )) == NULL ) {
#ifdef _DEBUG
		printf("FileOpen : Invalid Path (ptr = NULL)\n");
#endif
		return handle;
	}

	c = ptr - filename;

	// file is on cd/dvd
	if( !strncmp( filename, "cdfs:", c ) ) {
		CD_Init();
		CDVD_FlushCache();

		handle.fh = fioOpen( filename, mode );
		handle.dt = DT_CD;
	}
	else if( !strncmp( filename, "pfs", 3 ) ) {
		handle.fh = fileXioOpen( filename, mode, 0 );
		handle.dt = DT_HDD;
	}
	else if( !strncmp( filename, "mc0:", c ) || !strncmp( filename, "mc1:", c ) ) {
		handle.fh = fioOpen( filename, mode );
		handle.dt = DT_MC;
	}
	else if( !strncmp( filename, "mass:", c ) ) {
		handle.fh = fioOpen( filename, mode );
		handle.dt = DT_USB;
	}
	else if( !strncmp( filename, "host:", c ) ) {
		handle.fh = fioOpen( filename, mode );
		handle.dt = DT_HOST;
	}
	else if( !strncmp( filename, "smb:", c ) ) {
		handle.fh = smbc_open( filename, mode, 0666 );
		handle.dt = DT_SMB_SHARE;
	}

	return handle;
}
Beispiel #4
0
/****************************************************************************
 * Universal file opening function.  Returns the handle to the file.		*
 ****************************************************************************/
int OpenFile(char *filename, int mode, int media)
{
	int fd = 0;
	switch (media)
	{
	case 0:  //hdd
		{
			fd = fileXioOpen(filename, mode, 0);
			break;
		}
	case 1:  //cdfs
		{
			CDVD_FlushCache();
			fd = fioOpen(filename, mode);
			break;
		}
	case 2:
		{
			//fd = fioOpen(filename, mode);
			fd = fileXioOpen(filename, mode, 0);
			break;
		}
	case 3:
		{
			fd = fileXioOpen(filename, mode, 0);
			break;	
		}
	case 4:
		{
			fd = fioOpen(filename, mode);
			break;	
		}
	case 5:
		{
			fd = fileXioOpen(filename, mode, 0);
			break;	
		}
	}
	return fd;
}
Beispiel #5
0
void list_mountable_devices(char *device, list_t *list)
{

	int i,n = 0;

	iox_stat_t stat;

	char mc_path[6] = "mc0:";
	char mass_device[8] = "mass0:";

	add_reg_entry(list->entries,"..",n++);

	if (!strcmp(device,"mc"))
	{
		for (i = 0; i < 2; i++)
		{
			mc_path[2] = '0' + i;
			if(!fileXioGetStat(mc_path,&stat))
			{
				add_dir_entry(list->entries,mc_path,n++);
			}
		}

		list->num = n;

	}

	if (!strcmp(device,"mass"))
	{
		for(i=0; i < 10; i++)
		{

			mass_device[4] = '0'+i;

			if(!(fileXioGetStat(mass_device, &stat) < 0))
			{
				add_dir_entry(list->entries,mass_device,n++);
			}
		}

	// Older versions of the module only support "mass:"
		if (!n)
		{
			if (!(fileXioGetStat("mass:",&stat) < 0))
			{
				add_dir_entry(list->entries,"mass:",n++);
			}

		}

		list->num = n;

	}

	if (!strcmp(device,"hdd"))
	{

		// Checking for "hdd0:" doesn't work, maybe since it's a block device
		//if (!(fileXioGetStat("hdd0:",&stat) < 0))
		{
			list_partitions(list);
		}
	}

	if (!strcmp(device,"cdfs"))
	{
		//if(!(fileXioGetStat("cdfs:",&stat) < 0))
		{
			add_dir_entry(list->entries,"cdfs:", n++);
		}

		CDVD_FlushCache();
		refresh_cdfs();

		list->num = n;

	}
	else
	{
		CDVD_Stop();
	}

}
Beispiel #6
0
int DirGetContents( const char *path, const char *filter, fileInfo_t *fileInfo, int maxItems )
{
	int		c, i;
	char	*ptr;
	int		numRead;
	int		index	= 0;

	if( !path || !fileInfo || !maxItems )
		return -1;

	if( (ptr = strchr( path, '/' )) == NULL ) {
		printf("DirGetContents : Invalid Path (ptr = NULL)\n");
		return -1;
	}

	c = ptr - path;

	// try to read in dir from cd/dvd
	if( !strncmp( path, "cdfs:/", c ) ) 
	{
		// just make sure we are initialized
		CD_Init();

		struct TocEntry *tocEntries = (struct TocEntry*) malloc( sizeof(struct TocEntry) * maxItems );
		
		if( !tocEntries )
			return -1;

		CDVD_FlushCache();
		numRead = CDVD_GetDir( ptr, NULL, CDVD_GET_FILES_AND_DIRS, tocEntries, maxItems, NULL );
		CDVD_Stop();

		index	= 0;
		ptr		= NULL;

		if( filter )
			ptr = (char*) malloc( strlen(filter) + 1 );

		for( i = 0; i < numRead; i++ )
		{
			if( index >= maxItems )
				break;

			if( !strcmp( tocEntries[i].filename, ".." ) || !strcmp( tocEntries[i].filename, "." ) )
				continue;

			// check for filters
			c = 1;

			if( filter && !(tocEntries[i].fileProperties & FLAG_DIRECTORY) ) 
			{
				strcpy( ptr, filter );

				c = 0;
				char *token = strtok( ptr, " " );

				while( token ) {
					// found matching extension
					if( CmpFileExtension( tocEntries[i].filename, token ) ) {
						c = 1;
						break;
					}

					token = strtok( NULL, " " );
				}
			}

			if( c == 1 )
			{
				strncpy( fileInfo[index].name, tocEntries[i].filename, sizeof(fileInfo[index].name) );

				fileInfo[index].size	= tocEntries[i].fileSize;
				fileInfo[index].flags	= tocEntries[i].fileProperties;

				index++;
			}
		}

		if( ptr )
			free(ptr);

		free(tocEntries);
	}
	else if( !strncmp( path, "pfs", 3 ) )
	{
		// try to read in dir from hdd
		int hDir = fileXioDopen( path );
		int nRet;
		iox_dirent_t dirEntry;

		if( hDir < 0 )
			return -1;

		index	= 0;
		ptr		= NULL;

		if( filter )
			ptr = (char*) malloc( strlen(filter) + 1 );

		do {
			if( !(nRet = fileXioDread( hDir, &dirEntry )) )
				break;

			if(!strcmp( dirEntry.name, "." ) || !strcmp( dirEntry.name, ".."))
				continue;

			if( index >= maxItems )
				break;

			if( FIO_S_ISDIR(dirEntry.stat.mode) )
				fileInfo[index].flags = FLAG_DIRECTORY;
			else
				fileInfo[index].flags = 0;

			// check for filters
			c = 1;

			if( filter && !(fileInfo[index].flags & FLAG_DIRECTORY) )
			{
				strcpy( ptr, filter );

				c = 0;
				char *token = strtok( ptr, " " );

				while( token ) {
					// found matching extension
					if( CmpFileExtension( dirEntry.name, token ) ) {
						c = 1;
						break;
					}

					token = strtok( NULL, " " );
				}
			}
			
			if( c == 1 )
			{
				strncpy( fileInfo[index].name, dirEntry.name, sizeof(fileInfo[index].name) );
				fileInfo[index].size = dirEntry.stat.size;

				index++;
			}

		} while( nRet > 0 );

		if( ptr )
			free(ptr);

		fileXioDclose( hDir );
	}
	else if( !strncmp( path, "mc0:/", c ) || !strncmp( path, "mc1:/", c ) )
	{
		// try to read in dir from memory card
		int		nPort;
		char	mcPath[256];
		mcTable mcEntries[MAX_DIR_FILES] __attribute__((aligned(64)));

		if( !strncmp( path, "mc0:/", c ) )
			nPort = 0;
		else
			nPort = 1;

		strcpy( mcPath, ptr );
		strcat( mcPath, "*" );

		mcGetDir( nPort, 0, mcPath, 0, MAX_DIR_FILES, mcEntries );
		mcSync( 0, NULL, &numRead );

		index	= 0;
		ptr		= NULL;

		if( filter )
			ptr = (char*) malloc( strlen(filter) + 1 );

		for( i = 0; i < numRead; i++ )
		{
			if( index >= maxItems )
				break;

			if( !strcmp( mcEntries[i].name, "." ) || !strcmp( mcEntries[i].name, "..") )
				continue;

			if( mcEntries[i].attrFile & MC_ATTR_SUBDIR )
				fileInfo[index].flags = FLAG_DIRECTORY;
			else
				fileInfo[index].flags = 0;

			// check for filters
			c = 1;

			if( filter && !(mcEntries[i].attrFile & MC_ATTR_SUBDIR) )
			{
				strcpy( ptr, filter );

				c = 0;
				char *token = strtok( ptr, " " );

				while( token ) {
					// found matching extension
					if( CmpFileExtension( mcEntries[i].name, token ) ) {
						c = 1;
						break;
					}

					token = strtok( NULL, " " );
				}
			}

			if( c == 1 )
			{
				strncpy( fileInfo[index].name, mcEntries[i].name, sizeof(fileInfo[index].name) );

				fileInfo[index].size	= mcEntries[i].fileSizeByte;

				index++;
			}
		}

		if( ptr )
			free(ptr);
	}
	else if( !strncmp( path, "mass:/", c ) ) 
	{
		// try to read in dir from USB device
		int nRet;
		fat_dir_record dirEntry;

		// returns number of entries in directory
		nRet = usb_mass_getFirstDirentry( ptr, &dirEntry );

		index	= 0;
		ptr		= NULL;

		if( filter )
			ptr = (char*) malloc( strlen(filter) + 1 );

		// loop through all entries in directory
		while( nRet > 0 ) {

			if(!strcmp( dirEntry.name, "." ) || !strcmp( dirEntry.name, "..")) {
				nRet = usb_mass_getNextDirentry(&dirEntry);
				continue;
			}

			// ignore volume label
			if( dirEntry.attr & USB_VOLUME ) {
				nRet = usb_mass_getNextDirentry(&dirEntry);
				continue;
			}

			if( index >= maxItems )
				break;

			if( dirEntry.attr & USB_DIRECTORY )
				fileInfo[index].flags = FLAG_DIRECTORY;
			else
				fileInfo[index].flags = 0;

			// check for filters
			c = 1;

			if( filter && !(fileInfo[index].flags & FLAG_DIRECTORY) )
			{
				strcpy( ptr, filter );

				c = 0;
				char *token = strtok( ptr, " " );

				while( token ) {
					// found matching extension
					if( CmpFileExtension( dirEntry.name, token ) ) {
						c = 1;
						break;
					}

					token = strtok( NULL, " " );
				}
			}
			
			if( c == 1 )
			{
				strncpy( fileInfo[index].name, dirEntry.name, sizeof(fileInfo[index].name) );
				fileInfo[index].size = dirEntry.size;

				index++;
			}

			nRet = usb_mass_getNextDirentry( &dirEntry );
		}

		if( ptr )
			free(ptr);
	}
	else if( !strncmp( path, "smb", 3 ) )
	{
		// read from a samba share
		int hDir = smbc_opendir( path );
		const struct smbc_dirent *dirEntry;

		if( hDir < 0 )
			return -1;

		index	= 0;
		ptr		= NULL;

		if( filter )
			ptr = (char*) malloc( strlen(filter) + 1 );

		while( (dirEntry = smbc_readdir( hDir )) != NULL )
		{
			if(!strcmp( dirEntry->name, "." ) || !strcmp( dirEntry->name, ".."))
				continue;

			if( index >= maxItems )
				break;

			if( dirEntry->smbc_type == SMBC_DIR )
				fileInfo[index].flags = FLAG_DIRECTORY;
			else
				fileInfo[index].flags = 0;

			// check for filters
			c = 1;

			if( filter && !(fileInfo[index].flags & FLAG_DIRECTORY) )
			{
				strcpy( ptr, filter );

				c = 0;
				char *token = strtok( ptr, " " );

				while( token ) {
					// found matching extension
					if( CmpFileExtension( dirEntry->name, token ) ) {
						c = 1;
						break;
					}

					token = strtok( NULL, " " );
				}
			}
			
			if( c == 1 )
			{
				strncpy( fileInfo[index].name, dirEntry->name, sizeof(fileInfo[index].name) );
				fileInfo[index].size = 0; // fixme

				index++;
			}

		};

		if( ptr )
			free(ptr);

		smbc_closedir( hDir );
	}

	return index;
}
Beispiel #7
0
int loadLoaderModules(int debug_mode, int disable_cdrom)
{
	static int load_dvd_config = -1;
	static int load_netsurf_config = -1;
	static int load_usb_config = -1;
	int i;
	int rv;
	int lrv = -1;

	if (debug_mode == 1) {
		/* Network is used by ps2link and can't be used by Linux. */
		network_support = 0;
	}

#ifdef RESET_IOP
	if (debug_mode == -1) {
		graphic_setStatusMessage("Flushing cache");
		FlushCache(0);
		graphic_setStatusMessage("Exit IOP Heap");
		SifExitIopHeap();
		graphic_setStatusMessage("Exit LoadFile");
		SifLoadFileExit();
		graphic_setStatusMessage("Exit FIO");
		fioExit();
		graphic_setStatusMessage("Exit RPC");
		SifExitRpc();
		graphic_setStatusMessage("Stop DMA");
		SifStopDma();
		graphic_setStatusMessage("PreReset Init RPC");
		SifInitRpc(0);
		graphic_setStatusMessage("Reseting IOP");
		while(!SifIopReset(s_pUDNL, 0));

		graphic_setStatusMessage("IOP Sync");
		while (!SifIopSync());

		graphic_setStatusMessage("Initialize RPC");
		SifInitRpc(0);
	}
#endif

	graphic_setStatusMessage("Patching enable LMB");
	sbv_patch_enable_lmb();
	graphic_setStatusMessage("Patching disable prefix check");
	sbv_patch_disable_prefix_check();

	/* CDVDMAN is loaded by IopReset and NVRAM can be read. */
	graphic_setStatusMessage("Read NVRAM from CDVD");

	if (!disable_cdrom) {
		nvram_init();
	}

	eromdrvSupport = 0;

	/* FIXME: eedebug handler seems to crash the ee
	graphic_setStatusMessage("Add eedebug handler");
	addEEDebugHandler();
	*/

	graphic_setStatusMessage("Loading modules");
	for (i = 0; i < moduleLoaderNumberOfModules; i++) {
		const rom_entry_t *romfile;

		if (moduleList[i].debug_mode != 0) {
			if (moduleList[i].debug_mode != debug_mode) {
				continue;
			}
		}

		/* Load configuration when necessary modules are loaded. */
		if (moduleList[i].loadCfg) {
			checkForMusicSupport();

			setDefaultConfiguration(NULL);

			lrv = loadConfiguration(CONFIG_FILE);

			changeMode();

			/* Load configuration on startup and not on IOP reset. */
			moduleList[i].loadCfg = 0;
		}
		graphic_setStatusMessage(moduleList[i].path);
		kprintf("Loading module (%s)\n", moduleList[i].path);

		if (!network_support) {
			if (moduleList[i].network) {
				continue;
			}
		}

		if (moduleList[i].ps2smap) {
			moduleList[i].args = getPS2MAPParameter(&moduleList[i].argLen);
		}
		if (moduleList[i].dns) {
			moduleList[i].args = getPS2DNS(&moduleList[i].argLen);
		}
		if (moduleList[i].checkMc) {
			static char file[256];

			/* Try to load module from MC if available. */
			snprintf(file, sizeof(file), CONFIG_DIR "/%s", moduleList[i].path);
			rv = SifLoadModule(file, moduleList[i].argLen, moduleList[i].args);
		} else {
			rv = -1;
		}
		if (rv < 0) {
			if ((moduleList[i].sms_mod == 0) || (isDVDVSupported())) {
				if (moduleList[i].eromdrv < 0) {
					/* Try to detect EROM driver only the first time. */
					moduleList[i].eromdrv = 1;
					if (disable_cdrom) {
						continue;
					}

					rv = open("rom1:EROMDRV", O_RDONLY);
					if (rv >=0 ) {
						eromdrvpath[12] = 0;

						/* This is an old fat PS2 (working with SCPH-50004 and SCPH-39004). */
						close(rv);
					} else {
						const u8 *nvm;

						nvm = get_nvram();
						if (nvm_errors == 0) {
							/* NVM layout seems to be correct. */
							eromdrvpath[12] = nvm[NVM_REAL_REGION];
							rv = open(eromdrvpath, O_RDONLY);
							if (rv >=0 ) {
								/* Region code seems to be correct. */
								close(rv);
							} else {
								error_printf("The region code stored in the NVRAM S%02x T%02x F%02x R%02x "
									"can't be detected by version string %s (%s).",
									nvm[0x180],
									nvm[0x181],
									nvm[NVM_FAKE_REGION],
									nvm[NVM_REAL_REGION],
									ps2_rom_version);
								continue;
							}
						} else {
							error_printf("%d errors when reading NVRAM. Please set path "
								"to EROMDRV and reload modules.", nvm_errors);
							continue;
						}
					}
				}
				if (moduleList[i].eromdrv != 0) {
					moduleList[i].args = get_eromdrvpath();
					moduleList[i].argLen = strlen(moduleList[i].args) + 1;
				}
				romfile = rom_getFile(moduleList[i].path);
				if (romfile != NULL) {
					int ret;

					ret = SifExecModuleBuffer((void *) romfile->start, romfile->size, moduleList[i].argLen, moduleList[i].args, &rv);
					if (ret < 0) {
						rv = ret;
					}
				} else {
					rv = SifLoadModule(moduleList[i].path, moduleList[i].argLen, moduleList[i].args);
				}
				if (rv < 0) {
					if (moduleList[i].eromdrv != 0) {
						kprintf("Failed to load module \"%s\".\n", get_eromdrvpath());
					} else {
						kprintf("Failed to load module \"%s\".\n", moduleList[i].path);
					}
					if (moduleList[i].ps2smap && !isSlimPSTwo()) {
						network_support = 0;
					} else {
						if (moduleList[i].eromdrv != 0) {
							error_printf("Failed to load module \"%s\".", get_eromdrvpath());
						} else {
							error_printf("Failed to load module \"%s\".", moduleList[i].path);
						}
					}
				} else {
					if (moduleList[i].eromdrv != 0) {
						eromdrvSupport = -1;
					}
				}
			}
		}
	}
	graphic_setStatusMessage(NULL);
	printAllModules();

	fileXioInit();

	if (load_netsurf_config) {
		load_netsurf_config = 0;

		if (lrv != 0) {
			graphic_setStatusMessage("Check for NetSurf config");

			lrv = loadConfiguration(PS2NS_CONFIG_FILE);

			graphic_setStatusMessage(NULL);
		}
	}

	if (load_usb_config) {
		load_usb_config = 0;

		if (lrv != 0) {
			graphic_setStatusMessage("Check for USB config");

			lrv = loadConfiguration(USB_CONFIG_FILE);

			graphic_setStatusMessage(NULL);
		}
	}

	if (load_dvd_config && isDVDVSupported()) {
		load_dvd_config = 0;

		graphic_setStatusMessage("Init DVD driver");

		CDDA_Init();
		CDVD_Init();

		if (lrv != 0) {
			DiskType type;

			graphic_setStatusMessage("Load config from DVD");

			type = CDDA_DiskType();

			if (type == DiskType_DVDV) {
				CDVD_SetDVDV(1);
			} else {
				CDVD_SetDVDV(0);
			}

			kprintf("kloader disc type %u\n", type);
			switch (type) {
			case DiskType_CD:
			case DiskType_DVD:
			case DiskType_DVDV:
				/* Load configuration from disc. */
				lrv = loadConfiguration(DVD_CONFIG_FILE);

				changeMode();
#if 0
				if (lrv != 0) {
					error_printf("Failed to load config from \"%s\", using default configuration.", DVD_CONFIG_FILE);
				}
#endif
				break;
			default:
				kprintf("kloader unsupported disc type %u\n", type);
				break;
			}

			/* Stop CD when finished. */
			CDVD_Stop();
			CDVD_FlushCache();
		}
		graphic_setStatusMessage(NULL);
	}

	snprintf(hardware_information, sizeof(hardware_information),
		"%s with DVD-R %s, %s sound support and %s network adapter",
		isSlimPSTwo() ? "slim PSTwo" : "fat PS2",
		disable_cdrom ? "disabled" : (isDVDVSupported() ? "support" : "problem"),
		(libsd_version <= 0x104) ? "direct" : "indirect",
		network_support ? "with" : "without");

	return 0;
}