summaryrefslogtreecommitdiff
path: root/diag/geodsp/mk-lba-img.c
blob: 795de1a79db23086a180745e19362095148b6461 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* ----------------------------------------------------------------------- *
 *
 *   Copyright 2010 Gene Cumm
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
 *   Boston MA 02111-1307, USA; either version 2 of the License, or
 *   (at your option) any later version; incorporated herein by reference.
 *
 * ----------------------------------------------------------------------- */

/*
 * mk-lba-img.c
 *
 * Makes an image that contains the LBA in every *word of every sector
 */

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

#define NUM_SECT (256*63+1)
#define BPS (512)
#define SECT_INT (512 / sizeof(int))

typedef unsigned char uint8_t;
typedef unsigned int uint32_t;

const char DEF_FN[] = "lba.img";

int main(int argc, char *argv[])
{
	int i, j, b[SECT_INT], rv = 0, one = 0;
	FILE *f;
	uint8_t tt = 0;
	const char *fn;

	if (argc >= 2) {
		if (argc >= 3) {
			if (strcasecmp("-1", argv[1]) == 0) {
				fn = argv[2];
				one = 1;
			} else {
				fn = argv[1];
			}
		} else {
			fn = argv[1];
		}
	} else {
		fn = DEF_FN;
	}

	f = fopen(fn, "w");

	if (f) {
		for (i = 0; i < NUM_SECT; i++) {
			if (one) {
				b[0] = i;
			} else {
				for (j = 0; j < (512 / sizeof(int)); j++) {
					b[j] = i;
				}
			}
			fwrite(b, 512, 1, f);
		}
		fclose(f);
	} else {
		puts("Unable to open for writing");
		rv = 1;
	}
	return rv;
}