syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / memdisk / postprocess.pl
1 #!/usr/bin/perl
2 ## -----------------------------------------------------------------------
3 ##   
4 ##   Copyright 2001 H. Peter Anvin - All Rights Reserved
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 ## $Id: postprocess.pl,v 1.4 2004/12/14 22:46:25 hpa Exp $
14
15 #
16 # Postprocess the memdisk binary.
17 #
18
19 eval { use bytes; };
20
21 ($out,$file16,$file32) = @ARGV;
22
23 open(OUT, "> $out\0") or die "$0: Cannot create file: $out\n";
24 eval { binmode OUT; };
25 open(FILE, "< $file16\0") or die "$0: Cannot open file: $file16\n";
26 eval { binmode FILE };
27
28 @info = stat(FILE);
29 $size = $info[7];
30
31 $sectors = ($size + 511) >> 9;
32 $xsize = $sectors << 9;
33
34 read(FILE, $f16, $size);
35
36 print OUT $f16;
37
38 if ( $size != $xsize ) {
39     # Pad to a sector boundary
40     print OUT "\0" x ($xsize-$size);
41 }
42
43 seek(OUT, 0x1f1, SEEK_SET);     # setup_sects
44 # All sectors are setup except the first
45 print OUT pack("C", $sectors-1);
46
47 seek(OUT, $xsize, SEEK_SET);
48 close(FILE);
49
50 open(FILE, "+< $file32\0") or die "$0: Cannot open file: $file32\n";
51
52 while ( ($n = read(FILE, $f32, 65536)) > 0 ) {
53     print OUT $f32;
54 }
55
56 close(FILE);
57 close(OUT);
58