raw reading hard disk on mac

Discussion in 'Mac Programming' started by naveen, Jan 21, 2005.

  1. macrumors member

    Joined:
    Oct 27, 2004
    #1
    Hi

    I want to raw read the hard disk sector on mac using xcode c++ project.I am using following code for that

    #define _LARGEFILE64_SOURCE //FOR READING LARGE CAPACITY HARD disk
    #define _FILE_OFFSET_BITS 64
    #define _LARGEFILE_SOURCE

    #include<stdio.h>
    #include<stdlib.h>

    FILE * pFile;
    unsigned char * buffer[512];

    pFile = fopen ( "/dev/disk1" , "rb" );
    if (pFile==NULL) exit (1);


    fseeko(pFile ,(off_t)1826*512, SEEK_SET);

    // copy the file into the buffer.
    fread (buffer,512,1,pFile);

    /*** the whole file is loaded in the buffer. ***/
    pFile = fopen ("myfile.doc" , "wb+");
    fwrite (buffer , 512 ,1, pFile);
    fclose (pFile);

    But in some cases i found that readed sector have different values that actual values. Plz if there is any other function for reading and writing or other way then plz help me to sought out my problem.
     
  2. macrumors newbie

    Joined:
    Aug 5, 2003
    #2
    I'm in a rush as I write this, but you might want to look into the xnu system call meta_bread() to read each block into a buf, set a semaphore, modify it, unlock it, then sync it back to disk. When I get more time I'll post some details.
     

Share This Page