File: ramirez.fixbs

package info (click to toggle)
lg-issue37 3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,216 kB
  • ctags: 160
  • sloc: sh: 74; makefile: 34
file content (52 lines) | stat: -rw-r--r-- 858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
	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;
}