Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

naveen

macrumors member
Original poster
Oct 27, 2004
43
0
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.
 

fintler

macrumors newbie
Aug 5, 2003
13
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.