Strange problem with fileio

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Strange problem with fileio

Post by Cpasjuste »

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: Select all

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

Code: Select all

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: Select all

/* 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);
	}
}
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

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.
mbf
Posts: 55
Joined: Fri Aug 18, 2006 7:43 pm

Post by mbf »

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?
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

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.
johnmph
Posts: 119
Joined: Sat Jul 23, 2005 11:48 pm

Post by johnmph »

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.
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

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

Jim
Cpasjuste
Posts: 214
Joined: Sun May 29, 2005 8:28 am

Post by Cpasjuste »

Many thanks for you help guys, i understand the problem now.
Post Reply