My bugs or maybe PSPSDK's bugs... sceIoDread and Callbacks

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

My bugs or maybe PSPSDK's bugs... sceIoDread and Callbacks

Post by Shazz »

Hello again...

Not sure that's not my bugs but as I did not find why... maybe somebody will tell me...

1. sceIoDread

I use it to retrieve FS informations (is it a DIR, a FILE,...) and each time the SceIoDirent.d_stat.st_mode access mode is wrong :
- 0x11FF for a dir instead of FIO_S_IFDIR (0x2000)
- 0x21FF for a file instead of FIO_S_IFREG;(0x1000)
So I have to patch them manually :(

Here is the piece of code :

Code: Select all

SceIoDirent Lfiles[MAXDIRNUM]; 
...
while&#40;&#40;ret>0&#41; && &#40;Lfiles_num<MAXDIRNUM&#41;&#41; &#123;
	    	ret = sceIoDread&#40;fd, &Lfiles&#91;Lfiles_num&#93;&#41;;

	    	//manual patch
	        //printf&#40;"before&#91;%s&#93; &#58; %x\n", Lfiles&#91;Lfiles_num&#93;.d_name, Lfiles&#91;Lfiles_num&#93;.d_stat.st_mode&#41;;
	    	if&#40;Lfiles&#91;Lfiles_num&#93;.d_stat.st_mode == 0x11FF&#41; Lfiles&#91;Lfiles_num&#93;.d_stat.st_mode = FIO_S_IFDIR;
	    	if&#40;Lfiles&#91;Lfiles_num&#93;.d_stat.st_mode == 0x216D&#41; Lfiles&#91;Lfiles_num&#93;.d_stat.st_mode = FIO_S_IFREG;
	    	if&#40;Lfiles&#91;Lfiles_num&#93;.d_stat.st_mode == 0x21FF&#41; Lfiles&#91;Lfiles_num&#93;.d_stat.st_mode = FIO_S_IFREG;
	    	//printf&#40;"after&#91;%s&#93; &#58; %x\n", Lfiles&#91;Lfiles_num&#93;.d_name, Lfiles&#91;Lfiles_num&#93;.d_stat.st_mode&#41;;

		    if &#40;Lfiles&#91;Lfiles_num&#93;.d_name&#91;0&#93; == '.'&#41; continue;
    		if &#40;ret>0&#41; Lfiles_num++;
&#125;
I searched in the forums, I only found something about memseting the SceIoDirent, is it the issue ?

2. Exit callback

I use the standard pspsdk code to set the exit callback and blablabla... it works perfect when I run my code in user mode but in kernel mode the X button has no action on the Exit validation (the O works), exactly like in the PSP MediaCenter 0.87, X doesn't work too.

Any idea ?

I got this issue in 2 different apps... in the same context.
- TiTAN Art Division -
http://www.titandemo.org
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

I have a Japanese PSP and I can always only use the O for confirming Exit. It's the default 'confirm' button. This is different for the US version, where the X button is default. A bit confusing when I for instance play the US version of Wipeout on the Japanese PSP, as that game uses the X button for confirm as per the US standards.

Do you have a US PSP or a Jap PSP?
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

US 1.5
X : validate Exit (no effect in kernel mode)
O : Cancel exit (always works)
- TiTAN Art Division -
http://www.titandemo.org
Arwin
Posts: 426
Joined: Tue Jul 12, 2005 7:00 pm

Post by Arwin »

Shazz wrote:US 1.5
X : validate Exit (no effect in kernel mode)
O : Cancel exit (always works)
Seems then that the regional settings for US are only active in user mode, which could make sense, somehow (not sure exactly how though ;). But lets assume that everything except possibly the dashboard itself is meant to run in user mode, and it makes sense.
User avatar
cwbowron
Posts: 76
Joined: Fri May 06, 2005 4:22 am
Location: East Lansing, MI
Contact:

Re: My bugs or maybe PSPSDK's bugs... sceIoDread and Callbac

Post by cwbowron »

Shazz wrote: 1. sceIoDread

I use it to retrieve FS informations (is it a DIR, a FILE,...) and each time the SceIoDirent.d_stat.st_mode access mode is wrong :
- 0x11FF for a dir instead of FIO_S_IFDIR (0x2000)
- 0x21FF for a file instead of FIO_S_IFREG;(0x1000)
So I have to patch them manually :(
I have the same issue with my file selection code, but I do not know why it is happening.
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

Concerning sceIoDread, thnaks cwbowron for confirming the issue... so there is something....

as a work around, I saw that Adresd in his PSPMC used the d_attr to identify directories and files :

Code: Select all

&#40;direntt->d_stat.st_attr & 0x10&#41; == 0x10&#41; &#123; // directory
&#40;direntt->d_stat.st_attr & 0x20&#41; == 0x20&#41; && &#40;direntt->d_name&#91;0&#93; != 0&#41;&#41; &#123; // File
But....

Concerning the exit Callback, I don't know really what to think, it is obviously due to the fact I'm in kernel mode but.... even where to look at...
I'm going to disassemble the kernel call to see what's happening...
- TiTAN Art Division -
http://www.titandemo.org
cage
Posts: 6
Joined: Wed Jul 13, 2005 5:50 pm

Post by cage »

I got the same problems and I ran some tests on files and directories. It turns out, that there is a bug in the SDK.

To decide whether it is a file or a folder you got to check the st_mode variable.
BUT you have to use the IOAccessModes for that.
from pspiofilemgr_stat.h:
...
00029 FIO_S_IFMT = 0xF000,
00031 FIO_S_IFLNK = 0x4000,
00033 FIO_S_IFDIR = 0x2000, // wrong
00035 FIO_S_IFREG = 0x1000, // wrong
...

Furthermore the entries for folders and regular files are switched =(
So to check for a folder you do something like

SceIoDirent file;
// check for folder
if (FIO_S_IFREG & (file.d_stat.st_mode & FIO_S_IFMT)) {
...
}

or you redifne the stuff if it is too anoying for ya.

I noticed that I only cant exit a program if something turned wrong (some errors occured), in any other case it works ok. (jap PSP, v1.5)
Any information on that would be great...
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

The FIO values come from the PS2, and they were meant more as placeholders. Sorry for the confusion. A patch would to fix them would be appreciated :).

As far as the exit callback goes, the thread that registers the callback must be a usermode thread. So just pass PSP_THREAD_ATTR_USER to sceKernelCreateThread() and you should be fine.
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

mrbrown wrote: As far as the exit callback goes, the thread that registers the callback must be a usermode thread. So just pass PSP_THREAD_ATTR_USER to sceKernelCreateThread() and you should be fine.
Huummm.. So I changed to

Code: Select all

int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;
	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread,
				     0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;
	return thid;
&#125;
And when I pushed the X button to validate the exit, I've got the Please Wait message.... freezes 10s then power off...

So I tried in user mode using :

Code: Select all

PSP_MAIN_THREAD_ATTR&#40;THREAD_ATTR_USER&#41;;

__attribute__ &#40;&#40;constructor&#41;&#41;
void loaderInit&#40;&#41;
&#123;
    pspKernelSetKernelPC&#40;&#41;;
    pspSdkInstallNoDeviceCheckPatch&#40;&#41;;
    //pspDebugInstallKprintfHandler&#40;NULL&#41;;
&#125;
And then it 'works'....(with a funny message: "prfile.mod.c:...oem... not exit, reboot start in debug) and exit

But as I have to be in kernel mode to use sceKernelLoadExec, not really a solution for the moment :D
- TiTAN Art Division -
http://www.titandemo.org
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

OK, found,

While in kernel mode :
1. Set the callback thread in user mode while creating it
2. Detect that the exit_callback is called (global var)
3. In your main loop (in kernel mode), call sceGameExit() if the callback is detected to kill the kernel thread

ouch :D
- TiTAN Art Division -
http://www.titandemo.org
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

About the SceIoDirent usage, before doing a patch, I tested some examples and I saw :
- the usage of SceIoDirent ->d_stat.st_attr & FIO_SO_IFREG/FIO_SO_IFDIR is not possible with an UMD (always 0)
- SceIoDirent ->d_stat.st_mode should be used, as said Cage like that :

Code: Select all

// check for a file
if &#40;FIO_S_IFREG & &#40;SceIoDirent .d_stat.st_mode & FIO_S_IFMT&#41;&#41;
// check for a folder
if &#40;FIO_S_IFDIR & &#40;SceIoDirent .d_stat.st_mode & FIO_S_IFMT&#41;&#41; 
Maybe everybody already knew it, not my case.... that's the macros I never saw before :
// File mode checking macros
#define FIO_S_ISLNK(m) (((m) & FIO_S_IFMT) == FIO_S_IFLNK)
#define FIO_S_ISREG(m) (((m) & FIO_S_IFMT) == FIO_S_IFREG)
#define FIO_S_ISDIR(m) (((m) & FIO_S_IFMT) == FIO_S_IFDIR)

Shame on me :D

so here is the patch I propose (simply invert #define)

Note :
I have some doubts about those one too... need to check

Code: Select all

	/** User access rights mask */
	FIO_S_IRWXU		= 0x01C0,	
	/** Read user permission */
	FIO_S_IRUSR		= 0x0100,
	/** Write user permission */
	FIO_S_IWUSR		= 0x0080,
	/** Execute user permission */
	FIO_S_IXUSR		= 0x0040,	

	/** Group access rights mask */
	FIO_S_IRWXG		= 0x0038,	
	/** Group read permission */
	FIO_S_IRGRP		= 0x0020,
	/** Group write permission */
	FIO_S_IWGRP		= 0x0010,
	/** Group execute permission */
	FIO_S_IXGRP		= 0x0008,
patch:

Code: Select all

--- pspiofilemgr_stat.h	2005-07-20 09&#58;37&#58;12.287260600 +0200
+++ pspiofilemgr_stat2.h	2005-07-25 15&#58;35&#58;39.661769400 +0200
@@ -30,9 +30,9 @@
 	/** Symbolic link */
 	FIO_S_IFLNK		= 0x4000,
 	/** Directory */
-	FIO_S_IFDIR		= 0x2000,
+	FIO_S_IFDIR		= 0x1000,
 	/** Regular file */
-	FIO_S_IFREG		= 0x1000,
+	FIO_S_IFREG		= 0x2000,
 
 	/** Set UID */
 	FIO_S_ISUID		= 0x0800,
- TiTAN Art Division -
http://www.titandemo.org
Post Reply