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 ((in.id<0) || (out.id<0))
{
printf("Error opening file\n");
}
int fsize=FileLseek(&in, 0, SEEK_END);
int csize;
printf("Copying %d bytes from %s to %s.\n", fsize, infile, outfile);
buffer=malloc(fsize);
sprintf(buffer,"testing\0");
csize=fsize;
if (buffer==NULL)
{
printf("File too big. Copying in 32K chunks\n");
buffer=malloc(32768);
csize=32768;
if (buffer==NULL)
{
printf("Unable to allocate 32K.\n");
FileClose(&in);FileClose(&out);return(0);
}
}
while (csize<=fsize)
{
bytesread=FileRead(&in, buffer, csize);
printf("%d bytes read\n",bytesread);
//printf("%s\n",buffer);
printf("%d bytes written\n",FileWrite(&out, buffer, bytesread));
fsize-=csize;
}
if (fsize>0)
{
FileRead(&in, buffer, fsize);
FileWrite(&out, buffer, fsize);
}
free(buffer);
FileClose(&in);
FileClose(&out);
return 1;
}
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 :-)