A tool to calculate Amiga bootsector checksums.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33534 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2009-10-11 20:26:39 +00:00
parent 1631cac3e3
commit e6f2508262
3 changed files with 49 additions and 0 deletions

View File

@ -107,6 +107,7 @@ SubInclude HAIKU_TOP src tools bfs_shell ;
SubInclude HAIKU_TOP src tools cppunit ;
SubInclude HAIKU_TOP src tools docbook ;
SubInclude HAIKU_TOP src tools elfsymbolpatcher ;
SubInclude HAIKU_TOP src tools fixup_amiga_boot_checksum ;
SubInclude HAIKU_TOP src tools fixup_tos_boot_checksum ;
SubInclude HAIKU_TOP src tools fs_shell ;
SubInclude HAIKU_TOP src tools gensyscalls ;

View File

@ -0,0 +1,6 @@
SubDir HAIKU_TOP src tools fixup_amiga_boot_checksum ;
BuildPlatformMain <build>fixup_amiga_boot_checksum
: fixup_amiga_boot_checksum.c
:
;

View File

@ -0,0 +1,42 @@
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <netinet/in.h>
#define BB_SIZE (2*512)
int main(int argc, char **argv)
{
int fd, i;
uint32_t sum;
uint8_t bootblock[BB_SIZE];
uint32_t *p = (uint32_t *)bootblock;
fd = open(argv[1], O_RDWR);
if (fd < 0) {
return 1;
}
if (read(fd, bootblock, BB_SIZE) < BB_SIZE) {
perror("read");
return 1;
}
if (ntohl(p[0]) != 'DOS\0') {
fprintf(stderr, "bad bootblock signature!\n");
return 1;
}
p[1] = 0;
for (sum = 0, i = 0; i < (BB_SIZE)/sizeof(uint32_t); i++) {
uint32_t old = sum;
// big endian
sum += ntohl(*p++);
// overflow
if (sum < old)
sum++;
}
fprintf(stderr, "checksum: %lu\n", sum);
// big endian
((uint32_t *)bootblock)[1] = htonl(sum);
lseek(fd, 0LL, SEEK_SET);
write(fd, bootblock, BB_SIZE);
return 0;
}