How do I write a bin file (512 bytes) to the first sector (sector 0) of a floppy disk?

前端 未结 3 1057
星月不相逢
星月不相逢 2020-11-30 07:55

How do I write a .bin file to be in the first sector of a floppy disk/virtual floppy disk/floppy image?

I\'m trying to boot a simple 512-byte bootloader. The size on

3条回答
  •  情深已故
    2020-11-30 08:37

    To write a file into another file, you can write a program. Following snippet is in C.

    char buf[512];
    int floppy_desc, file_desc;
    file_desc = open("xx.bin", O_RDONLY);
    read(file_desc, buf, 512);
    close(file_desc);
    
    floppy_desc = open("floppy.img", O_RDWR);
    lseek(floppy_desc, 512, SEEK_SET);
    write(floppy_desc, buf, 512);
    close(floppy_desc);
    

提交回复
热议问题