forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Filesystem Usage Example

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development
View previous topic :: View next topic  
Author Message
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Wed May 28, 2008 7:10 am    Post subject: Filesystem Usage Example Reply with quote

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.

_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------


Last edited by whatisdot on Thu Jun 05, 2008 3:37 am; edited 1 time in total
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Wed May 28, 2008 7:59 am    Post subject: Reply with quote

You need to load the IOP HDD modules.
_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Wed May 28, 2008 9:08 am    Post subject: Reply with quote

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:

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


What am I missing???
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
EP



Joined: 05 Nov 2005
Posts: 39

PostPosted: Wed May 28, 2008 10:08 am    Post subject: Reply with quote

whatisdot wrote:
What am I missing???

You need to load the ps2atad IRX first.
Back to top
View user's profile Send private message
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Wed May 28, 2008 11:15 am    Post subject: Reply with quote

So far I've loaded these modules:

Load correctly
Code:

   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:

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

_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
EP



Joined: 05 Nov 2005
Posts: 39

PostPosted: Wed May 28, 2008 4:07 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
ragnarok2040



Joined: 09 Aug 2006
Posts: 230

PostPosted: Wed May 28, 2008 6:04 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Thu May 29, 2008 6:41 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Thu May 29, 2008 6:52 am    Post subject: Reply with quote

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.

_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------


Last edited by whatisdot on Thu Jun 05, 2008 3:34 am; edited 1 time in total
Back to top
View user's profile Send private message
Mega Man



Joined: 18 Jun 2005
Posts: 274

PostPosted: Sun Jun 01, 2008 7:14 am    Post subject: Reply with quote

You also need to load fileXio.irx after iomanX.irx.
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Thu Jun 05, 2008 3:07 am    Post subject: Reply with quote

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:

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:

#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[MAX_PARTITIONS] __attribute__((aligned(64)));

int main() {
   char *printStr;
   int i=0, nparty=0;

   // Initialize the screen (clear it)
   init_scr();

   // Initialize the Remote Proceedure Call manager
   SifInitRpc(0);

   printStr = "Loading modules...\n";
   // print to PS2 Screen
   scr_printf( printStr );
   // print to console window
   printf( printStr );

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

   printStr = "Finished loading modules.\nChecking the hard drive...\n";
   scr_printf( printStr );
   printf( printStr );

   if( hddCheckPresent() < 0 ) {
      printStr = "NO HDD FOUND!\n";
      scr_printf( printStr );
      printf( printStr );
      return -1;
   } else {
      printStr = "Found HDD!\n";
      scr_printf( printStr );
      printf( printStr );
   }

   if( hddCheckFormatted() < 0 ) {
      printStr = "HDD Not Formatted!\n";
      scr_printf( printStr );
      printf( printStr );
      return -1;
   } else {
      printStr = "HDD Is Formatted!\n";
      scr_printf( printStr );
      printf( printStr );
   }

   // populate 'parties' with information on each partition
   i = hddGetFilesystemList(parties, MAX_PARTITIONS);

   // "# partitions"
   printStr = "%i partitions\n";
   scr_printf( printStr, i);
   printf( printStr, i);

   // List each partition name
   nparty=i-1;
   for(i=nparty;i>=0;i--) {
      printStr = "Partition: %s\n";
      scr_printf( printStr, parties[i].name);
      printf( printStr, parties[i].name);
   }

   printStr = "All done!\nGoodbye\n";
   scr_printf( printStr );
   printf( printStr );

   return 0;
}

_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
Lukasz



Joined: 19 Jan 2004
Posts: 248
Location: Denmark

PostPosted: Thu Jun 05, 2008 6:03 am    Post subject: Reply with quote

Hint: You can have the Makefile copy the IRX files into the directory for you.

Code:

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: $(EE_BIN) $(IRXS)

%.irx:
   cp $(PS2SDK)/iop/irx/$@ $@

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

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

_________________
Lukasz.dk
Back to top
View user's profile Send private message Visit poster's website
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Thu Jun 05, 2008 9:02 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Tue Jun 17, 2008 6:41 am    Post subject: Reply with quote

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
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
cosmito



Joined: 04 Mar 2007
Posts: 314
Location: Portugal

PostPosted: Tue Jun 17, 2008 8:12 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
whatisdot



Joined: 07 Apr 2008
Posts: 43
Location: Purdue University, USA

PostPosted: Wed Jun 18, 2008 10:23 am    Post subject: Reply with quote

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. =)
_________________
--------------------------------------------------------------
"A witty saying proves nothing."
--------------------------------------------------------------
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PS2 Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group