mywrite.c

来自「阿基米德操作系统的源代码」· C语言 代码 · 共 35 行

C
35
字号

#include <sys/types.h> 
#include <unistd.h> 
#include <fcntl.h>

void main(int argc,char * argv[])
{
  char	boot_buf[160000];
  char  head_buf[160000];
  int	floppy_desc,boot_desc,head_desc;
  int   ret;
  int   i;

  if (argc != 3){
     printf("\n mywrite boot head \n");
     exit(1);
  }
  boot_desc = open(argv[1], O_RDONLY);
  ret = read(boot_desc, boot_buf, 512);
  close(boot_desc);

  head_desc = open(argv[2], O_RDONLY);
  ret = read(head_desc, head_buf, 160000);
  close(head_desc);

  for (i = 0; i < ret; i++)
	boot_buf[i + 512] = head_buf[i];

  floppy_desc = open("/dev/fd0", O_RDWR);
  lseek(floppy_desc, 0, SEEK_CUR);
  write(floppy_desc, boot_buf, ret + 512);
  close(floppy_desc);
  exit(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?