Get name of File from file descriptor.

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

Moderators: cheriff, TyRaNiD

Post Reply
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Get name of File from file descriptor.

Post by Torch »

If I have a file descriptor fd that was from sceIoOpen, how do I get the name of the file associated with fd? Or name of the Directory if the file descriptor is from sceIoDopen.
Dariusc123456
Posts: 388
Joined: Tue Aug 12, 2008 12:46 am

Post by Dariusc123456 »

Torch, I just want to ask what are you trying todo?
ctszy
Posts: 18
Joined: Sat Apr 12, 2008 11:18 pm

Post by ctszy »

I think the best way is to hook the sceIoOpen|sceIoDopen function.

also, if you're just looking for filename, there's another solution:
Find the uidblock of your fd,
(the uidblock of latest opened fd is the next of the one with the name of "Iob", you may reopen the descriptor to get it.)
and uidname is the filename. if your descriptor is opened by sceIoDopen, then uidname would be the full path.
(However, the length is limited by 27 chars.)
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

ctszy wrote:I think the best way is to hook the sceIoOpen|sceIoDopen function.

also, if you're just looking for filename, there's another solution:
Find the uidblock of your fd,
(the uidblock of latest opened fd is the next of the one with the name of "Iob", you may reopen the descriptor to get it.)
and uidname is the filename. if your descriptor is opened by sceIoDopen, then uidname would be the full path.
(However, the length is limited by 27 chars.)
I've already hooked the Open/Dopen functions. So I *could* maintain a list of fd's and assoiciated files names. But that would be a waste of memory. I'll try getting the UID block.

What did you mean its limited by 27 chars? The name is a char * in the uid block struct.
ctszy
Posts: 18
Joined: Sat Apr 12, 2008 11:18 pm

Post by ctszy »

well, maybe I got it wrong..
BTW, normally there wouldn't be more than 0x10 fd's opening at the same time, and the length limit of full path in FAT is 255.
so I don't think 4K will be a great waste, even in Kernel mode;)
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

ctszy wrote:well, maybe I got it wrong..
BTW, normally there wouldn't be more than 0x10 fd's opening at the same time, and the length limit of full path in FAT is 255.
so I don't think 4K will be a great waste, even in Kernel mode;)
Only 16 fs's ??? That sounds wrong. I know that most other stuff like power callbacks etc are limited to 16, but fd's? That sounds wrong.
ctszy
Posts: 18
Joined: Sat Apr 12, 2008 11:18 pm

Post by ctszy »

Torch wrote:Only 16 fs's ??? That sounds wrong. I know that most other stuff like power callbacks etc are limited to 16, but fd's? That sounds wrong.
I didnt mean it's limited to 16.. I just mean in most cases there won't be too many file descriptors working at the same time, that number was just an example.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

sceKernelGetUIDcontrolBlock returns SCE_KERNEL_ERROR_UNKNOWN_UID for all the UIDs I receive in sceIoDread.
ctszy
Posts: 18
Joined: Sat Apr 12, 2008 11:18 pm

Post by ctszy »

Torch wrote:sceKernelGetUIDcontrolBlock returns SCE_KERNEL_ERROR_UNKNOWN_UID for all the UIDs I receive in sceIoDread.
well, if you output the fd given by sce functions you'll see it is not the "absolute" UID.
For example, you may get a fd with value of 0x05, but in fact its UID is 0x04E3EA21.
(different each time, given by system)
SceUID type doesn't mean it is a real UID.

(there's one exception: when vshcontrol module loads file in /ISO and /GAME I saw it uses the real UID.)

That's why I mentioned how to get the real one on above :)
You can use PSPLINK to output a list of UIDs and take a look, that will help
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

ctszy wrote: That's why I mentioned how to get the real one on above :)
You can use PSPLINK to output a list of UIDs and take a look, that will help
But int sceIoReopen requires a file name AND an old fd ?? What am I supposed to do?
ctszy
Posts: 18
Joined: Sat Apr 12, 2008 11:18 pm

Post by ctszy »

Torch wrote: But int sceIoReopen requires a file name AND an old fd ?? What am I supposed to do?
Oh ... yes, sorry I forgot you cannot reopen it without the filename :<
I used this method in a specific example that works for every FIO so it just didn't matter... It's my negligence, sorry again.
So just do the hook then :) It is also the most stable solution.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

There is a hard limit (or there used to be) on open fd's on the memory stick, I think it was around 16 or so :)
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

I'm currently keeping track of all the Dopen fd's created. Do you know a better way to find out the 'path' if you simply have the fd ?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Unfortunately I don't think the kernel stores much in the way of the the actual file name as from the PSP's point of view it doesn't much care. Seems there is some stuff in the Iob UID block (not seen that one before :P) but not much. I think as pointed out the only way would be to capture it at sceIoOpen/sceIoDopen time.
Post Reply