Move the checksum fixup tool where it belongs.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30467 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b10b8f90cb
commit
5b47f71ccb
34
src/tools/fixup_tos_boot_checksum/fixup_tos_floppy_chksum.c
Normal file
34
src/tools/fixup_tos_boot_checksum/fixup_tos_floppy_chksum.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user