23 lines
576 B
C
Raw Normal View History

2023-01-27 13:15:37 +04:00
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
2023-01-27 12:25:39 +00:00
#include <stdint.h>
2023-01-27 13:15:37 +04:00
int main(int argc, char* argv[]) {
if (argc != 2) {
fprintf(stderr, "Usage: %s mbr.bin\n", argv[0]);
return 1;
}
const char* filename = argv[1];
int fd = open(filename, O_RDWR);
off_t length = lseek(fd, 0, SEEK_END);
if (length > 510) {
2023-01-27 12:25:39 +00:00
fprintf(stderr, "file %s is larger than 510 bytes (size: %ju)\n",
filename, (uintmax_t)length);
2023-01-27 13:15:37 +04:00
return 1;
}
lseek(fd, 510, SEEK_SET);
write(fd, "\x55\xaa", 2);
return 0;
}