Writing files and reading directories

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

Moderators: cheriff, TyRaNiD

Post Reply
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Writing files and reading directories

Post by Pirata Nervo »

I made a prx which runs in game (not from game.txt) and I made a function to read a directory. The MS light blinks for a long period of time but does not read anything.

This does not create any file:

Code: Select all

FILE* outFile = fopen("ms0:/test2.jpg", "wb");
fclose(outFile);
I made a different prx which runs in game (from game.txt) and the only thing it does is create a file and it works perfectly.

Both files run in kernel mode

Are there any restrictions for PRX files when running in game but not as seplugins from game.txt ?
Image
Upgrade your PSP
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

have you test the natif API like fd = sceIoOpen("device:/path/to/file", O_WRONLY|O_CREAT, 0777) instead of the one got from the glibc
Meaby some stuf on the runtime got into trouble when running in game
context
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Yeah I've just tested this:

Code: Select all

int fd = sceIoOpen("ms0:/test.txt", PSP_O_CREAT | PSP_O_WRONLY, 0777);
char data[100];
sprintf(data, "sakdfsngfdg");
sceIoWrite(fd, data, strlen(data));
sceIoClose(fd);
and as it happened with the read directory function the ms led blinks for a long period of time but this time it created the file but did not write anything.
Image
Upgrade your PSP
Onii
Posts: 40
Joined: Sun Oct 05, 2008 1:07 pm

Post by Onii »

Check your return codes to see what one is failing.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Ok so here are the returned values.

Code: Select all

int fd = sceIoOpen("ms0:/test.txt", PSP_O_CREAT | PSP_O_WRONLY, 0777);
Returns a positive number. (so this one is working) Takes at least 10 seconds to create the file.

Code: Select all

int bw = sceIoWrite(fd, data, sizeof(data));
Returns 80220087 / -214525589 - Error

Code: Select all

int close = sceIoClose(fd);
Returns 0 so it closed the file successfully but just like with sceIoOpen, it blinks for at least 10 seconds.

I think this is due to the fact that I am "pausing" the game

Edit:
Just tested before starting the main thread in my prx and it wrote the file with success. So I guess the problem is I am pausing the game. I need to write the file after resuming the game to confirm this

Edit 2: confirmed
Image
Upgrade your PSP
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

If you're using threads, I think you forgot that the PSP uses COOPERATIVE multitasking. Threads don't run unless you call system routines that switch threads. The most common way to allow other threads to run is to call sceKernelDelayThread(). Calling blocking functions will also allow other threads to run.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

I do have sceKernelDelayThread in the while loop.
I tried writing the file from the main thread and did not work. The same happened when writing a file from another thread
Image
Upgrade your PSP
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Do you have the 3.71 fatmsmod.prx for 5.00 patch installed by any chance?

I did some tests and I'm having problems with some IO functions with it installed.
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

Nope neither 1.50 kernel addon
Image
Upgrade your PSP
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

Can you post somewhere a EBOOT so we can test your code against
different psp and different kind of memory stick.
Do you have perform some test regression like testing your code on 3.52M33,3.90M33, etc ......
Pirata Nervo
Posts: 409
Joined: Tue Oct 09, 2007 4:22 am

Post by Pirata Nervo »

It's not an eboot, it's a prx and I already said the problem was I was "pausing" the game thread. Now that I am not pausing anymore it works perfectly
Image
Upgrade your PSP
Post Reply