Get name of File from file descriptor.
Get name of File from file descriptor.
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.
-
- Posts: 388
- Joined: Tue Aug 12, 2008 12:46 am
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.)
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.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.)
What did you mean its limited by 27 chars? The name is a char * in the uid block struct.
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 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;)
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.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.
well, if you output the fd given by sce functions you'll see it is not the "absolute" UID.Torch wrote:sceKernelGetUIDcontrolBlock returns SCE_KERNEL_ERROR_UNKNOWN_UID for all the UIDs I receive in sceIoDread.
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
Oh ... yes, sorry I forgot you cannot reopen it without the filename :<Torch wrote: But int sceIoReopen requires a file name AND an old fd ?? What am I supposed to do?
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.
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.