[syslinux] [PATCH 1/1] core: Check if ldlinux.sys exceeds the limit at its building time.

Matt Fleming matt at console-pimps.org
Mon Sep 16 07:08:31 PDT 2013


Peter, does this look OK to you?

Raphael, I can't work out why ADV_SIZE is a constant in this file?

On Sat, 31 Aug, at 05:01:20PM, Raphael S.Carvalho wrote:
> Calc the size of ldlinux.sys from ldlinux.bin, and check if it exceeds the limit.
> ldlinux.sys must fit between the bootsector and two copies of ADV whose size may vary.
> Thus, the size of ldlinux.sys (limit) can be at most: 65536 - 2 * ADV_SIZE - 512.
> 
> Certain file systems (such as BTRFS and UFS2) will rely on ldlinux.sys being installed on the 0-64k range,
> thus it can't exceed the limit, otherwise the superblock would be corrupted.
> 
> Signed-off-by: Raphael S.Carvalho <raphael.scarv at gmail.com>
> ---
>  core/Makefile         |    1 +
>  core/ldlinux_limit.pl |   39 +++++++++++++++++++++++++++++++++++++++
>  2 files changed, 40 insertions(+), 0 deletions(-)
>  create mode 100755 core/ldlinux_limit.pl
> 
> diff --git a/core/Makefile b/core/Makefile
> index f795a5c..e0daafc 100644
> --- a/core/Makefile
> +++ b/core/Makefile
> @@ -220,6 +220,7 @@ ldlinux.bss: ldlinux.bin
>  	dd if=$< of=$@ bs=512 count=1
>  
>  ldlinux.sys: ldlinux.bin
> +	$(PERL) $(SRC)/ldlinux_limit.pl $< \
>  	dd if=$< of=$@ bs=512 skip=2
>  
>  codepage.cp: $(OBJ)/../codepage/$(CODEPAGE).cp
> diff --git a/core/ldlinux_limit.pl b/core/ldlinux_limit.pl
> new file mode 100755
> index 0000000..923d516
> --- /dev/null
> +++ b/core/ldlinux_limit.pl
> @@ -0,0 +1,39 @@
> +#!/usr/bin/perl
> +## -----------------------------------------------------------------------
> +##
> +##   Copyright 2013 Raphael S. Carvalho <raphael.scarv at gmail.com>
> +##
> +##   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
> +##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
> +##   Boston MA 02111-1307, USA; either version 2 of the License, or
> +##   (at your option) any later version; incorporated herein by reference.
> +##
> +## -----------------------------------------------------------------------
> +
> +## ldlinux_limit.pl: Calc the size of ldlinux.sys and check if it exceeds the limit.
> +## ldlinux.sys must fit between the bootsector and two copies of ADV whose size may vary.
> +##
> +## Certain file systems will simply install ldlinux.sys as an ordinary file, but UFS2 and
> +## BTRFS for example, rely on ldlinux.sys being installed on the 0-64k range.
> +##
> +## 0-64k range:
> +## [0](bootsector)[512](ldlinux.sys)[65536 - 2 * ADV_SIZE](2 copies of ADV)[65536]
> +
> +use File::stat;
> +
> +($ldlinux_bin) = @ARGV;
> +$adv_size = 512;
> +$limit = 65536 - 2 * $adv_size - 512;
> +$pad = 512;
> +
> +$ldlinux_size = stat($ldlinux_bin)->size - 1024;
> +$align = $ldlinux_size % $pad;
> +$ldlinux_size += $pad - $align;
> +
> +if ($ldlinux_size > $limit) {
> +	print STDERR "$0: ldlinux.sys ($ldlinux_size) larger than limit ($limit).\n";
> +	exit 1;
> +}
> +
> +exit 0;
> -- 
> 1.7.2.5
> 

-- 
Matt Fleming, Intel Open Source Technology Center


More information about the Syslinux mailing list