kvm: qemu: ftruncate() is not supported by hugetlbfs on older hosts
[kvm-userspace.git] / extboot / signrom.c
blobfe8d677459dd317bf5b332ae330960f23937385c
1 /*
2 * Extended Boot Option ROM
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Copyright IBM Corporation, 2007
19 * Authors: Anthony Liguori <aliguori@us.ibm.com>
22 #include <stdio.h>
23 #include <stdint.h>
24 #include <string.h>
26 int main(int argc, char **argv)
28 FILE *fin, *fout;
29 char buffer[512], oldbuffer[512];
30 int i, size, lag = 0;
31 uint8_t sum = 0;
33 if (argc != 3) {
34 printf("Usage: %s ROM OUTPUT\n", argv[0]);
35 return 1;
38 fin = fopen(argv[1], "rb");
39 fout = fopen(argv[2], "wb");
41 if (fin == NULL || fout == NULL) {
42 fprintf(stderr, "Could not open input/output files\n");
43 return 1;
46 do {
47 size = fread(buffer, 512, 1, fin);
48 if (size == 1) {
49 for (i = 0; i < 512; i++)
50 sum += buffer[i];
52 if (lag) {
53 if (fwrite(oldbuffer, 512, 1, fout) != 1) {
54 fprintf(stderr, "Write failed\n");
55 return 1;
58 lag = 1;
59 memcpy(oldbuffer, buffer, 512);
61 } while (size == 1);
63 if (size != 0) {
64 fprintf(stderr, "Failed to read from input file\n");
65 return 1;
68 oldbuffer[511] = -sum;
70 if (fwrite(oldbuffer, 512, 1, fout) != 1) {
71 fprintf(stderr, "Failed to write to output file\n");
72 return 1;
75 fclose(fin);
76 fclose(fout);
78 return 0;