1 ## -----------------------------------------------------------------------
3 ## Copyright 2007-2009 H. Peter Anvin - All Rights Reserved
4 ## Copyright 2009 Intel Corporation; author: H. Peter Anvin
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 ## -----------------------------------------------------------------------
17 ## Check the size of a binary file and pad it with zeroes to that size
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;
35 die "$0: no default size for filename: $file\n";
39 $padsize = $maxsize unless(defined($padsize));
41 open(FILE
, '+<', $file) or die;
43 if (!defined($size = $st[7])) {
44 die "$0: $file: $!\n";
46 if ($size > $maxsize) {
47 print STDERR
"$file: too big ($size > $maxsize)\n";
49 } elsif ($size < $padsize) {
51 print FILE
"\0" x
($padsize-$size);