LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: home

如何用c将512字节文件文件写入主引导扇区?

[复制链接]
发表于 2004-5-7 23:24:10 | 显示全部楼层
这个程序错在那里?是读/dev/ad0s1的446-512字节的。
  1. #include <fcntl.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. int
  5. main(vid)
  6. {
  7.         int         fd,fdp,n;
  8.         char        buf[66];
  9.         if((fd=open("/dev/ad0s1",O_RDONLY))<0) {
  10.                 perror("open error");
  11.                 exit(1);
  12.         }
  13.        if((fdp=open("66_par",O_RDWR|O_CREAT))<0) {
  14.                 perror("oepn fdp error");
  15.                 exit(1);
  16.         }
  17.         if(lseek(fd,446,SEEK_SET)<0) {
  18.                 perror("lseek error");
  19.                 exit(1);
  20.         }
  21.         if((n=read(fd,buf,sizeof(buf))) <0  ) {
  22.                 perror("read error");
  23.                 exit(1);
  24.         }
  25.         if(write(fdp,buf,n) != n) {
  26.                 perror("write error");
  27.                 exit(1);
  28.         }
  29.         close(fd);
  30.         close(fdp);
  31.         return(0);
  32. }
复制代码
# ./a.out
read error: Invalid argument

why ??:confused:
发表于 2004-5-8 00:13:00 | 显示全部楼层
没问题呀,不过我是linux,用的是/dev/hda(或hda1)
发表于 2004-5-9 14:46:50 | 显示全部楼层
上面的程序在linux用没问题!!
发表于 2004-5-9 23:46:09 | 显示全部楼层
真奇怪呀???我在linux试也没问题。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表