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:
François Revol 2009-04-27 18:45:28 +00:00
parent b10b8f90cb
commit 5b47f71ccb
1 changed files with 34 additions and 0 deletions

View 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, &sector[512-2], 2);
return 0;
}