| View previous topic :: View next topic |
| Author |
Message |
Treat
Joined: 26 Sep 2004 Posts: 16
|
Posted: Fri May 27, 2005 2:07 pm Post subject: sceIoLseek |
|
|
how does the sceIoLseek function work? i tried this
| Code: |
fd = sceIoOpen("ms0:/psp/game/myapp/thefile", O_RDONLY);
if(!fd) {
printf("file not found!\n");
return;
}
unsigned int blah;
int res = sceIoLseek(fd, 0x123, 0);
printf("sceIoLseek: %d\n", res);
sceIoRead(fd, (char*)&blah, 4);
|
output:
sceIoLseek: -7ffdfcdc
read works ok but it always reads the first 4 bytes. |
|
| Back to top |
|
 |
MindWall
Joined: 10 May 2005 Posts: 70
|
Posted: Fri May 27, 2005 2:26 pm Post subject: |
|
|
I haven't done coding in years, but aren't you specifying to read 4 bytes to start with?
sceIoRead(fd, (char*)&blah, 4); |
|
| Back to top |
|
 |
Treat
Joined: 26 Sep 2004 Posts: 16
|
Posted: Fri May 27, 2005 2:53 pm Post subject: |
|
|
| yes, but i want it to read at offset 0x123 |
|
| Back to top |
|
 |
Guest
|
Posted: Fri May 27, 2005 3:23 pm Post subject: Re: sceIoLseek |
|
|
| Treat wrote: | how does the sceIoLseek function work? i tried this
| Code: |
unsigned int blah;
int res = sceIoLseek(fd, 0x123, 0);
[b]printf("sceIoLseek: %d\n", res);[/b]
sceIoRead(fd, (char*)&blah, 4);
|
output:
sceIoLseek: -7ffdfcdc
read works ok but it always reads the first 4 bytes. |
Looks like "res" really should be unsigned. Mind changing that so it might be possible to make more sense of the return code ?
I don't know a heck of alot about reading to/from flash. But I wonder if its possible that reads/writes should be in some multiples of a block size ? |
|
| Back to top |
|
 |
Treat
Joined: 26 Sep 2004 Posts: 16
|
Posted: Fri May 27, 2005 6:05 pm Post subject: |
|
|
unsigned output is: 0x80020324
this works
| Code: |
void my_seek(int fd, int offset)
{
char c;
for(int i = 0; i < offset; ++i)
sceIoRead(fd, &c, 1);
}
|
but i rather not do it that way |
|
| Back to top |
|
 |
Guest
|
Posted: Fri May 27, 2005 6:11 pm Post subject: |
|
|
For efficiency, you might also consider reading a 512 byte chunk at a time first into a buffer, then do you program reading/seeking from that buffer. Reading one character at a time from memstick could be expensive.
Maybe I am making an assumption here that the IoRead call itself is unbuffered, and that assumption may be incorrect. Anyone know ? |
|
| Back to top |
|
 |
Vampire
Joined: 12 Apr 2005 Posts: 138
|
Posted: Fri May 27, 2005 6:34 pm Post subject: |
|
|
int sceIoLseek(int fd, long long offset, int whence);
or
s32 sceIoLseek(s32 fd, s64 offset, s32 whence); |
|
| Back to top |
|
 |
Guest
|
Posted: Fri May 27, 2005 6:42 pm Post subject: |
|
|
| OOOH! That can make a BIG difference! ;) |
|
| Back to top |
|
 |
Treat
Joined: 26 Sep 2004 Posts: 16
|
Posted: Fri May 27, 2005 6:52 pm Post subject: |
|
|
| ahhh, sweet thanks |
|
| Back to top |
|
 |
|