sceIoLseek

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

Moderators: cheriff, TyRaNiD

Post Reply
Treat
Posts: 16
Joined: Sun Sep 26, 2004 10:17 pm

sceIoLseek

Post by Treat »

how does the sceIoLseek function work? i tried this

Code: Select all

	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.
MindWall
Posts: 70
Joined: Tue May 10, 2005 4:27 pm

Post by MindWall »

I haven't done coding in years, but aren't you specifying to read 4 bytes to start with?
sceIoRead(fd, (char*)&blah, 4);
Treat
Posts: 16
Joined: Sun Sep 26, 2004 10:17 pm

Post by Treat »

yes, but i want it to read at offset 0x123
Guest

Re: sceIoLseek

Post by Guest »

Treat wrote:how does the sceIoLseek function work? i tried this

Code: Select all

	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 ?
Treat
Posts: 16
Joined: Sun Sep 26, 2004 10:17 pm

Post by Treat »

unsigned output is: 0x80020324

this works

Code: Select all

void my_seek(int fd, int offset)
{
	char c;
	for&#40;int i = 0; i < offset; ++i&#41;
		sceIoRead&#40;fd, &c, 1&#41;;
&#125;
but i rather not do it that way
Guest

Post by Guest »

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 ?
Vampire
Posts: 138
Joined: Tue Apr 12, 2005 8:16 am

Post by Vampire »

int sceIoLseek(int fd, long long offset, int whence);

or

s32 sceIoLseek(s32 fd, s64 offset, s32 whence);
Guest

Post by Guest »

OOOH! That can make a BIG difference! ;)
Treat
Posts: 16
Joined: Sun Sep 26, 2004 10:17 pm

Post by Treat »

ahhh, sweet thanks
Post Reply