Page 1 of 1

problem with simple file copy code

Posted: Mon May 16, 2005 8:18 am
by Mak0
bascially im trying to write a simple tool to copy TITLE.DB from my memory card to my pc but it seems to crash right after it accesses mc0:/BADATA-SYSTEM/TITLE.DB. im probably making some trivial mistake that hopefully someone more experienced can point out. here's my code:

Code: Select all

#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <loadfile.h>
#include <fileio.h>
#include <malloc.h>
#include <libmc.h>
#include <string.h>
#include <modload.h>

#define TYPE_XMC

void LoadModules&#40;void&#41;;



int main&#40;&#41; &#123;

	
	SifInitRpc&#40;0&#41;;
	LoadModules&#40;&#41;;
int inF, ouF;
  char line&#91;512&#93;;
  int bytes;

 if&#40;&#40;inF = fioOpen&#40;"mc0&#58;/BADATA-SYSTEM/TITLE.DB", O_RDONLY&#41;&#41; < 0&#41; &#123;
    scr_printf&#40;"error opening <mc0&#58;/BADATA-SYSTEM/TITLE.DB>!"&#41;;
    exit&#40;-1&#41;;
  &#125;

  if&#40;&#40;ouF = fioOpen&#40;"host&#58;TITLE.DB", O_WRONLY | O_CREAT&#41;&#41; < 0&#41; &#123;
    scr_printf&#40;"error writing <host&#58;TITLE.DB>!"&#41;;
    exit&#40;-1&#41;;
  &#125;
while&#40;&#40;bytes = fioRead&#40;inF, line, sizeof&#40;line&#41;&#41;&#41; > 0&#41;
    fioWrite&#40;ouF, line, bytes&#41;;

  fioClose&#40;inF&#41;;
  fioClose&#40;ouF&#41;;

	SifExitRpc&#40;&#41;;

	SleepThread&#40;&#41;;
	return 0;
&#125;

void LoadModules&#40;void&#41;
&#123;
    int ret;

#ifdef TYPE_MC
	ret = SifLoadModule&#40;"rom0&#58;SIO2MAN", 0, NULL&#41;;
	if &#40;ret < 0&#41; &#123;
		printf&#40;"Failed to load module&#58; SIO2MAN"&#41;;
		SleepThread&#40;&#41;;
	&#125;

	ret = SifLoadModule&#40;"rom0&#58;MCMAN", 0, NULL&#41;;
	if &#40;ret < 0&#41; &#123;
		printf&#40;"Failed to load module&#58; MCMAN"&#41;;
		SleepThread&#40;&#41;;
	&#125;

	ret = SifLoadModule&#40;"rom0&#58;MCSERV", 0, NULL&#41;;
	if &#40;ret < 0&#41; &#123;
		printf&#40;"Failed to load module&#58; MCSERV"&#41;;
		SleepThread&#40;&#41;;
	&#125;
#else
	ret = SifLoadModule&#40;"rom0&#58;XSIO2MAN", 0, NULL&#41;;
	if &#40;ret < 0&#41; &#123;
		printf&#40;"Failed to load module&#58; SIO2MAN"&#41;;
		SleepThread&#40;&#41;;
	&#125;

	ret = SifLoadModule&#40;"rom0&#58;XMCMAN", 0, NULL&#41;;
	if &#40;ret < 0&#41; &#123;
		printf&#40;"Failed to load module&#58; MCMAN"&#41;;
		SleepThread&#40;&#41;;
	&#125;

	ret = SifLoadModule&#40;"rom0&#58;XMCSERV", 0, NULL&#41;;
	if &#40;ret < 0&#41; &#123;
		printf&#40;"Failed to load module&#58; MCSERV"&#41;;
		SleepThread&#40;&#41;;
	&#125;
#endif

&#125;

Posted: Mon May 16, 2005 10:15 am
by pixel
Crashing how ?

Posted: Mon May 16, 2005 10:21 am
by Mak0
It just seems to hang after accessing mc0:/ and no file is created on host:/ even though fioOpen returns 0.

I have no idea as to why.

Posted: Mon May 16, 2005 12:34 pm
by cheriff
If all you want is a copy of the file, do you really need to write a whole elf just to do that?
Try

Code: Select all

ps2client copyfrom mc0&#58;/BADATA-SYSTEM/TITLE.DB host&#58;TITLE.DB
Thats how i get stuff off/on a mc. I'm not at my dev machine right now, but im pretty sure thats right.

PS: you may need a slightly older version of ps2client..i've heard rumours the netfs functions were pulled out recently?? i dunno.
PPS: you have to load ps2netfs.irx from ps2sdk first...

EDIT: Now recent ckeckouts of ps2client also come with a program fsclient that takes this functionality off ps2client