PDA

View Full Version : error for FSOpenFork




pallavi0703
Jun 24, 2008, 05:23 AM
Hello All,
In Xcode Carbon C bundel application I want to open a file and read data from it, but at runtime I am not able to make FSRef from file path. Following code I am using please tell me what changed are required in this code.



CFURLRef url ;
Boolean flag;
FSRef ref , ref2 ;
OSErr error ,result;
char *volname = NULL;
char revpath[PATH_MAX];
HFSUniStr255 dataForkName;
SInt16 forkRefNum;

volumeNameForPath("/", &volname);//user defined function to get default volume name
strcat(volname,":CFURL.txt");//now volname = "Macintosh HD:CFURL.txt" and strlen((char*)volname = 22

url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,volname,strlen((char*)volname),false);
flag = CFURLGetFSRef((CFURLRef)url , &ref);//true if success else false
//flag returned is 0 it should be 1

or

error = FSPathMakeRef(volname,&ref2,false);

result = FSGetDataForkName(&dataForkName);
if (result != noErr) {
syslog(LOG_INFO, "FSGetDataForkName() returned %d", result);
return;
}

result = FSOpenFork(&ref, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum);//result returned is -35.


Thanks & Regards,
Pallavi.



gnasher729
Jun 24, 2008, 08:13 AM
Hello All,
In Xcode Carbon C bundel application I want to open a file and read data from it, but at runtime I am not able to make FSRef from file path. Following code I am using please tell me what changed are required in this code.



CFURLRef url ;
Boolean flag;
FSRef ref , ref2 ;
OSErr error ,result;
char *volname = NULL;
char revpath[PATH_MAX];
HFSUniStr255 dataForkName;
SInt16 forkRefNum;

volumeNameForPath("/", &volname);//user defined function to get default volume name
strcat(volname,":CFURL.txt");//now volname = "Macintosh HD:CFURL.txt" and strlen((char*)volname = 22

url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,volname,strlen((char*)volname),false);
flag = CFURLGetFSRef((CFURLRef)url , &ref);//true if success else false
//flag returned is 0 it should be 1

or

error = FSPathMakeRef(volname,&ref2,false);

result = FSGetDataForkName(&dataForkName);
if (result != noErr) {
syslog(LOG_INFO, "FSGetDataForkName() returned %d", result);
return;
}

result = FSOpenFork(&ref, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum);//result returned is -35.

Read the documentation for CFURLCreateFromFileSystemRepresentation. The comment for the second parameter says "The character bytes to convert into a CFURL object. This should be the path as you would use in POSIX function calls."

pallavi0703
Jun 25, 2008, 03:03 AM
Hello gnasher729,
Now I am using posix file path ,
but for reading file every time new error code is returned like -4628 ,-4132,-5380 etc.

ByteCount requestCount;
void *buffer;
ByteCount *actualCount;

result = FSOpenFork(&ref, dataForkName.length, dataForkName.unicode, fsRdPerm, &forkRefNum);// returns noErr
if(result == noErr) {

buffer = malloc(1024);
requestCount = 128;
Err1= FSReadFork(forkRefNum,fsFromStart,0, requestCount,&buffer, &actualCount);//program get hanged
}