old-www/LDP/LG/issue37/ramirez.fixbs

53 lines
858 B
Plaintext

/*
fixbs
-----
Fix bootsector of an mformat-ed hard drive FAT partition.
Gilbert Ramirez
Technical Services
University Health System
$Id: ramirez.fixbs,v 1.1.1.1 2002/08/14 22:27:25 dan Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char **argv)
{
char *device;
int fd;
char jmp[2] = { 0x3c, 0x90 };
char dirlen[2] = { 0x00, 0x02 };
if (argc != 2) {
fprintf(stderr, "\nusage: %s device\n"
"\tFixes boot sector on device\n", argv[0]);
exit(-1);
}
device = argv[1];
if ((fd = open(device, O_WRONLY)) < 0) {
fprintf(stderr, "%s: couldn't open %s for writing\n", argv[0],
device);
exit(-1);
}
lseek(fd, 1, SEEK_SET);
write(fd, jmp, 2);
lseek(fd, 0x11, SEEK_SET);
write(fd, dirlen, 2);
close(fd);
return 0;
}