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 

I just can't format the HDD using libhdd... Why???

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



Joined: 13 Apr 2006
Posts: 24

PostPosted: Thu Apr 13, 2006 5:52 am    Post subject: I just can't format the HDD using libhdd... Why??? Reply with quote

Hi folks!

I am writing a simple application to format the PS2 HDD. Everything goes fine: it's detected, it's formatted (i can see the internal HDD orange led flashing while it's being formatted).

At the end of the proccess, I just poweroff the PS2. But if I run the application again, it recognizes my HDD like UNFORMATTED, i. e., the program was just "pretending" it was formatting my HDD. At this point, the second time the application is run, it should display "Nothing to do! HDD is already formatted", because that was done already in the first execution, but no: I just get the formatting routine again! :(

Here goes my code:
Code:

#include <kernel.h>
#include <sifrpc.h>
#include <libhdd.h>
#include <debug.h>
#include <string.h>
#include <libmc.h>
#include <loadfile.h>

#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/ioctl.h>

extern u8 *iomanx_irx;
extern int size_iomanx_irx;
extern u8 *filexio_irx;
extern int size_filexio_irx;
extern u8 *ps2dev9_irx;
extern int size_ps2dev9_irx;
extern u8 *ps2atad_irx;
extern int size_ps2atad_irx;
extern u8 *ps2hdd_irx;
extern int size_ps2hdd_irx;
extern u8 *ps2fs_irx;
extern int size_ps2fs_irx;
extern u8 *poweroff_irx;
extern int size_poweroff_irx;
extern u8 *cdvd_irx;
extern int size_cdvd_irx;

void loadModules(void);

int main()
{   
   SifInitRpc(0);

   init_scr();

   loadModules();
   
   if(hddCheckPresent() == 0) {

      if(hddCheckFormatted() != 0) {

         if(hddFormat() == 0)
            scr_printf("HDD formated successfuly\n\n");
         else

            scr_printf("Error! Could not format HDD\n\n");
      } else

         scr_printf("Nothing to do! HDD is already formatted\n\n");

   } else

      scr_printf("Error! HDD not found!\n\n");
   
   while(1);
   
   return 0;
}

void loadModules(void) {
   static char hddarg[] = "-o" "\0" "4" "\0" "-n" "\0" "20";
   static char pfsarg[] = "-m" "\0" "4" "\0" "-o" "\0" "10" "\0" "-n" "\0" "40";
   int ret;
   
   hddPreparePoweroff();

   SifLoadModule("rom0:SIO2MAN", 0, NULL);
   SifExecModuleBuffer(&poweroff_irx, size_poweroff_irx, 0, NULL, &ret);
   SifExecModuleBuffer(&iomanx_irx, size_iomanx_irx, 0, NULL, &ret);
   SifExecModuleBuffer(&filexio_irx, size_filexio_irx, 0, NULL, &ret);
   SifExecModuleBuffer(&ps2dev9_irx, size_ps2dev9_irx, 0, NULL, &ret);
   SifExecModuleBuffer(&ps2atad_irx, size_ps2atad_irx, 0, NULL, &ret);
   SifExecModuleBuffer(&ps2hdd_irx, size_ps2hdd_irx, sizeof(hddarg), hddarg, &ret);
   SifExecModuleBuffer(&ps2fs_irx, size_ps2fs_irx, sizeof(pfsarg), pfsarg, &ret);
}


What I am doing wrong? What am I missing? Hope to get some help from you guys!

Thanks in advance!

sparrow


Last edited by sparrow on Tue Apr 18, 2006 7:27 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Thu Apr 13, 2006 10:15 pm    Post subject: Reply with quote

Nobody?

Well, I am using the exploit method to run my format elf. This can be why it's not working?

Hope to get some help!

Regards!
Back to top
View user's profile Send private message Visit poster's website
Saotome



Joined: 03 Apr 2004
Posts: 182

PostPosted: Fri Apr 14, 2006 12:20 am    Post subject: Reply with quote

Well I'm not 100% sure but I had a similar problem in my first HDD project: I created some directories but after restart they were gone. Just before I was about to give up and throw away my HDD I ran a last test doing a hdd cache flush (don't know the exact function name since I'm not home right now) after creating the directories. Maybe that's what you're missing, just a guess though ;)
_________________
infj
Back to top
View user's profile Send private message
dlanor



Joined: 28 Oct 2004
Posts: 269
Location: Stockholm, Sweden

PostPosted: Fri Apr 14, 2006 3:39 am    Post subject: Reply with quote

This thread made me interested in finding out more on how those two 'hddCheck*' functions really work, so I started looking/searching in the sources. Apparently they are both remapped/wrapped to fileXioDevctl calls in nearly identical manner, as shown by this small excerpt from "$PS2SDKSRC/ee/rpc/hdd/src/libhdd.c"
Code:

int hddCheckPresent()
{
   int rv;

   if(!hddStatusCurrent)
      hddUpdateInfo();

   rv = fileXioDevctl("hdd0:", HDDCTL_STATUS, NULL, 0, NULL, 0);

   if((rv >= 3) || (rv < 0))
      return -1;
   else
      return 0;
}

int hddCheckFormatted()
{
   int rv;

   if(!hddStatusCurrent)
      hddUpdateInfo();

   rv = fileXioDevctl("hdd0:", HDDCTL_STATUS, NULL, 0, NULL, 0);
   if((rv >= 1) || (rv < 0))
      return -1;
   else
      return 0;   
}
Both those cases use an identical call, with identical arguments, to ask the IRX driver for the relevant status. The only difference is in how the two functions 'filter' the return value. So the crucial call here is clearly: "rv = fileXioDevctl("hdd0:", HDDCTL_STATUS, NULL, 0, NULL, 0)"

Analyzing this deeper was a bit tricky due to inconsistent use of constants, but apparently HDDCTL_STATUS, defined in "$PS2SDKSRC/common/include/hdd-ioctl.h" is identical in both value and purpose to APA_DEVCTL_STATUS, defined both in "$PS2SDKSRC/iop/hdd/pfs/src/misc.h" and "$PS2SDKSRC/hdd/apa/src/hdd_fio.h", and finally referenced by "$PS2SDKSRC/iop/hdd/apa/src/hdd_fio.c" for the "hddDevctl" function.

The relevant part of that function simply looks like this:
Code:
   case APA_DEVCTL_STATUS:
      rv=hddDeviceBuf[f->unit].status;
      break;
Clearly then, that structure member 'status' is supposed to keep track of HDD status, both as it relates to presence/absence of the unit, and as it relates to its formatted/unformatted state. The big question then becomes how and when that 'status' value is set inside the IRX.

Judging by the EE code sections quoted further above, it is clear that the function call "hddUpdateInfo()" should handle this, though it doesn't do so directly (only makes various fileXio calls that may affect it). But "hddUpdateInfo()" will only be used if the flag variable "hddStatusCurrent" is false.

That variable is only set in two places, both inside "libhdd.c". The first place is where this static variable is declared, with initialization to 0. The other place is inside "hddUpdateInfo()", where it is set to 1 at the end of the function. So if such a call has already been made earlier, then neither of the two 'hddCheck*' functions will bother to make such an update but will proceed to refetch an old "hddDeviceBuf[f->unit].status" value from the IRX. Any invalid result in that status value, resulting from (or otherwise occurring after) an earlier call to "hddUpdateInfo()", will therefore persist forever as far as these two 'hddCheck*' functions are concerned, as they then do nothing to update the information.

That's as far as I've gotten for now. The main thing to proceed with next is to check how the fileXio calls of "hddUpdateInfo()" affect the IRX internals (mainly hddDeviceBuf[f->unit].status), and try to see if anything suspicious is going on there.

Best regards: dlanor
Back to top
View user's profile Send private message
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Sun Apr 16, 2006 9:02 am    Post subject: Reply with quote

Guys, I really don't know what is happening. It just doesn't work. DMS HDD Format Tool works. But my code doesn't. I don't want to use DMS HDD Format Tool. I want to format the HDD by myself. Does anybody here has a working example about how to properly format the PS2 HDD?

Thanks in advance!

sparrow
Back to top
View user's profile Send private message Visit poster's website
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Mon Apr 17, 2006 12:31 am    Post subject: Reply with quote

Guys,

How can I call the hddFormat function (int hddFormat(iop_file_t *f, ...)) which is inside the /ps2sdk/iop/hdd/apa/src/hdd_fio.c file? I know this file will be merged inside the ps2hdd.irx library, so how can I call it?

I think the problem is with the hddFormat function (int hddFormat()) which is inside the /ps2sdk/ee/rpc/hdd/src/libhdd.c file, because it doesn't create the __mbr partition.

The hddFormat function inside the hdd_fio.c file will create the __mbr partition, so how can I call it instead of the default (libhdd.c) hddFormat() function?

I hope I get a reply soon, so I will make some tests, then I will post here!

Thenks in advance!

Regards,

sparrow
Back to top
View user's profile Send private message Visit poster's website
Drakonite
Site Admin


Joined: 17 Jan 2004
Posts: 989

PostPosted: Mon Apr 17, 2006 1:26 am    Post subject: Reply with quote

__mbr isn't a pfs formatted partition

The ee side libhdd's hddFormat calls the iop side apa hddFormat (that you pointed at in your post), followed by a pfs format for each of the required partitions that are supposed to contain the pfs file system.

The ee side libhdd DOES create everything the IOP side function of the same name creates (it actually calls it), in fact it does a bit more as it formats the partitions that should be pfs, which the IOP side function requires you to do on your own.

If the drive is formatted using the dms hdd tool (which itself just uses an old version of the libhdd code), does your code then see the drive as formatted? If not it is pretty clear your code simply is not detecting right.
_________________
Shoot Pixels Not People!
Makeshift Development
Back to top
View user's profile Send private message Visit poster's website
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Mon Apr 17, 2006 4:28 am    Post subject: Reply with quote

Thanks for the info, Drakonite!

Yeah, my code detects my HDD as FORMATTED if I use the DMS HDD Format Tool to format it: "Nothing to do! HDD is already formatted" is displayed, what is the correct thing!

So what do you think I could do? Where can I download the old libs used by DMS HDD Format Tool and how can I use them to compile my application?

I hope to get my application working soon, thanks to you guys!

Best regards,

sparrow

Drakonite wrote:
__mbr isn't a pfs formatted partition

The ee side libhdd's hddFormat calls the iop side apa hddFormat (that you pointed at in your post), followed by a pfs format for each of the required partitions that are supposed to contain the pfs file system.

The ee side libhdd DOES create everything the IOP side function of the same name creates (it actually calls it), in fact it does a bit more as it formats the partitions that should be pfs, which the IOP side function requires you to do on your own.

If the drive is formatted using the dms hdd tool (which itself just uses an old version of the libhdd code), does your code then see the drive as formatted? If not it is pretty clear your code simply is not detecting right.
Back to top
View user's profile Send private message Visit poster's website
Drakonite
Site Admin


Joined: 17 Jan 2004
Posts: 989

PostPosted: Mon Apr 17, 2006 9:48 am    Post subject: Reply with quote

Shouldn't hddPreparePoweroff(); be run AFTER the modules are loaded, not before?
_________________
Shoot Pixels Not People!
Makeshift Development
Back to top
View user's profile Send private message Visit poster's website
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Mon Apr 17, 2006 11:30 am    Post subject: Reply with quote

According to libhdd's documentation:

Quote:

void hddPreparePoweroff();
Installs the default power-off handler. The default poweroff hander will close all PFS files then
power off the PS2 when the reset button is pressed. For this operation it is required that
poweroff.irx (included with libHdd) is loaded on IOP. This can actually be loaded before or after
the call is made to this function.


Anyway, I will put that function call after modules loading, then I will put the results here!

Regards,

sparrow
Drakonite wrote:
Shouldn't hddPreparePoweroff(); be run AFTER the modules are loaded, not before?
Back to top
View user's profile Send private message Visit poster's website
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Mon Apr 17, 2006 8:19 pm    Post subject: Reply with quote

I just made the test... No success! :-(


sparrow wrote:
According to libhdd's documentation:

Quote:

void hddPreparePoweroff();
Installs the default power-off handler. The default poweroff hander will close all PFS files then
power off the PS2 when the reset button is pressed. For this operation it is required that
poweroff.irx (included with libHdd) is loaded on IOP. This can actually be loaded before or after
the call is made to this function.


Anyway, I will put that function call after modules loading, then I will put the results here!

Regards,

sparrow
Drakonite wrote:
Shouldn't hddPreparePoweroff(); be run AFTER the modules are loaded, not before?
Back to top
View user's profile Send private message Visit poster's website
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Tue Apr 18, 2006 10:08 am    Post subject: Reply with quote

Problem solved guys!

I just used old libhdd IRX's that I got from PGEN! I am now wondering why the new lib is not formatting the HDD properly... *sigh*
Back to top
View user's profile Send private message Visit poster's website
dlanor



Joined: 28 Oct 2004
Posts: 269
Location: Stockholm, Sweden

PostPosted: Tue Apr 18, 2006 5:57 pm    Post subject: Reply with quote

sparrow wrote:
Problem solved guys!

I just used old libhdd IRX's that I got from PGEN! I am now wondering why the new lib is not formatting the HDD properly... *sigh*
This may mean "problem solved" for your current project, but it means the opposite for the homebrew community as a whole. It is the new driver, not any old version, which MUST be made to work properly one way or another. Otherwise we've lost control. :(

This also raises the question if any other software successfully uses the new lib for formatting or not !?! If so, then it may just be a matter of using it differently than you tried to do, but if not then it could mean that the current version has completely lost the capability for correct formatting. :(

I'm not yet sufficiently familiar with the libhdd code to debug it myself, though I do plan to rectify that. In the meantime I hope that other developers with a better grip on it will investigate the problem.

Best regards: dlanor
Back to top
View user's profile Send private message
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Tue Apr 18, 2006 7:26 pm    Post subject: Reply with quote

I agree with you, dlanor. The problem is only solved to my current project. I really wanted to use the new libs with it. I hope the ps2dev guys really fix this issue someday! Now I am taking off the "solved" from the thread's title, so we don't get a false feeling of "job done".

Regards,

sparrow
Back to top
View user's profile Send private message Visit poster's website
Polo35



Joined: 09 Apr 2006
Posts: 25

PostPosted: Tue May 30, 2006 6:56 am    Post subject: Reply with quote

So, as requested at ps2scene, i post what i found here.

I'm working on a hdd manager for ULE ( uLaunchELF ), and i'd got some problem with libhdd format fontion from ps2sdk.

I've try with libhdd1.2 from ps2dev.org web site, and format work fine, but size report was wrong.

I decided to search difference between two libs and found in iop/apa/src/hdd_fio.c a little difference in format fonction, setup mbr section:

In ps2sdk libhdd:

Code:
strncpy(header->mbr.magic, mbrMagic, 31);
header->mbr.magic[31] = '\0';


In libhdd1.2 from ps2dev:

Code:
strncpy(header->mbr.magic, mbrMagic, 0x20);


I've copied the line from ps2dev libhdd1.2 to ps2sdk libhdd and recomplied it completly, and now format fonction work fine.

Hdd is well reconize formated by $ony tool, DM$ tool, and "my tool". ;)

So if somebody want to confirm that thing, and make a fix to ps2sdk in svn, i would be very grateful.

Best regards

Polo
Back to top
View user's profile Send private message
sparrow



Joined: 13 Apr 2006
Posts: 24

PostPosted: Mon Jul 10, 2006 7:31 am    Post subject: Reply with quote

OMG! How could I forget to return about this?

Polo, your solution just WORKED GREAT, thank you!

Is this problem already fixed in the SDK svn? Please, someone do that! :-D

Regards

sparrow
Back to top
View user's profile Send private message Visit poster's website
jbit
Site Admin


Joined: 28 May 2005
Posts: 293
Location: København, Danmark

PostPosted: Mon Jul 10, 2006 9:47 am    Post subject: Reply with quote

Fixed in SVN revision 1330
Back to top
View user's profile Send private message Visit poster's website
Polo35



Joined: 09 Apr 2006
Posts: 25

PostPosted: Tue Jul 11, 2006 7:13 am    Post subject: Reply with quote

jbit wrote:
Fixed in SVN revision 1330

Great.

Thanks jbit. ;)

Best regards

Polo
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