Page 1 of 1

Difference betweein FIO_S_ and FIO_SO_

Posted: Mon Nov 08, 2004 4:43 am
by KaylaKaze
What's the difference in these file attributes? The code I was originally using in PS2Menu-K worked fine using FIO_S_, but when I copied it over to my new project, I had to change them to FIO_SO_ to get the file attributes from the MC correctly. I'm also having a weird situation when copying a file from MC to HD, it reads only 0s with the fioRead command. For example: fioRead(mc_file, buffer, fsize) gives me fsize 0s when I fileXioWrite(hd_file, buffer, fsize) and I did a printf("%d", buffer[0]) and it printed 0 when it should be 66 so the problem must be in the read.

More info (after more testing):
the fioRead is returning 0. I'm guessing that means 0 bytes read. I filled the buffer with a dummy string before the read and it remained as the dummy string afterwards so I guessing that's the case. It's opened as O_RDONLY so I don't see why it shouldn't be reading.

Posted: Mon Nov 08, 2004 5:45 am
by pixel
people might correct me if I'm wrong, but, FIO_SO_* attributes are for IOMAN only. The FIO_S_* attributes should be used when working with IOMANX.

Posted: Mon Nov 08, 2004 3:12 pm
by KaylaKaze
I'm using IOMANX. Maybe it's the other way around. All the core modules are the same as the ones used in ps2menu. But in the copy function, when I do an attribute check (to see if it's a directory or file for recursive copy) files come back as 0x17 and directories as 0x27 which is the SO values.

The weird thing is I have code to read from the MC (reads the icon.sys files) and that works fine but the code for reading for the copying doesn't.

Posted: Mon Nov 08, 2004 7:22 pm
by KaylaKaze
The problem seems to be in my CopyFile function since the FileRead and FileWrite functions work fine (FileRead and FileWrite are part of a set of functions that allow for transparent file handling so you don't have to know whether you nead fileXio or fio commands). Anyone see anything wrong with this copy routine?

Code: Select all

int CopyFile(u8* infile, u8* outfile, int attr)
{
	FILE_HANDLE in, out;
	u8* buffer;
	in=FileOpen(infile, O_RDONLY);
	out=FileOpen(outfile, O_CREAT|O_WRONLY);
	int bytesread;
	if &#40;&#40;in.id<0&#41; || &#40;out.id<0&#41;&#41;
	&#123;
		printf&#40;"Error opening file\n"&#41;;
	&#125;
	int fsize=FileLseek&#40;&in, 0, SEEK_END&#41;;
	int csize;
	printf&#40;"Copying %d bytes from %s to %s.\n", fsize, infile, outfile&#41;;
	buffer=malloc&#40;fsize&#41;;
	sprintf&#40;buffer,"testing\0"&#41;;
	csize=fsize;
	if &#40;buffer==NULL&#41;
		&#123;
			printf&#40;"File too big. Copying in 32K chunks\n"&#41;;
			buffer=malloc&#40;32768&#41;;
			csize=32768;
			if &#40;buffer==NULL&#41;
				&#123;
					printf&#40;"Unable to allocate 32K.\n"&#41;;
					FileClose&#40;&in&#41;;FileClose&#40;&out&#41;;return&#40;0&#41;;
				&#125;
		&#125;
	while &#40;csize<=fsize&#41;
	&#123;
		bytesread=FileRead&#40;&in, buffer, csize&#41;;
		printf&#40;"%d bytes read\n",bytesread&#41;;
		//printf&#40;"%s\n",buffer&#41;;
		printf&#40;"%d bytes written\n",FileWrite&#40;&out, buffer, bytesread&#41;&#41;;
		fsize-=csize;
	&#125;
	
	if &#40;fsize>0&#41;
	&#123;
		FileRead&#40;&in, buffer, fsize&#41;;
		FileWrite&#40;&out, buffer, fsize&#41;;
	&#125;
	free&#40;buffer&#41;;
	FileClose&#40;&in&#41;;
	FileClose&#40;&out&#41;;
	
	return 1;	
&#125;

Posted: Mon Nov 08, 2004 7:36 pm
by pixel
Maybe you just found out some bug in the ps2sdk. I'll try to look a bit into that problem.

Posted: Tue Nov 09, 2004 6:13 am
by pukko
int fsize=FileLseek(&in, 0, SEEK_END);
Think you need to rewind the tape..

Posted: Tue Nov 09, 2004 6:17 am
by pixel
Mh, right :)

Posted: Tue Nov 09, 2004 2:27 pm
by KaylaKaze
Thank you, thank you. I would NEVER have noticed that :-)