root/mbr/checksize.pl

Revision d4c1eecb7c6e37432ba9ef0624e29129d9b8be24, 1.5 KB (checked in by H. Peter Anvin <hpa@…>, 2 years ago)

gptmbr: implement the new T13-approved GPT protocol

My GPT-based protocol was modified by the UEFI and T13 committees (the
former responsible for the GPT format, the latter for EDD and
therefore for the disk-related part of the BIOS specification.) This
is thus now on its way to become an official protocol, so change the
implementation to match.

This still needs testing, and the Syslinux core needs to be adjusted
to leverage the extended information.

Signed-off-by: H. Peter Anvin <hpa@…>

  • Property mode set to 100755
Line 
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.
11##
12## -----------------------------------------------------------------------
13
14##
15## checksize.pl
16##
17## Check the size of a binary file and pad it with zeroes to that size
18##
19
20use bytes;
21
22($file, $maxsize, $padsize) = @ARGV;
23
24if (!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";
36    }
37}
38
39$padsize = $maxsize unless(defined($padsize));
40
41open(FILE, '+<', $file) or die;
42@st = stat(FILE);
43if (!defined($size = $st[7])) {
44    die "$0: $file: $!\n";
45}
46if ($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);
52}
53
54exit 0;
Note: See TracBrowser for help on using the browser.