aboutsummaryrefslogtreecommitdiffstats
path: root/mbr/checksize.pl
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2009-03-30 18:17:05 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2009-03-30 18:17:05 -0700
commit848c8f9a4133e4e0113120a2b311d2352af26228 (patch)
tree9a7b32bb2fe51c98e0a16af42a5f07f05b6d20fa /mbr/checksize.pl
parenta1e66d80179262be63c43bb33046bd41069b803d (diff)
downloadsyslinux.git-848c8f9a4133e4e0113120a2b311d2352af26228.tar.gz
syslinux.git-848c8f9a4133e4e0113120a2b311d2352af26228.tar.xz
syslinux.git-848c8f9a4133e4e0113120a2b311d2352af26228.zip
altmbr: an alternative MBR which ignores the active flag
Impact: new feature Create an alternative MBR which takes a partition number in byte 439 instead of looking at the active flag. This is useful when dual-booting legacy operating systems which assume that their particular partition must be the active partition. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'mbr/checksize.pl')
-rwxr-xr-xmbr/checksize.pl20
1 files changed, 14 insertions, 6 deletions
diff --git a/mbr/checksize.pl b/mbr/checksize.pl
index 68a035b7..a3643101 100755
--- a/mbr/checksize.pl
+++ b/mbr/checksize.pl
@@ -1,6 +1,6 @@
## -----------------------------------------------------------------------
##
-## Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
+## Copyright 2007-2009 H. Peter Anvin - All Rights Reserved
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
@@ -13,18 +13,26 @@
##
## checksize.pl
##
-## Check the size of a binary file
+## Check the size of a binary file and pad it with zeroes to that size
##
-($file, $maxsize) = @ARGV;
+use bytes;
-@st = stat($file);
+($file, $maxsize, $padsize) = @ARGV;
+
+$padsize = $maxsize unless(defined($padsize));
+
+open(FILE, '+<', $file) or die;
+@st = stat(FILE);
if (!defined($size = $st[7])) {
die "$0: $file: $!\n";
}
if ($size > $maxsize) {
print STDERR "$file: too big ($size > $maxsize)\n";
exit 1;
-} else {
- exit 0;
+} elsif ($size < $padsize) {
+ seek(FILE, $size, 0);
+ print FILE "\0" x ($padsize-$size);
}
+
+exit 0;