Page 1 of 1

Filesystem Usage Example

Posted: Wed May 28, 2008 7:10 am
by whatisdot
Hello everyone. Your favorite newbie, here, with another exciting topic.
I have been looking for code related to file systems and the hard drive, and have come up a bit short. I made this small example to try to see if I could access my hard drive partitions on my PS2, but it just hangs at whatever "hdd...()" function I try to execute. I'm obviously missing something, but I'm a little befuddled. Could someone shed some light on this issue? Thanks. =)


EDIT:
Example code has been moved to the bottom of the thread.

Posted: Wed May 28, 2008 7:59 am
by Lukasz
You need to load the IOP HDD modules.

Posted: Wed May 28, 2008 9:08 am
by whatisdot
Okay, I'm trying to load the modules, but I don't know which modules need to be loaded. I've already tried these, but the 'ps2hdd' and 'ps2fs' don't want to load. I can only assume they rely on some other module that I have yet to find...

Code: Select all

SifLoadModule("host0:fileXio.irx", 0, NULL);
SifLoadModule("host0:ps2hdd.irx", 0, NULL);
SifLoadModule("host0:ps2fs.irx", 0, NULL);
What am I missing???

Posted: Wed May 28, 2008 10:08 am
by EP
whatisdot wrote:What am I missing???
You need to load the ps2atad IRX first.

Posted: Wed May 28, 2008 11:15 am
by whatisdot
So far I've loaded these modules:

Load correctly

Code: Select all

	SifLoadModule("rom0:SIO2MAN", 0, NULL);
	SifLoadModule("rom0:MCMAN", 0, NULL);
	SifLoadModule("rom0:MCSERV", 0, NULL);
	SifLoadModule("host0:fileXio.irx", 0, NULL);
	SifLoadModule("host0:ps2atad.irx", 0, NULL);
Refuse to load

Code: Select all

	SifLoadModule("host0:ps2hdd.irx", 0, NULL);
	SifLoadModule("host0:ps2fs.irx", 0, NULL);

Posted: Wed May 28, 2008 4:07 pm
by EP
There is also iomanX as well as ps2dev9 which are needed prior to loading ps2atad, ps2hdd, and ps2fs. However; if you're running code through ps2link you have already loaded those particular two.

Posted: Wed May 28, 2008 6:04 pm
by ragnarok2040
If you look at the imports.lst files for the IOP modules you need, you can usually tell what modules need to be loaded.

You might need to include some arguments for ps2fs.irx and ps2hdd.irx, as well. These are the arguments I use that I gleaned from other sources, and I think this is the way to load them with SifLoadModule().

static char hddarg[] = "-o" "\0" "4" "\0" "-n" "\0" "20";
SifLoadModule("host0:ps2hdd.irx", sizeof(hddarg), hddarg);

static char pfsarg[] = "-m" "\0" "4" "\0" "-o" "\0" "10" "\0" "-n" "\0" "40";
SifLoadModule("host0:ps2fs.irx", sizeof(pfsarg), pfsarg);

-o is maxopen and -n is cachesize for ps2hdd.irx
-m is maxmounts, -o is maxopen, and -n is for the number of buffers for ps2fs.irx

Posted: Thu May 29, 2008 6:41 am
by cosmito
ragnarok2040 wrote:If you look at the imports.lst files for the IOP modules you need, you can usually tell what modules need to be loaded.
Hmm useful advice, I wasn't aware of it. Thanks

Posted: Thu May 29, 2008 6:52 am
by whatisdot
Thanks for the responses. The modules load correctly now, but it still freezes when I execute one of the hdd...() functions. It turns out that "poweroff.irx" was also needed.
A bit more info on my setup; I have a 250GB hard drive in my PS2 and I have formatted a couple of partitions using the PS2HDD application, as well as storing a number of PS2 games on it using HDLoader. At this point I am just trying to get a listing of the partitions. Once I can do this, I was going to try to mount them to folders in my formatted partitions on the HDD. I am also using PS2Link to test it.


EDIT:
Sample code has been moved to the bottom of this thread.

Posted: Sun Jun 01, 2008 7:14 am
by Mega Man
You also need to load fileXio.irx after iomanX.irx.

Posted: Thu Jun 05, 2008 3:07 am
by whatisdot
Hey Mega Man! That did the trick! Thanks a bunch. I'll rework this code and repost it when it is cleaned up. Thanks for all the help, everyone!

EDIT:
I hope someone else finds this code useful. I hope it saves them the time and energy it took me, and the people who responded to this thread. Feel free to respond if someone sees some redundancy or flaw.
Here is the bare bottom code for checking the hard drive and it's partitions. I was checking this at runtime using PS2Link. I made sure to copy the following modules into my executable's directory:

poweroff.irx
fileXio.irx
ps2atad.irx
ps2fs.irx
ps2hdd.irx
(the order in which these modules are loaded is important)

And here's the code:

Makefile

Code: Select all

EE_BIN = file_system.elf
EE_OBJS = file_system.o
EE_LIBS = -ldebug -lhdd -lfileXio -lpoweroff

all: $(EE_BIN)

clean:
	rm -f *.elf *.o *.a

include $(PS2SDK)/samples/Makefile.pref
include $(PS2SDK)/samples/Makefile.eeglobal
file_system.c

Code: Select all

#include <tamtypes.h>
#include <stdio.h>
#include <debug.h>
#include <libhdd.h>
#include <libpwroff.h>
#include <fileXio_rpc.h>
#include <sifrpc.h>
#include <loadfile.h>

#define MAX_PARTITIONS   100
// The space that will hold the information about the
// partitions on the hard drive.
t_hddFilesystem parties&#91;MAX_PARTITIONS&#93; __attribute__&#40;&#40;aligned&#40;64&#41;&#41;&#41;;

