dmi: check both the AC and ID flags at the same time
[syslinux.git] / mbr / checksize.pl
blob4b42327fa1ca4cd79e1f02fd114603f4397a8290
1 ## -----------------------------------------------------------------------
2 ##
3 ## Copyright 2007-2009 H. Peter Anvin - All Rights Reserved
4 ## Copyright 2009 Intel Corporation; author: H. Peter Anvin
5 ##
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ## Boston MA 02111-1307, USA; either version 2 of the License, or
10 ## (at your option) any later version; incorporated herein by reference.
12 ## -----------------------------------------------------------------------
15 ## checksize.pl
17 ## Check the size of a binary file and pad it with zeroes to that size
20 use bytes;
22 ($file, $maxsize, $padsize) = @ARGV;
24 if (!defined($maxsize)) {
25 # Defaults based on the filename
26 if ($file =~ /^mbr[^0-9a-z]/) {
27 $maxsize = $padsize = 440;
28 } elsif ($file =~ /^gptmbr[^0-9a-z]/) {
29 $maxsize = $padsize = 440;
30 } elsif ($file =~ /^isohdp[fp]x[^0-9a-z]/) {
31 $maxsize = $padsize = 432;
32 } elsif ($file =~ /^altmbr[^0-9a-z]/) {
33 $maxsize = $padsize = 439;
34 } else {
35 die "$0: no default size for filename: $file\n";
39 $padsize = $maxsize unless(defined($padsize));
41 open(FILE, '+<', $file) or die;
42 @st = stat(FILE);
43 if (!defined($size = $st[7])) {
44 die "$0: $file: $!\n";
46 if ($size > $maxsize) {
47 print STDERR "$file: too big ($size > $maxsize)\n";
48 exit 1;
49 } elsif ($size < $padsize) {
50 seek(FILE, $size, 0);
51 print FILE "\0" x ($padsize-$size);
54 exit 0;