说来惭愧,原来这么简单。 代码从minix源代码 installboot.c中截取。
/*First open the device*/
int fd;
fd = open("/dev/hda", O_RDWR);
/*Then read the first two sectors of the device*/
char buf[1024+1];
lseek(fd, 0, SEEK_SET);
read(fd, buf, 1024); /*I am curious about why get 1024 bytes not 512 bytes*/
/*Doing patch*/
/*need more study*/
/*Write the code back to the device*/
lseek(fd, 0, SEEK_SET);
write(fd, buf, 1024);
So easy, isn't it?