error for FSOpenFork

Discussion in 'Mac Programming' started by pallavi0703, Jun 24, 2008.

  1. pallavi0703 macrumors newbie


    Dec 12, 2007
    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


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

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

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

    Thanks & Regards,
  2. gnasher729 macrumors P6


    Nov 25, 2005
    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."
  3. pallavi0703 thread starter macrumors newbie


    Dec 12, 2007
    now error for FSReadFork

    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

Share This Page