Bootloader::Core::ZIPL.3pm

Langue: en

Version: 2007-09-26 (openSuse - 09/10/07)

Section: 3 (Bibliothèques de fonctions)

NAME

Bootloader::Core::ZIPL - ZIPL library for bootloader configuration

PREFACE

This package is the ZIPL library of the bootloader configuration

SYNOPSIS

use Bootloader::Core::ZIPL;

"$obj_ref = Bootloader::Core::ZIPL->new ();"

"$settings_ref = Bootloader::Core::ZIPL->GetSettings ();"

"$files_ref = Bootloader::Core::ZIPL->ListFiles ();"

"$status = Bootloader::Core::ZIPL->FixSectionName ($name, \$names_ref, $type);"

"$status = Bootloader::Core::ZIPL->ParseLines (\%files, $avoid_reading_device_map);"

"$sections_ref Bootloader::Core->SplitLinesToSections (\@lines, \@section_starts);"

"$files_ref = Bootloader::Core::ZIPL->CreateLines ();"

"$status = Bootloader::Core::ZIPL->UpdateBootloader ($avoid_init);"

"$status = Bootloader::Core::ZIPL->InitializeBootloader ();"

"$lines_ref = Bootloader::Core::ZIPL->Info2Section (\%section_info, \@sect_names);"

"$sectin_info_ref = Bootloader::Core::ZIPL->Section2Info (\@section_lines);"

"$glob_info = $Bootloader::Core::ZIPL->Global2Info (\@glob_lines, \@section_names);"

"$lines_ref = Bootloader::Core::ZIPL->Info2Global (\%section_info, \@section_names, \@sections);"

"Bootloader::Core::ZIPL->MangleSections (\@sections, \%global);"

"($lines_ref, $com_bef) Bootloader::Core::ZIPL->ProcessSingleMenuFileLine ($lines, $com_bef, $separator);"

"$line = Bootloader::Core::ZIPL->CreateSingleMenuFileLine ($key, $value, $separator);"

DESCRIPTION

