Quote:
Originally Posted by EmtYskY
First I create a pointer *signature= malloc(2 * sizeof(unsigned char)) and then point it to the 510 position on MBR buffer [..]
|
If set the pointer
signature to some place in some other buffer, then the address of the new malloc()ed memory is lost. This is a memory leak. You can just point
signature to
buffer+510, or read directly from buffer[510] and buffer[511] to get the checksum.
Quote:
Originally Posted by EmtYskY
[..] but It hasn't worked correctly I had only the 1st byte of the checksum.
|
You probably need to cast buffer[510] to the type of the checksum. As this is 2 bytes, you need to make sure not to read past the end of the buffer.
Probably a safer way is to transfer the bytes to an certain type using bitwise shifting. For example, if you need to read the checksum in a
unsigned int, you could do something like:
Code:
unsigned int read_chksum;
read_checksum = (buffer[511] << 8) | buffer[510];
/* switch [511] and [510] depending on endianess of the on-disk checksum*/
Hope this helps.