how do you read mbr and partition table from the hard disk and edit it? I want to know exactly how do the partition r开发者_如何学编程ecovery softwares work?
Get the sources of fdisk.
Please see here on what MSDN has to say about 'CreateFile', somewhere down on the page titled 'Physical Disks and Volumes', and see on the KB about this. You would have to make calls to 'DeviceIoControl'.
The partition and MBR is part of the boot sector found at the first sector of the disk, i.e. sector 0.
Be careful! Messing with the partitions will end up losing the data. Don't say you weren't warned!
If you want to access the disk physically prior to Windows starting up, look at Ralph Brown's interrupt list for Int 0x13 (hexadecimal) to do direct Disk I/O. There are some excellent open source software such as 'fdisk', 'cfdisk', 'gnuparted' that will explain how it works. - Use the source luke...
Start by reading up on BIOS interrupt calls, e.g. here: http://en.wikipedia.org/wiki/INT_13
BIOS is probably the closest access you can normally get to hardware - it lives even below the OS and provides, amongst other things, raw disk access.
精彩评论