$obj_ref = Bootloader::Core::ZIPL->new ();
Creates an instance of the Bootloader::Core::ZIPL class.
$settings_ref = Bootloader::Core::ZIPL->GetSettings ();
returns the complete settings in a hash. Does not read the settings from the system, but returns internal structures.
$files_ref = Bootloader::Core::ZIPL->ListFiles ();
Returns the list of the configuration files of the bootloader Returns undef on fail
$status = Bootloader::Core::ZIPL->FixSectionName ($name, \$names_ref, $type);
$status = Bootloader::Core::ZIPL->ParseLines (\%files, $avoid_reading_device_map);
Parses the contents of all files and stores the settings in the internal structures. As first argument, it takes a hash reference, where keys are file names and values are references to lists, each member is one line of the file. As second argument, it takes a boolean flag that, if set to a true value, causes it to skip updating the internal device_map information. The latter argument is not used for ZIPL. Returns undef on fail, defined nonzero value on success.
$sections_ref Bootloader::Core->SplitLinesToSections (\@lines, \@section_starts);
Splits the lines of the configuration file to particular sections As argument it takes a reference to a list of lines (each line represented as a hash) and a reference to a list of keys starting a new section. Returns a reference of a list of sections, each represented as a list of lines. The first section is the global section of the bootloader (without
$files_ref = Bootloader::Core::ZIPL->CreateLines ();
creates contents of all files from the internal structures. Returns a hash reference in the same format as argument of ParseLines on success, or undef on fail.
$status = Bootloader::Core::ZIPL->UpdateBootloader ($avoid_init);
Updates the settings in the system. Backs original configuration files up and replaces them with the ones with the '.new' suffix. Also performs operations needed to make the change effect (run '/sbin/zipl'). Returns undef on fail, defined nonzero value on success.
$status = Bootloader::Core::ZIPL->InitializeBootloader ();
Initializes the firmware to boot the bootloader. Returns undef on fail, defined nonzero value otherwise
$lines_ref = Bootloader::Core::ZIPL->Info2Section (\%section_info, \@sect_names);
Takes the info about the section and uses it to construct the list of lines. The info about the section also contains the original lines. As parameter, takes the section info (reference to a hash), returns the lines (a list of hashes). =cut

# list<map<string,any>> Info2Section (map<string,string> info), list<string> sect_names) sub Info2Section {
    my $self = shift;
    my %sectinfo = ( %{+shift} ); # make a copy of section info
    my $sect_names_ref = shift;


    my @lines = @{$sectinfo{"__lines"} || []};

    my $type = $sectinfo{"type"} || "";

    my $so = $self->{"exports"}{"section_options"};




    # print "info2section, section " . $sectinfo{"name"} . ", type " . $type . ".\n";




    # allow to keep the section unchanged

    if ((($sectinfo{"__modified"} || 0) == 0) and ($type ne "menu"))

    {

        return \@lines;

    }



# $sectinfo{``name''} = $self->FixSectionName ($sectinfo{``name''}, # $sect_names_ref, $type);
    @lines = map {         my $line_ref = $_;
        my $key = $line_ref->{``key''};
        my $parameters = "";


        if ($key eq "label")

        {

            $line_ref = $self->UpdateSectionNameLine ($sectinfo{"name"}, $line_ref, $sectinfo{"original_name"});

            delete ($sectinfo{"name"});

#           $line_ref->{"key"}="[".$line_ref->{"value"}."]";

#           $line_ref->{"value"}="";

        }

        elsif ($key eq "ramdisk")

        {

            $key = "initrd";

            $line_ref->{"value"} = delete $sectinfo{$key};

        }

        elsif ($key eq "parameters")

        {

            $line_ref->{"value"} = "root=".$sectinfo{"root"}." ".$sectinfo{"append"};

            delete ($sectinfo{"root"});

            delete ($sectinfo{"append"});

        }

        elsif ($key eq "menuname")

        {

            # $line_ref->{"key"}="menuname";

            $line_ref->{"value"} = delete $sectinfo{"name"};

        }

        elsif ($key eq "prompt")

        {

            # $line_ref->{"key"}="menuname";

            $line_ref->{"value"} =

                delete $sectinfo{$key} eq "true" ? "1" : "0";

        }

        elsif (not exists $so->{$type . "_" . $key})

        {

            # print $type . "_" . $key . " unknown!\n";

            $line_ref = undef; # only accept known section options CAVEAT!

        }

        else

        {

            if (defined ($sectinfo{$key})) {

                $line_ref->{"value"} = delete $sectinfo{$key};

            }

            else {

                $line_ref = undef;

            }

        }

        defined $line_ref ? $line_ref : ();

    } @lines;




    my $parameters = "";

    while ((my $key, my $value) = each (%sectinfo))

    {

        if ($key eq "name") {

            if ($type eq "image" || $type eq "dump") {

                my $line_ref = $self->UpdateSectionNameLine($sectinfo{"name"}, {},

                                                            $sectinfo{"original_name"});

                $line_ref->{"key"} = "label";

                #  $line_ref->{"key"}="[".$line_ref->{"value"}."]";

                #  $line_ref->{"value"}="";

                push @lines, $line_ref;

            }

            elsif ($type eq "menu") {

                push @lines, {

                    "key" => "menuname",

                    "value" => $value,

                };

            } # else ignore for unknown section type

        }

        elsif (not exists ($so->{$type . "_" . $key})) {

            # print $type . "_" . $key . " unknown!\n";

            next; # only accept known section options CAVEAT!

        }

        elsif ($key eq "list") {

            my $i = 1;

            foreach (split(/\s*,\s*/, $value)) {

                # check for valid section references

                foreach my $section (@{$sect_names_ref}) {

                    if ($_ eq $section) {

                        push @lines, {

                            "key" => "$i",

                            "value" => "$_",

                        };

                        $i++;

                        last;

                    }

                }

            }

        }

        elsif ($key eq "initrd" || $key eq "dumpto" || $key eq "target") {

            $key = "ramdisk" if ($key eq "initrd");

            push @lines, {

                "key" => $key,

                "value" => $value,

            };

        }

        elsif ($key eq "root") {

            $parameters = "root=" . $value . " " . $parameters;

        }

        elsif ($key eq "append") {

            $parameters = $parameters . $value;

        }

        else {

            my ($stype) = split /:/, $so->{$type . "_" . $key};

            # bool values appear in a config file or not

            if ($stype eq "bool") {

                next if $value ne "true";

                $value = "1";

            }




            push @lines, {

                "key" => $key,

                "value" => $value,

            };

        }




    }




    if ($parameters) {

        push @lines, {

            "key" => "parameters",

            "value" => "" . $parameters . ""

        };

    }




    my $ret = $self->FixSectionLineOrder (\@lines,

        [ "label", "menuname" ]);




    return $ret;

}