int main&#40;&#41; &#123;
	char *printStr;
	int i=0, nparty=0;

	// Initialize the screen &#40;clear it&#41;
	init_scr&#40;&#41;;

	// Initialize the Remote Proceedure Call manager
	SifInitRpc&#40;0&#41;;

	printStr = "Loading modules...\n";
	// print to PS2 Screen
	scr_printf&#40; printStr &#41;;
	// print to console window
	printf&#40; printStr &#41;;

	// Load the needed modules
	SifLoadModule&#40;"host0&#58;poweroff.irx", 0, NULL&#41;;
	SifLoadModule&#40;"host0&#58;fileXio.irx", 0, NULL&#41;;
	SifLoadModule&#40;"host0&#58;ps2atad.irx", 0, NULL&#41;;
	// set the arguments for loading 'ps2fs'
	// -m 4  &#40;maxmounts 4&#41;
	// -o 10 &#40;maxopen 10&#41;
	// -n 40 &#40;number of buffers 40&#41;
	static char pfsarg&#91;&#93; = "-m" "\0" "4" "\0" "-o" "\0" "10" "\0" "-n" "\0" "40";
	SifLoadModule&#40;"host0&#58;ps2fs.irx", sizeof&#40;pfsarg&#41;, pfsarg&#41;;
	// set the arguments for loading 'ps2hdd'
	// -o 4 &#40;maxopen 4&#41;
	// -n 20 &#40;cachesize 20&#41;
	static char hddarg&#91;&#93; = "-o" "\0" "4" "\0" "-n" "\0" "20";
	SifLoadModule&#40;"host0&#58;ps2hdd.irx", sizeof&#40;hddarg&#41;, hddarg&#41;;

	printStr = "Finished loading modules.\nChecking the hard drive...\n";
	scr_printf&#40; printStr &#41;;
	printf&#40; printStr &#41;;

	if&#40; hddCheckPresent&#40;&#41; < 0 &#41; &#123;
		printStr = "NO HDD FOUND!\n";
		scr_printf&#40; printStr &#41;;
		printf&#40; printStr &#41;;
		return -1;
	&#125; else &#123;
		printStr = "Found HDD!\n";
		scr_printf&#40; printStr &#41;;
		printf&#40; printStr &#41;;
	&#125;

	if&#40; hddCheckFormatted&#40;&#41; < 0 &#41; &#123;
		printStr = "HDD Not Formatted!\n";
		scr_printf&#40; printStr &#41;;
		printf&#40; printStr &#41;;
		return -1;
	&#125; else &#123;
		printStr = "HDD Is Formatted!\n";
		scr_printf&#40; printStr &#41;;
		printf&#40; printStr &#41;;
	&#125;

	// populate 'parties' with information on each partition
	i = hddGetFilesystemList&#40;parties, MAX_PARTITIONS&#41;; 

	// "# partitions"
	printStr = "%i partitions\n";
	scr_printf&#40; printStr, i&#41;;
	printf&#40; printStr, i&#41;;

	// List each partition name
	nparty=i-1;
	for&#40;i=nparty;i>=0;i--&#41; &#123;
		printStr = "Partition&#58; %s\n";
		scr_printf&#40; printStr, parties&#91;i&#93;.name&#41;;
		printf&#40; printStr, parties&#91;i&#93;.name&#41;;
	&#125;

	printStr = "All done!\nGoodbye\n";
	scr_printf&#40; printStr &#41;;
	printf&#40; printStr &#41;;

	return 0;
&#125;

Posted: Thu Jun 05, 2008 6:03 am
by Lukasz
Hint: You can have the Makefile copy the IRX files into the directory for you.

Code: Select all

EE_BIN = file_system.elf
EE_OBJS = file_system.o
EE_LIBS = -ldebug -lhdd -lfileXio -lpoweroff

IRXS = poweroff.irx fileXio.irx ps2atad.irx ps2fs.irx ps2hdd.irx 

all&#58; $&#40;EE_BIN&#41; $&#40;IRXS&#41;

%.irx&#58;
	cp $&#40;PS2SDK&#41;/iop/irx/$@ $@

clean&#58;
	rm -f *.elf *.o *.a *.irx

include $&#40;PS2SDK&#41;/samples/Makefile.pref
include $&#40;PS2SDK&#41;/samples/Makefile.eeglobal 

Posted: Thu Jun 05, 2008 9:02 am
by cosmito
whatisdot wrote:I hope someone else finds this code useful.
Yes I do indeed. Many thanks.

BTW: If you're into sharing code for helping others you could setup a free subversion repository, using www.assembla.com ou others (like google code) and commit the source there. This has also the big advantage to yourself that is inherent to the use of a source control version system, since you can obviously decide if your repositories will be public or not.

My public is at http://svn2.assembla.com/svn/pedroduarteps2dev_public . Feel free to browse, although not much code is there yet.

Posted: Tue Jun 17, 2008 6:41 am
by whatisdot
Very nice! I made an account and uploaded some of the things I have done. I augmented the example here to mount a file system on the hard drive and list its directories. You can find this and my other examples here:

http://www.assembla.com/spaces/files/ps2sdk-demos

Posted: Tue Jun 17, 2008 8:12 am
by cosmito
Cool. But I strongly advice you to look at the source control system it offers (subversion) since true power comes from it. As soon you get familiar with it you simply cannot code without it :) A great client for Winblows is TortoiseSVN.

Posted: Wed Jun 18, 2008 10:23 am
by whatisdot
Hi ptek,

I have never gotten around to looking into SVN, but now is as good a time as any. I found this after doing some searching.

http://svnbook.red-bean.com/

I have some reading to do. Thanks for the encouragement. =)