Welcome! Log In Create A New Profile

Advanced

check if the dol/elf is booted form sd or hdd...

Posted by filfat 
check if the dol/elf is booted form sd or hdd...
January 03, 2013 02:35PM
has started to code a way to load config file to wiicraft. and i need help. i will check if the file is booted from SD/SDHC/USB/Internet(send over the file) is this possible?
Re: check if the dol/elf is booted form sd or hdd...
January 03, 2013 04:14PM
Never tried it, but does argv[0] contain the file path and can you get it that way?
Re: check if the dol/elf is booted form sd or hdd...
January 03, 2013 05:46PM
i dont know.
Re: check if the dol/elf is booted form sd or hdd...
January 03, 2013 09:39PM
Yeah argv[0] contains the path I am fairly certain, and you can get it from there indeed.

Check the first byte; if it is "s", it's from the SD card, if it is "u", it's from a USB drive.

EDIT: Something like this should work I think:

	char test;
	int useSD;
	sscanf(argv[0], "%c", &test); //read first character from argv[0] into test
	if(test == 115){ useSD = 1; } //first character = s
	if(test == 117){ useSD = 0; } //first character = u

(Haven't tried this, but I believe it should work in theory, provided the path is indeed passed as argv[0] (which I'm confident it is) and it includes the storage device.)

EDIT: Tested it and it definitely works.



Edited 4 time(s). Last edit at 01/08/2013 05:21PM by SifJar.
Re: check if the dol/elf is booted form sd or hdd...
January 04, 2013 03:37AM
You should make sure argv and argv[0] are not NULL before using that code, to account for all the poorly coded loaders out there.
Re: check if the dol/elf is booted form sd or hdd...
January 04, 2013 11:49AM
will i got a ip there if i has send it over internet/wifi?
Re: check if the dol/elf is booted form sd or hdd...
January 04, 2013 01:50PM
Why don't you try it and see?
Re: check if the dol/elf is booted form sd or hdd...
January 04, 2013 02:17PM
Quote
filfat
will i got a ip there if i has send it over internet/wifi?

Well you would only get the first byte using the code I provided above (and for anything other than "s" or "u" it would do nothing). argv[0] may contain an IP, I don't know. As chris suggested, you can try it and see what happens. (try printing argv[0] to screen and then load it via the different methods [SD, USB, wiiload (i.e. wifi)] and see what argv[0] is in each case)
Re: check if the dol/elf is booted form sd or hdd...
January 04, 2013 02:37PM
Re: check if the dol/elf is booted form sd or hdd...
January 04, 2013 05:18PM
From my tests I get the best results by either using absolute or relative file names;

"/apps/programname/config.txt"

or

"config.txt"
"settings/config.txt"

also try changing the working directory in c;

chdir("/apps/programname/");
Re: check if the dol/elf is booted form sd or hdd...
January 04, 2013 11:40PM
how does i use mkdir? or is it not added?
Re: check if the dol/elf is booted form sd or hdd...
January 05, 2013 06:37PM
[pastebin.com]

(This forum's parsing messes up the code, hence the pastebin for such a small snippet of code)

EDIT: I feel I should also mention that this is the case on all platforms AFAIK; that function is always defined in sys/stat.h.



Edited 4 time(s). Last edit at 01/05/2013 09:21PM by SifJar.
Re: check if the dol/elf is booted form sd or hdd...
January 05, 2013 06:44PM
Re: check if the dol/elf is booted form sd or hdd...
January 07, 2013 07:23PM
i cant get the makedir to work it only crash my program.
Re: check if the dol/elf is booted form sd or hdd...
January 08, 2013 01:01AM
You're probably doing it wrong then. Showing us your code certainly wouldn't stop anyone from helping...
Re: check if the dol/elf is booted form sd or hdd...
January 08, 2013 02:56AM
i ran this and it worked on my sdcard

mkdir("test",  S_IRWXU|S_IRGRP|S_IXGRP);
Re: check if the dol/elf is booted form sd or hdd...
January 08, 2013 07:00AM
here:
 int initFolders(bool SD){



        if(SD)

                return mkdir("sd:/Wiicraft", 0777);

        else

                return mkdir("usb:/Wiicraft", 0777);

}

0777 is a perssimision code.
Re: check if the dol/elf is booted form sd or hdd...
January 08, 2013 07:01AM
and else is a comment but its is not showing here... -_-
Re: check if the dol/elf is booted form sd or hdd...
January 08, 2013 11:57AM
Have you tried owen's code? Perhaps the Wii libraries don't support the permissions format you used.
Re: check if the dol/elf is booted form sd or hdd...
January 08, 2013 12:30PM
i will try it when i come home =)
Sorry, only registered users may post in this forum.

Click here to login