From b4dbd2cfa724476162fa6d35941a5d7cdc9c9524 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Mon, 18 Feb 2019 08:10:10 -0500 Subject: Adds all assignments not previously in a git repo --- CS3871/os/copy.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 CS3871/os/copy.c (limited to 'CS3871/os/copy.c') diff --git a/CS3871/os/copy.c b/CS3871/os/copy.c new file mode 100644 index 0000000..6e21083 --- /dev/null +++ b/CS3871/os/copy.c @@ -0,0 +1,95 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main(argc, argv) +int argc; +char ** argv; +{ + int val; + char buf[512], *dev; + int file, floppy; + + if (argc < 3 ) { + perror("usage: copy path_to_bootloader path_to_os [path_to_device]\n"); + exit(1); + } + if (argc >= 4) { + dev = argv[3]; + } else { + dev = "/dev/fd0"; + } + + memset(buf, 0, 512); + + floppy = open(dev, O_RDWR); + if (file < 0) { + perror("Could not open floppy: "); + exit(1); + } + + /****************************** + * Write Bootloader to Floppy * + ******************************/ + + file = open(argv[1], O_RDONLY); + if (file < 0) { + perror("Could not open bootloader: "); + exit(1); + } + + val = read(file, buf, 510); + close(file); + if (val < 0) { + perror("Could not read bootloader: "); + exit(1); + } + + buf[510] = 0x55; + buf[511] = 0xaa; + + lseek(floppy, 0, SEEK_CUR); + + val = write(floppy, buf, 512); + if (val < 0) { + perror("Error writing to floppy: "); + close(floppy); + exit(1); + } + + + /********************** + * Write OS to Floppy * + **********************/ + + file = open(argv[2], O_RDONLY); + if (file < 0) { + perror("Could not open os: "); + exit(1); + } + + val = read(file, buf, 512); + close(file); + if (val < 0) { + perror("Could not read os: "); + exit(1); + } + + val = write(floppy, buf, 512); + if (val < 0) { + perror("Error writing to floppy: "); + close(floppy); + exit(1); + } + + syncfs(floppy); + close(floppy); + + printf("Floppy successfully copied!\n"); + return 0; +} -- cgit v1.1