From 5b47f71ccbee753b8d41efad86a6c7a9b5cefe0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Mon, 27 Apr 2009 18:45:28 +0000 Subject: [PATCH] Move the checksum fixup tool where it belongs. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30467 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../fixup_tos_floppy_chksum.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/tools/fixup_tos_boot_checksum/fixup_tos_floppy_chksum.c diff --git a/src/tools/fixup_tos_boot_checksum/fixup_tos_floppy_chksum.c b/src/tools/fixup_tos_boot_checksum/fixup_tos_floppy_chksum.c new file mode 100644 index 0000000000..87fe8c9932 --- /dev/null +++ b/src/tools/fixup_tos_boot_checksum/fixup_tos_floppy_chksum.c @@ -0,0 +1,34 @@ +#include +#include +#include + +uint8_t sector[512]; + +int main(int argc, char **argv) +{ + int fd, i; + uint16_t sum; + uint8_t *p = sector; + fd = open(argv[1], O_RDWR); + if (fd < 0) { + return 1; + } + if (read(fd, sector, 512-2) < 512-2) { + perror("read"); + return 1; + } + for (sum = 0, i = 0; i < (512-2)/2; i++) { + uint16_t v; + v = *p++ << 8; + v += *p++; + sum += v; + } + sum = 0x1234 - sum /*+ 1*/; + //sum = 0xaa55; + // big endian + *p++ = (uint8_t)(sum >> 8); + *p++ = (uint8_t)sum; + //lseek(fd, 0LL, SEEK_SET); + write(fd, §or[512-2], 2); + return 0; +}