PDA

View Full Version : how should I read data from file if size return is logical size of file




pallavi0703
Jun 26, 2008, 07:37 AM
Hello All,
I want to get the size of the file. So I am using function

result = FSOpenFork(&ref, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum);
result = FSGetForkSize(forkRefNum, &forkSize);
result = GetEOF(forkRefNum,&lfrksz);

both the functions returns filesize as 998 bytes but on disk file size shown is 4 KB that is 406 bytes.
forksize written is logical size , but how should I read the data from file. I am using. I could not understand that how should I treat the logical size, if data stored in file is serial bytes.
forkData =(void *)malloc(forkSize);
if (forkData != NULL)
{
Err1= FSReadFork(forkRefNum,fsFromStart,0, forkSize,&forkData, &actualCount);
}


if suppose f1.txt is
6790
8967
4035
etc.



Shogododdo
Jun 26, 2008, 12:47 PM
Firstly I assume you mean the file size stated is 4096 (4K).

The disk is probably configured to write the minimum of a disk block, which in your case is 4K is length.

Having said that, I wouldn't develop file IO code that looped around for 4k bytes to acquire the data.

You need to develop a looping structure that break out of the loop when you are given the end of file (EOF) signal.

I'm a newbie to cocoa so in low level terms I dont know the correct calls to make. However, from what I have read it seems like you need to use the methods of NSDocument to perform archiving (writing data) and unarchiving (reading data).

Shogo.

pallavi0703
Jun 26, 2008, 11:43 PM
Hello Shogododdo ,
Thanks for reply.
But what you are assuming is wrong.
physical size on disk of a file is 4 KB (406 bytes) and
logical size returned by result = FSGetForkSize(forkRefNum, &forkSize); is 998.

Shogododdo
Jun 27, 2008, 05:06 AM
Hello Shogododdo ,
Thanks for reply.
But what you are assuming is wrong.
physical size on disk of a file is 4 KB (406 bytes) and
logical size returned by result = FSGetForkSize(forkRefNum, &forkSize); is 998.

That is not 4K.

4K = 4 x 1024 = 4096 (not 406)
I was assuming there was a typo in your initial posting.

Investigate NSDocument, better still get yourself a copy of Aaron Hillegass's excellent book ... Cocoa Programming for Mac OSX.

Shogo

pallavi0703
Jun 27, 2008, 08:08 AM
Hello Shogododdo ,
Thanks for reply.
I am extremely sorry.
You may laugh on me , because I was passing different file ref and looking at another path file for its size.

Sorry for this stupid question.
Now I am getting logical file size = physical size = 406 bytes.
And I am able read file data properly.