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 

Strange problem with fileio

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



Joined: 29 May 2005
Posts: 214

PostPosted: Fri Sep 01, 2006 10:19 pm    Post subject: Strange problem with fileio Reply with quote

hello, i have a strange problem at using the fileio sample from the pspsdk, the filesystem dump part. This code looks really simple but i dont understand why i can dump a filesystem form flash0 without problem but not from ms0. Some help would be appreciated !

Also note that im not actually writing any files with this code what minimise the possible errors.

For exemple this code will work without problem
Code:
dump_filesystem("fatms0:/VSH/", "ms0:/plop/test");


But this one hang the psp directly without any printf outpout :
Code:
dump_filesystem("ms0:/IRSHELL/", "ms0:/plop/test");


I'v tried with a lot of possibility and it seems that if i choose ms0 or fatms0 for the source, it will hang the psp immediatly


Here is the main code routine :


Code:

/* Build a path, append a directory slash if requested */
void build_path(char *output, const char *root, const char *path, int append)
{
   while(*root != 0)
   {
      *output++ = *root++;
   }

   if(*(root-1) != '/')
   {
      *output++ = '/';
   }

   while(*path != 0)
   {
      *output++ = *path++;
   }
   if(append)
      *output++ = '/';

   *output++ = 0;
}

/* Dump a filing system */
void dump_filesystem(const char *root, const char *write_loc)
{
   int dfd;
   char next_root[256];
   char next_write[256];
   char mytest[512];

   sceIoMkdir(write_loc, 0777);

   dfd = sceIoDopen(root);
   if(dfd > 0)
   {
      SceIoDirent dir;

      while(sceIoDread(dfd, &dir) > 0)
      {
         if(dir.d_stat.st_attr & FIO_SO_IFDIR)
         {
            if(dir.d_name[0] != '.')
            {
               build_path(next_write, write_loc, dir.d_name, 0);
               build_path(next_root, root, dir.d_name, 1);

               printf("next_root is %s\n",next_root);
               printf("next_write is %s\n",next_write);

               dump_filesystem(next_root, next_write);
            }
         }
         else
         {         
            //printf("root is %s\n",root);
            //printf("write_loc is %s\n",write_loc);
            //printf("dir.d_name is %s\n",dir.d_name);

            //write_file(root, write_loc, dir.d_name);
            strcpy(mytest,"cp ");
            strcat(mytest,root);
            strcat(mytest,dir.d_name);
            strcat(mytest," ");
            strcat(mytest,write_loc);

            printf("%s\n",mytest);
         }
      }
      sceIoDclose(dfd);
   }
}
Back to top
View user's profile Send private message
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Sat Sep 02, 2006 1:28 am    Post subject: Reply with quote

I have finaly found the problem, "SceIoDirent dir;" must be put outside the function and so its possible to copy from ms to ms.
Maybe it could be usefull.
Back to top
View user's profile Send private message
mbf



Joined: 18 Aug 2006
Posts: 55

PostPosted: Sat Sep 02, 2006 3:25 am    Post subject: Reply with quote

Do I miss something it doesn't make sense? Why would moving the SceIoDirent declaration outside of the function fix the problem?

Unless... your stack is very small and the recursive calls to dump_filesystem use it up quickly?
Back to top
View user's profile Send private message
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Sat Sep 02, 2006 4:17 am    Post subject: Reply with quote

Yes i know its why i was really disapointed with my problem, i'v tested a lot of combinations for hours, and for sure moving this declaration outside the code make it work with 100% succes. What is strange also is that it worked from flash0 with the sceiodirent declare in the function but not from ms0, so i dont see why it would be a stack problem . You can test the code wich is easy to test.
Back to top
View user's profile Send private message
johnmph



Joined: 23 Jul 2005
Posts: 119

PostPosted: Sat Sep 02, 2006 9:03 am    Post subject: Reply with quote

Cpasjuste wrote:
Yes i know its why i was really disapointed with my problem, i'v tested a lot of combinations for hours, and for sure moving this declaration outside the code make it work with 100% succes. What is strange also is that it worked from flash0 with the sceiodirent declare in the function but not from ms0, so i dont see why it would be a stack problem . You can test the code wich is easy to test.


You can also define it as static in function.

It's because you give a pointer with sceIoDread and sceIoDread uses this pointer to know the start to seek dir and after he writes the next dir in the variable (*pointer).

If you don't save this variable, each time you call function, you reinitialize this variable and you take the first dir.
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sat Sep 02, 2006 12:46 pm    Post subject: Reply with quote

This is an FAQ. Search the forums for SceIoDirent. You need to memset it to 0 before using it.

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
Cpasjuste



Joined: 29 May 2005
Posts: 214

PostPosted: Sat Sep 02, 2006 6:24 pm    Post subject: Reply with quote

Many thanks for you help guys, i understand the problem now.
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 -> PSP 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