Merge branch 'json' into libupload
[profile/ivi/syslinux.git] / diag / geodsp / mk-lba-img.c
1 /* ----------------------------------------------------------------------- *
2  *
3  *   Copyright 2010 Gene Cumm
4  *
5  *   This program is free software; you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8  *   Boston MA 02111-1307, USA; either version 2 of the License, or
9  *   (at your option) any later version; incorporated herein by reference.
10  *
11  * ----------------------------------------------------------------------- */
12
13 /*
14  * mk-lba-img.c
15  *
16  * Makes an image that contains the LBA in every *word of every sector
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <errno.h>
22 #include <string.h>
23 #include <unistd.h>
24
25 #define NUM_SECT (256*63+1)
26 #define BPS (512)
27 #define SECT_INT (512 / sizeof(int))
28
29 typedef unsigned char uint8_t;
30 typedef unsigned int uint32_t;
31
32 const char DEF_FN[] = "lba.img";
33
34 int main(int argc, char *argv[])
35 {
36         int i, j, b[SECT_INT], rv = 0, one = 0;
37         FILE *f;
38         uint8_t tt = 0;
39         const char *fn;
40
41         if (argc >= 2) {
42                 if (argc >= 3) {
43                         if (strcasecmp("-1", argv[1]) == 0) {
44                                 fn = argv[2];
45                                 one = 1;
46                         } else {
47                                 fn = argv[1];
48                         }
49                 } else {
50                         fn = argv[1];
51                 }
52         } else {
53                 fn = DEF_FN;
54         }
55
56         f = fopen(fn, "w");
57
58         if (f) {
59                 for (i = 0; i < NUM_SECT; i++) {
60                         if (one) {
61                                 b[0] = i;
62                         } else {
63                                 for (j = 0; j < (512 / sizeof(int)); j++) {
64                                         b[j] = i;
65                                 }
66                         }
67                         fwrite(b, 512, 1, f);
68                 }
69                 fclose(f);
70         } else {
71                 puts("Unable to open for writing");
72                 rv = 1;
73         }
74         return rv;
75 }