Completing syslinux package contents.
[syslinux-debian/hramrach.git] / diag / geodsp / mk-lba-img.c
blobeb1c339320ab8265457211dc3a74524963df9b65
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2010 Gene Cumm
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.
11 * ----------------------------------------------------------------------- */
14 * mk-lba-img.c
16 * Makes an image that contains the LBA in every *word of every sector
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <errno.h>
22 #include <string.h>
23 #include <unistd.h>
25 #define NUM_SECT (256*63+1)
26 #define BPS (512)
27 #define SECT_INT (BPS / sizeof(unsigned int))
29 typedef unsigned char uint8_t;
30 typedef unsigned int uint32_t;
32 const char DEF_FN[] = "-";
34 int main(int argc, char *argv[])
36 int i, rv = 0, one = 0;
37 unsigned int lba, b[SECT_INT];
38 int len;
39 FILE *f;
40 uint8_t tt = 0;
41 const char *fn;
43 if (argc >= 2) {
44 if (argc >= 3) {
45 if (strcasecmp("-1", argv[1]) == 0) {
46 fn = argv[2];
47 one = 1;
48 } else {
49 fn = argv[1];
51 } else {
52 fn = argv[1];
54 } else {
55 fn = DEF_FN;
58 if (!strcmp(fn, "-"))
59 f = stdout;
60 else
61 f = fopen(fn, "w");
63 if (!f) {
64 fprintf(stderr, "%s: %s: unable to open for writing: %s\n",
65 argv[0], fn, strerror(errno));
66 return 1;
69 lba = 0;
70 while ((len = fread(b, 1, BPS, stdin))) {
71 if (len < BPS)
72 memset((char *)b + len, 0, BPS - len);
73 fwrite(b, 1, BPS, f);
74 lba++;
77 memset(b, 0, sizeof b);
79 while (lba < NUM_SECT) {
80 if (one) {
81 b[0] = lba;
82 } else {
83 for (i = 0; i < SECT_INT; i++)
84 b[i] = lba;
86 fwrite(b, 1, BPS, f);
87 lba++;
90 if (f != stdout)
91 fclose(f);
93 return rv;