Hello, i wrote a program to read and edit the MBR but i can't figure out how to edit CHS values. A little informtation:
the CHS address of the partition is described in 24 bits:
bits 0-7 Head
bits 8-13 Sector
bits 14-15 are last 2 bytes of cylinder
bits 16-23 Cylinder
1 2 3 4
char chs[3]; //assume that chs contains valid cylinder, head and sector
char head=chs[0];
char sect=chs[1]>>3;
short cylinder=(chs[2]<<2) | (chs[1]>>6); // is this ok?
the other problem is, how to split the 'cylinder' value into 2 bytes? I tried but... ERROR LOADING OPERATING SYSTEM...
Thank you for any help.
Are you using a char array in your code? Signed types perform shifting differently than unsigned types. For example, -128 (1000 0000b) >> 4 == -8 (1111 1000b), not 8 (0000 1000b).
If that doesn't work, try inverting your array indices, although I doubt that's the problem, what with x86 being little endian.