$sectin_info_ref = Bootloader::Core::ZIPL->Section2Info (\@section_lines);
Gets the information about the section. As argument, takes a reference to the list of lines building the section, returns a reference to a hash containing information about the section. =cut

# map<string,string> Section2Info (list<map<string,any>> section) sub Section2Info {
    my $self = shift;
    my @lines = @{+shift};


    my %ret = ();

    my @list = ();




    foreach my $line_ref (@lines) {

        my $key = $line_ref->{"key"};

        if ($key eq "label") {

            $ret{"name"} = $line_ref->{"value"};

            my $on = $self->Comment2OriginalName ($line_ref->{"comment_before"});

            $ret{"original_name"} = $on if ($on ne "");

        }

        elsif ($key eq "image")

        {

            $ret{$key} = $line_ref->{"value"};

            $ret{"type"} = "image";

        }

        elsif ($key eq "prompt")

        {

            $ret{$key} = $line_ref->{"value"} eq "1" ? "true" : "false";

        }

        elsif ($key eq "ramdisk" || $key eq "dumpto" || $key eq "default" ||

               $key eq "timeout" || $key eq "target")

        {

            if($key eq "ramdisk")

            {

              $key = "initrd";

              ($ret{$key} = $line_ref->{"value"}) =~ s/,0x[A-Fa-f0-9]+$//g; # remove load address

            }

            else

            {

              $ret{"type"} = "dump" if $key eq "dumpto";

              $ret{$key} = $line_ref->{"value"};

            }

        }

        elsif ($key eq "parameters")

        {

            # split off root device from other kernel parameters

            ($ret{"append"} = $line_ref->{"value"}) =~ s/root=[^[:space:]]+[[:space:]]+//g;

            ($ret{"root"} = $line_ref->{"value"}) =~ s/^.*root=([^[:space:]]+)[[:space:]]+.*$/$1/g;

            #print "params: ".$ret{"append"}."/".$ret{"root"}."\n";

        }

        elsif ($key eq "menuname")

        {

            $ret{"name"} = $line_ref->{"value"} || "menu";

            $ret{"type"} = "menu";

        }

        elsif ($key =~ m/\d+/)

        {

            $list[0+$key] = $line_ref->{"value"}

        }

    }




    # Fill menu with default values

    if ($ret{"type"} eq "menu") {

        $ret{"target"} = "/boot/zipl" unless $ret{"target"};

        $ret{"prompt"} = "true" unless exists $ret{"prompt"};

        $ret{"timeout"} = "10" unless exists $ret{"timeout"};

        $ret{"list"} = join(", ", grep { $_; } @list) if (@list) ;

    }




    $ret{"__lines"} = \@lines;

    return \%ret;

}



$glob_info = $Bootloader::Core::ZIPL->Global2Info (\@glob_lines, \@section_names);
Gets the general information from the global section of the menu file. This information usually means the default section, graphical menu, timeout etc. As argument it takes a reference to the list of hashes representing lines of the section, returns a reference to a hash containing the important information.
$lines_ref = Bootloader::Core::ZIPL->Info2Global (\%section_info, \@section_names, \@sections);
Takes the info about the global options and uses it to construct the list of lines. The info about global option also contains the original lines. As parameter, takes the section info (reference to a hash) and a list of sectino names, returns the lines (a list of hashes).
*
"Bootloader::Core::ZIPL->MangleSections (\@sections, \%global);"

Modifies the section and global data so that the data which is de-facto global, but in zipl.conf is in sections (defaultboot, menu) is moved to the global section. Modifies the data which it gets via references directly!!!

($lines_ref, $com_bef) Bootloader::Core::ZIPL->ProcessSingleMenuFileLine ($lines, $com_bef, $separator);
processes line represented as string and returns it represented as hashes (containing key, value, relevant comments). The list may be empty, contain one or more items. As argument, it takes a line (as string), comment from previous lines and separator between the key and value. Returns a reference to a list of hashed and a pending comment.
$line = Bootloader::Core::ZIPL->CreateSingleMenuFileLine ($key, $value, $separator);
Transforms a line (hash) to a string to save. As arguments it takes the the key, the value and a string to separate the key and the value. Returns a string.