PDA

View Full Version : Create Mountable Disk Image on intel Mac



vishal.chauhan
8th January 2007, 07:45
Hi All,

I m using qt 4.2.2 on my Mac Intel.
I have a code in which I am creating disk Image by reading the disk sector.This code is working properly on my Power Pc but when I use this Method on my Intel mac then it is giving the message that the disk is not mountable when I double click on the disk Image.

If any body know whats is the problem with this on my Mac Intel then plz tell me.

Thanks.

e8johan
8th January 2007, 08:52
It could be an issue of the endianess of the processor. PPC and Intel have different endianess so if you do not write your sector byte by byte you will probably end up with different results depending on the platform that you are using.

vishal.chauhan
8th January 2007, 10:09
Thanks .

But I donot know how to solve this.
I m using this code.

for(Counter = SectorReadStart; Counter < lTotalSectorsInDrive; Counter=Counter+1024)
{

if(TotalSectorsForImage>1024)
SizeToRead=1024*512;
else
SizeToRead=TotalSectorsForImage*512;
memset(pBuff,0x00,1024*512);

if(ReadDisk(DiskName, Counter, pBuff,SizeToRead ) != SizeToRead)
{
unsigned long dw = 0;
for(dw = 0; dw < 1024; dw++)
ReadDisk(DiskName, Counter+dw, pBuff+dw*512,512) ;
}

TotalSectorsForImage -= 1024;
fwrite((void*)pBuff,SizeToRead,1,hFileHandle);
}

where ReadDisk is

unsigned int ReadDisk(char *DriveName,unsigned long SectNo,unsigned char *Buffer, unsigned int Size)
{

FILE *pFile = NULL;
int fileDescriptor;
ssize_t numBytes;

fileDescriptor = open ( DriveName, O_RDONLY );
lseek(fileDescriptor, (off_t) SectNo*SECTSIZE, SEEK_SET);

// copy the file into the buffer.
numBytes = read( fileDescriptor, Buffer, Size );
close(fileDescriptor);

return numBytes;
}

TotalSectorsForImage -= 1024;
fwrite((void*)pBuff,SizeToRead,1,hFileHandle);


In which I m reading the 1024 sectors at a time and writing them into the file.