读取bochs硬盘分区信息的C程序
时间:2006-11-27 来源:mishuang
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define OFFSET 446
struct boot_info
{
unsigned char bootind;
unsigned char start_head;
unsigned char start_sec;
unsigned char start_cyl;
unsigned char sysind;
unsigned char last_head;
unsigned char last_sec;
unsigned char last_cyl;
unsigned int lowsec;
unsigned int size;
} record;
void print()
{
printf("bootind\t\t%u\t0x%x\n", record.bootind, record.bootind);
printf("start_head\t%u\t0x%x\n", record.start_head, record.start_head);
printf("start_sec\t%u\t0x%x\n", record.start_sec, record.start_sec);
printf("start_cyl\t%u\t0x%x\n", record.start_cyl, record.start_cyl);
printf("sysind\t\t%u\t0x%x\n", record.sysind, record.sysind);
printf("last_head\t%u\t0x%x\n", record.last_head, record.last_head);
printf("last_sec\t%u\t0x%x\n", record.last_sec, record.last_sec);
printf("last_cyl\t%u\t0x%x\n", record.last_cyl, record.last_cyl);
printf("lowsec\t\t%u\t0x%x\n", record.lowsec, record.lowsec);
printf("size\t\t%u\t0x%x\n", record.size, record.size);
}
int main(int argc, char *argv[])
{
int i, fd;
fd = open(argv[1], O_RDWR);
lseek(fd, OFFSET, SEEK_SET);
for (i = 0; i < 4; i ++) {
read(fd, &record, sizeof(record));
print();
if (i != 3)
printf("\n");
}
close(fd);
return EXIT_SUCCESS;
}
mishuang@msh:~/setup/bochs> read_mbr ./c.img
bootind 128 0x80
start_head 1 0x1
start_sec 1 0x1
start_cyl 0 0x0
sysind 129 0x81
last_head 15 0xf
last_sec 63 0x3f
last_cyl 121 0x79
lowsec 63 0x3f
size 122913 0x1e021
bootind 0 0x0
start_head 0 0x0
start_sec 1 0x1
start_cyl 122 0x7a
sysind 129 0x81
last_head 15 0xf
last_sec 63 0x3f
last_cyl 243 0xf3
lowsec 122976 0x1e060
size 122976 0x1e060
bootind 0 0x0
start_head 0 0x0
start_sec 1 0x1
start_cyl 244 0xf4
sysind 5 0x5
last_head 15 0xf
last_sec 127 0x7f
last_cyl 108 0x6c
lowsec 245952 0x3c0c0
size 121968 0x1dc70
bootind 0 0x0
start_head 0 0x0
start_sec 0 0x0
start_cyl 0 0x0
sysind 0 0x0
last_head 0 0x0
last_sec 0 0x0
last_cyl 0 0x0
lowsec 0 0x0
size 0 0x0
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define OFFSET 446
struct boot_info
{
unsigned char bootind;
unsigned char start_head;
unsigned char start_sec;
unsigned char start_cyl;
unsigned char sysind;
unsigned char last_head;
unsigned char last_sec;
unsigned char last_cyl;
unsigned int lowsec;
unsigned int size;
} record;
void print()
{
printf("bootind\t\t%u\t0x%x\n", record.bootind, record.bootind);
printf("start_head\t%u\t0x%x\n", record.start_head, record.start_head);
printf("start_sec\t%u\t0x%x\n", record.start_sec, record.start_sec);
printf("start_cyl\t%u\t0x%x\n", record.start_cyl, record.start_cyl);
printf("sysind\t\t%u\t0x%x\n", record.sysind, record.sysind);
printf("last_head\t%u\t0x%x\n", record.last_head, record.last_head);
printf("last_sec\t%u\t0x%x\n", record.last_sec, record.last_sec);
printf("last_cyl\t%u\t0x%x\n", record.last_cyl, record.last_cyl);
printf("lowsec\t\t%u\t0x%x\n", record.lowsec, record.lowsec);
printf("size\t\t%u\t0x%x\n", record.size, record.size);
}
int main(int argc, char *argv[])
{
int i, fd;
fd = open(argv[1], O_RDWR);
lseek(fd, OFFSET, SEEK_SET);
for (i = 0; i < 4; i ++) {
read(fd, &record, sizeof(record));
print();
if (i != 3)
printf("\n");
}
close(fd);
return EXIT_SUCCESS;
}
mishuang@msh:~/setup/bochs> read_mbr ./c.img
bootind 128 0x80
start_head 1 0x1
start_sec 1 0x1
start_cyl 0 0x0
sysind 129 0x81
last_head 15 0xf
last_sec 63 0x3f
last_cyl 121 0x79
lowsec 63 0x3f
size 122913 0x1e021
bootind 0 0x0
start_head 0 0x0
start_sec 1 0x1
start_cyl 122 0x7a
sysind 129 0x81
last_head 15 0xf
last_sec 63 0x3f
last_cyl 243 0xf3
lowsec 122976 0x1e060
size 122976 0x1e060
bootind 0 0x0
start_head 0 0x0
start_sec 1 0x1
start_cyl 244 0xf4
sysind 5 0x5
last_head 15 0xf
last_sec 127 0x7f
last_cyl 108 0x6c
lowsec 245952 0x3c0c0
size 121968 0x1dc70
bootind 0 0x0
start_head 0 0x0
start_sec 0 0x0
start_cyl 0 0x0
sysind 0 0x0
last_head 0 0x0
last_sec 0 0x0
last_cyl 0 0x0
lowsec 0 0x0
size 0 0x0
相关阅读 更多 +
排行榜 更多 +