Page 1 of 1

Request: nitrofs + libfat example

Posted: Fri Jun 12, 2009 8:09 am
by melw
I'm bit puzzled about how to get libfat and nitrofs working at the same time. Either I get fat or nitro initialized and working, but can't use one after another. Any pointers on this would be appreciated - perhaps adding also an example to examples/nds/filesystem ?

The following code was tested with R4DS (SLOT-1) and M3Lite (SLOT-2), both failing with writing to fat - rest of the code & project is exactly like in the nitrodir example:

Code: Select all

int main(void) {

	consoleDemoInit();

	if(!nitroFSInit()) {
		printf("nitro init FAILED!\n");
	}	else {
		printf("nitro init OK!\n");
		dirlist("/");
	
		FILE *fp;
	
		fp = fopen("fat:/test.dat", "w+b");
		if(fp==NULL)
			printf("fat test w+b FAILED!\n");
		else
			printf("fat test w+b OK!\n");	
		fclose(fp);
	}

	while(1) {
		swiWaitForVBlank();
	}

	return 0;
}
Fat part works normally with fatInitDefault() - which again renders nitroFS in unusable state.

Re: Request: nitrofs + libfat example

Posted: Fri Jun 12, 2009 4:48 pm
by Tomdev
i'm testing it, if it works on my ez v, will post the results(they are a bit different because i compiled nitrofs from source). and thanks for your help in my post :P

Re: Request: nitrofs + libfat example

Posted: Mon Jun 15, 2009 8:43 pm
by melw
Nevermind, the code posted above actually works as it should. The problem was a result of NitroFS not receiving the argv values as intended.

Re: Request: nitrofs + libfat example

Posted: Mon Jun 15, 2009 11:52 pm
by WinterMute
Cool, glad you got it sorted - I've been buried in other parts of toolchain maintenance this week so apologies for late replies.

This actually brings up something that I'm not sure how to handle at all. For a system where nitroFS isn't read through libfat then this sort of thing will fail anyway - emulators and slot2 cards for the most part. Where nitrofs *is* read through libfat then the ideal situation would be for fat calls to use the directory the nds is launched from, rather than saving things to /. Unfortunately defaulting to nitrofs destroys the working directory so the user would currently need to recreate it from argv.

Any ideas on a better way to handle this sort of situation?

Re: Request: nitrofs + libfat example

Posted: Wed Jun 17, 2009 6:03 am
by melw
WinterMute wrote:This actually brings up something that I'm not sure how to handle at all. For a system where nitroFS isn't read through libfat then this sort of thing will fail anyway - emulators and slot2 cards for the most part. Where nitrofs *is* read through libfat then the ideal situation would be for fat calls to use the directory the nds is launched from, rather than saving things to /. Unfortunately defaulting to nitrofs destroys the working directory so the user would currently need to recreate it from argv.

Any ideas on a better way to handle this sort of situation?
Hmmm. No clear winner in this case. Two alternatives I can think of straight away:
  • - Store working directory into a system variable. Nitrofs remains untouched, users can be advised to use this stored variable when accessing fat.
  • - Remove chdir("nitro:/") from nitroFSInit(). Working directory for fat calls works as intended, but nitrofs calls may require modifications.
Personally I'd prefer the latter - but that may be just because the project I'm working uses fat actively, whereas nitrofs is there mostly for loading resources when launching the application. Also, nitrofs working directory is normally just the root, hence the fat working directory is the one that matters.