1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | use constant SYSSIZE_LOC => 500; # bytes from beginning of boot block
|
---|
4 | use constant MINSIZE => 32768;
|
---|
5 |
|
---|
6 | use strict;
|
---|
7 |
|
---|
8 | use bytes;
|
---|
9 |
|
---|
10 | $#ARGV >= 1 or die "Usage: $0 liloprefix file ...\n";
|
---|
11 | open(L, "$ARGV[0]") or die "$ARGV[0]: $!\n";
|
---|
12 | undef($/);
|
---|
13 | my $liloprefix = <L>;
|
---|
14 | close(L);
|
---|
15 | length($liloprefix) >= 512 or die "LILO prefix too short\n";
|
---|
16 | shift(@ARGV);
|
---|
17 | my $totalsize = 0;
|
---|
18 | for my $file (@ARGV) {
|
---|
19 | next if (! -f $file or ! -r $file);
|
---|
20 | $totalsize += -s $file;
|
---|
21 | }
|
---|
22 | my $pad = 0;
|
---|
23 | if ($totalsize < MINSIZE) {
|
---|
24 | $pad = MINSIZE - $totalsize;
|
---|
25 | $totalsize = MINSIZE;
|
---|
26 | }
|
---|
27 | print STDERR "LILO payload is $totalsize bytes\n";
|
---|
28 | $totalsize += 16;
|
---|
29 | $totalsize >>= 4;
|
---|
30 | substr($liloprefix, SYSSIZE_LOC, 2) = pack('v', $totalsize);
|
---|
31 | print $liloprefix;
|
---|
32 | for my $file (@ARGV) {
|
---|
33 | next unless open(I, "$file");
|
---|
34 | undef($/);
|
---|
35 | my $data = <I>;
|
---|
36 | print $data;
|
---|
37 | close(I);
|
---|
38 | }
|
---|
39 | print "\x0" x $pad;
|
---|
40 | exit(0);
|
---|