Beispiel #1
0
int FileRemove( const char *file )
{
	char *ptr;
	int c;

	if( (ptr = strchr( file, ':' )) == NULL ) {
#ifdef _DEBUG
		printf("FileRemove : Invalid Path (ptr = NULL)\n");
#endif
		return -1;
	}

	c = ptr - file;

	if( !strncmp( file, "pfs", 3 ) ) {
		return fileXioRemove( file );
	}
	else if( !strncmp( file, "mc0:", c ) || !strncmp( file, "mc1:", c ) ) {
		// there's a bug in the fio stuff that creates a new directory
		// whenever a file is removed with fioRemove.
		c = fioRemove( file );
		fioRmdir( file );

		return c;
	}
	else if( !strncmp( file, "mass:", c ) ) {
		char strDir[256];

		c = fioRemove( file );

		// you MUST call fioRmdir with device number for USB device.
		strcpy( strDir, "mass0" );
		strcat( strDir, ptr );

		// need to remove trailing '/' or fioRmdir won't work
		if( strDir[ strlen(strDir) - 1 ] == '/' )
			strDir[ strlen(strDir) - 1 ] = 0x0;

		fioRmdir( strDir );
		return c;
	}
	else if( !strncmp( file, "smb:", c ) ) {
		return smbc_unlink( file );
	}

	return -1;
}
Beispiel #2
0
int FileRmdir( const char *path )
{
	char *ptr;
	int c;

	if( (ptr = strchr( path, ':' )) == NULL ) {
#ifdef _DEBUG
		printf("FileRmdir : Invalid Path (ptr = NULL)\n");
#endif
		return -1;
	}

	c = ptr - path;

	if( !strncmp( path, "pfs", 3 ) ) {
		return fileXioRmdir( path );
	}
	else if( !strncmp( path, "mc0:", c ) || !strncmp( path, "mc1:", c ) ) {
		return fioRmdir( path );
	}
	else if( !strncmp( path, "mass:", c ) ) {
		char strDir[256];

		// you MUST call fioRmdir with device number for USB device.
		strcpy( strDir, "mass0" );
		strcat( strDir, ptr );

		// need to remove trailing '/' or fioRmdir won't work
		if( strDir[ strlen(strDir) - 1 ] == '/' )
			strDir[ strlen(strDir) - 1 ] = 0x0;

		return fioRmdir( strDir );
	}
	else if( !strncmp( path, "smb:", c ) ) {
		return smbc_unlink( path );
	}

	return -1;
}
Beispiel #3
0
int real_copyRTEELF(void *arg)
{
	FILE *fin;
	const char *filename = rteELF;
	uint32_t *magic = (uint32_t *) magic_string;
	uint32_t elfSize = 0;
	const char *outputfilename;
	uint32_t elfNumber = 1;
	copyRTEELF_param_t *param = (copyRTEELF_param_t *) arg;
	

	outputfilename = param->outputFilename;
	elfNumber = atoi(param->elfNumber);
	kprintf("elfNumber 0x%08x.\n", elfNumber);
	kprintf("Search for elf in \"%s\".\n", filename);

	graphic_setPercentage(0, filename);

	fin = fopen(filename, "rb");
	if (fin != NULL)
	{
		char *buffer;
		uint32_t size;

		filename = NULL;
		fseek(fin, 0, SEEK_END);
		size = ftell(fin);
		fseek(fin, 0, SEEK_SET);
		buffer = malloc(size);
		if (buffer != NULL)
		{
			FILE *fout;
			char *addr;
			char *endaddr;

			if (fread(buffer, size, 1, fin) != 1)
			{
				fclose(fin);
				free(buffer);
				error_printf("Can't read file.");
				return -3;
			}
			fclose(fin);

			endaddr = (char *) (((uint32_t) buffer) + size);
			for (addr = buffer; addr < endaddr; addr += 4)
			{
				if (*((uint32_t *)addr) == *magic)
				{
					elfNumber--;
					if (elfNumber == 0) {
						break;
					}
				}
			}
			if (*((uint32_t *)addr) == *magic)
			{
				void *code;

				kprintf("Found elf at file offset 0x%08x.\n",
					((uint32_t) addr) - ((uint32_t) buffer));
				for (code = addr + 4; code < ((void *) endaddr); code += 4) {
					uint32_t value;

					value = *((uint32_t *)code);
					if (value == *magic) {
						/* memcopy gets SBIOS in register a1 and size in register a2. */
						elfSize = ((uint32_t) code) - ((uint32_t) addr);
						kprintf("ELF size is 0x%08x (1).\n", elfSize);
						break;
					}
				}
				if (elfSize == 0) {
					elfSize = ((uint32_t) endaddr) - ((uint32_t) addr);
					kprintf("ELF size is 0x%08x (2).\n", elfSize);
				}

				fout = fopen(outputfilename, "wb");
				if (fout == NULL) {
					fileXioMkdir(CONFIG_DIR, 0777);
					fout = fopen(outputfilename, "wb");
				}
				if (fout != NULL)
				{
					if (fwrite(addr, elfSize, 1, fout) != 1)
					{
						fclose(fout);
						fioRemove(outputfilename);
						fioRmdir(outputfilename); /* Needed because of bug in fioRemove. */
						free(buffer);
						error_printf("Failed to write \"%s\"", outputfilename);
						return -5;
					}
					fclose(fout);
					kprintf("\"%s\" written.\n", outputfilename);
				}
				else
				{
					error_printf("Failed to open \"%s\"", outputfilename);
					free(buffer);
					return -4;
				}
			}
			else
			{
				error_printf("Can't find ELF.");
				free(buffer);
				return -6;
			}
			free(buffer);
			buffer = NULL;
		}
		else
		{
			error_printf("out of memory");
			return -2;
		}
	}
	else
	{
		error_printf("Failed to open file \"%s\"", filename);
	}
	
	return 0;
}