2007年5月11日星期五

写软盘 引导扇区的工具


1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/uio.h>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include <sys/stat.h>
7 int
8 main(int argc,char *argv[])
9 {
10 struct stat img_file;
11
12 char boot_buf[512];
13 int i;
14 for(i=0;i<511;i++){
15 boot_buf[i]=0x00;
16 }
17 int img_fd, boot_fd;
18
19 if(argc!=3){
20 printf("USAGE:./write boot_file img_file\n");
21 }
22
23 boot_fd = open(argv[1], O_RDONLY);
24 img_fd = open(argv[2], O_RDWR);
25 fstat(img_fd,&img_file);
26 if((argc==3)&&(img_file.st_size!=1474560))
27 {
28 printf("WARNING:floppy image size is NOT 1474560 \n");
29 }
30 read(boot_fd, boot_buf, 510);
31 close(boot_fd);
32 boot_buf[510] = 0x55;
33 boot_buf[511] = 0xaa;
34 lseek(img_fd, 0, SEEK_CUR);
35 write(img_fd, boot_buf, 512);
36 close(img_fd);
37
38 exit(0);
39 }
36

没有评论: