Request: nitrofs + libfat example

Post Reply
melw
Posts: 13
Joined: Thu Mar 20, 2008 11:43 am

Request: nitrofs + libfat example

Post by melw » Fri Jun 12, 2009 8:09 am

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.

Tomdev
Posts: 82
Joined: Thu Jan 08, 2009 9:15 pm

Re: Request: nitrofs + libfat example

Post by Tomdev » Fri Jun 12, 2009 4:48 pm

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

melw
Posts: 13
Joined: Thu Mar 20, 2008 11:43 am

Re: Request: nitrofs + libfat example

Post by melw » Mon Jun 15, 2009 8:43 pm

Nevermind, the code posted above actually works as it should. The problem was a result of NitroFS not receiving the argv values as intended.

WinterMute
Site Admin
Posts: 1853
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Request: nitrofs + libfat example

Post by WinterMute » Mon Jun 15, 2009 11:52 pm

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?
Help keep devkitPro toolchains free, Donate today

Personal Blog

melw
Posts: 13
Joined: Thu Mar 20, 2008 11:43 am

Re: Request: nitrofs + libfat example

Post by melw » Wed Jun 17, 2009 6:03 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests