ACC SHELL
/**
* File:
* include/bootloader/routines/lib-iface.ycp
*
* Module:
* Bootloader installation and configuration
*
* Summary:
* Functions to interface the bootloader library
*
* Authors:
* Jiri Srain <jsrain@suse.cz>
*
* $Id: lib_iface.ycp 56945 2009-04-23 14:48:09Z juhliarik $
*
* WARNING:
* To be included to BootCommon.ycp only
* Use import "BootCommon" instead.
*/
{
textdomain "bootloader";
import "System::Bootloader_API";
import "Storage";
import "Mode";
/**
* Loader the library has been initialized to use
*/
string library_initialized = nil;
/**
* Declarations...
*/
global boolean DefineMultipath(map<string,string> multipath_map);
/**
* Retrieve the data for perl-Bootloader library from Storage module
* and pass it along
* @return nothing
*/
// FIXME: this should be done directly in perl-Bootloader through LibStorage.pm
global void SetDiskInfo () {
BootStorage::InitDiskInfo();
y2milestone ("Information about partitioning: %1", BootStorage::partinfo);
y2milestone ("Information about MD arrays: %1", BootStorage::md_info);
y2milestone ("Mapping real disk to multipath: %1", BootStorage::multipath_mapping);
System::Bootloader_API::setMountPoints ((map<string,string>) BootStorage::mountpoints);
System::Bootloader_API::setPartitions ((list<list<string> >) BootStorage::partinfo);
System::Bootloader_API::setMDArrays ((map<string,list<string> >) BootStorage::md_info);
DefineMultipath(BootStorage::multipath_mapping);
}
/**
* Initialize the bootloader library
* @param force boolean true if the initialization is to be forced
* @param loader string the loader to initialize the library for
* @return boolean true on success
*/
global boolean InitializeLibrary (boolean force, string loader) {
if (!force && loader == library_initialized)
return false;
BootStorage::InitMapDevices ();
y2milestone ("Initializing lib for %1", loader);
string architecture = BootArch::StrArch();
System::Bootloader_API::setLoaderType (loader, architecture);
integer out = System::Bootloader_API::defineUdevMapping(BootStorage::all_devices);
if (out == nil)
y2error("perl-Bootloader library was not initialized");
y2milestone ("Putting partitioning into library");
// pass all needed disk/partition information to library
SetDiskInfo();
y2milestone ("Library initialization finished");
library_initialized = loader;
return true;
}
/**
* Set boot loader sections
* @param sections a list of all loader sections (as maps)
* @return boolean true on success
*/
global boolean SetSections (list<map<string,any> > sections) {
sections = maplist (map<string,any> s, sections, {
if (Mode::normal())
{
if ((s["__changed"]:false) || (s["__auto"]:false))
s["__modified"] = "1";
} else {
s["__modified"] = "1";
}
return s;
});
y2milestone ("Storing bootloader sections %1", sections);
boolean ret = System::Bootloader_API::setSections (sections);
if (! ret)
y2error ("Storing bootloader sections failed");
return ret;
}
/**
* Get boot loader sections
* @return a list of all loader sections (as maps)
*/
global list<map<string,any> > GetSections () {
y2milestone ("Reading bootloader sections");
list<map<string,any> > sects = System::Bootloader_API::getSections ();
if (sects == nil)
{
y2error ("Reading sections failed");
return [];
}
y2milestone ("Read sections: %1", sects);
return sects;
}
/**
* Set global bootloader options
* @param globals a map of global bootloader options
* @return boolean true on success
*/
global boolean SetGlobal (map<string,string> globals) {
y2milestone ("Storing global settings %1", globals);
globals["__modified"] = "1";
boolean ret = System::Bootloader_API::setGlobalSettings (globals);
if (! ret)
y2error ("Storing global settings failed");
return ret;
}
/**
* Get global bootloader options
* @return a map of global bootloader options
*/
global map<string,string> GetGlobal () {
y2milestone ("Reading bootloader global settings");
map<string,string> glob = System::Bootloader_API::getGlobalSettings ();
if (glob == nil)
{
y2error ("Reading global settings failed");
return $[];
}
y2milestone ("Read global settings: %1", glob);
return glob;
}
/**
* Get bootloader configuration meta data such as field type descriptions
* @return a map of meta data for global and section entries
*/
global map<string,string> GetMetaData () {
y2milestone ("Reading meta data for global and section settings");
// FIXME: DiskInfo should be read directly by perl-Bootloader
// send current disk/partition information to perl-Bootloader
SetDiskInfo();
y2milestone ("Calling getMetaData");
map<string,string> meta = System::Bootloader_API::getMetaData ();
y2milestone ("Returned from getMetaData");
if (meta == nil)
{
y2error ("Reading meta data failed");
return $[];
}
y2milestone ("Read meta data settings: %1", meta);
return meta;
}
/**
* Set the device mapping (Linux <-> Firmware)
* @param device_map a map from Linux device to Firmware device identification
* @return boolean true on success
*/
global boolean SetDeviceMap (map<string,string> device_map) {
y2milestone ("Storing device map");
boolean ret = System::Bootloader_API::setDeviceMapping (device_map);
if (! ret)
y2error ("Storing device map failed");
return ret;
}
/**
* Set the mapping (real device <-> multipath)
* @param map<string,string> map from real device to multipath device
* @return boolean true on success
*/
global boolean DefineMultipath(map<string,string> multipath_map) {
y2milestone ("Storing multipath map: %1", multipath_map);
if (size(multipath_map) == 0)
{
y2milestone("Multipath was not detected");
return true;
}
boolean ret = System::Bootloader_API::defineMultipath (multipath_map);
if (! ret)
y2error ("Storing multipath map failed");
return ret;
}
/**
* Get the device mapping (Linux <-> Firmware)
* @return a map from Linux device to Firmware device identification
*/
global map<string,string> GetDeviceMap () {
y2milestone ("Reading device mapping");
map<string,string> devmap = System::Bootloader_API::getDeviceMapping ();
if (devmap == nil)
{
y2error ("Reading device mapping failed");
return $[];
}
y2milestone ("Read device mapping: %1", devmap);
return devmap;
}
/*
* Display the log file written by the underlying bootloader libraries
*/
global void bootloaderError (string error) {
string bl_logfile = "/var/log/YaST2/y2log_bootloader";
string bl_log = (string)SCR::Read (.target.string, bl_logfile);
errorWithLogPopup (
sformat (
// error popup - label, %1 is bootloader name
_("Error occurred while installing %1."),
BootCommon::getLoaderName (BootCommon::getLoaderType (false), `summary)
),
bl_log
);
y2error ("%1", error);
}
/**
* Read the files from the system to internal cache of the library
* @param avoid_reading_device_map do not read the device map, but use internal
* data
* @return boolean true on success
*/
global boolean ReadFiles (boolean avoid_reading_device_map) {
y2milestone ("Reading Files");
boolean ret = System::Bootloader_API::readSettings (avoid_reading_device_map);
if (! ret)
y2error ("Reading files failed");
return ret;
}
/**
* Flush the internal cache of the library to the disk
* @return boolean true on success
*/
global boolean CommitSettings () {
y2milestone ("Writing files to system");
boolean ret = System::Bootloader_API::writeSettings ();
if (! ret)
bootloaderError ("Writing files to system failed");
return ret;
}
/**
* Update the bootloader settings, make updated saved settings active
* @return boolean true on success
*/
global boolean UpdateBootloader () {
y2milestone ("Updating bootloader configuration");
boolean ret = System::Bootloader_API::updateBootloader (true);
y2milestone ("return value from updateBootloader: %1", ret);
if (! ret)
bootloaderError ("Error occurred while updating configuration files");
return ret;
}
/**
* Update append in from boot section, it means take value from "console"
* and add it to "append"
*
* @param string append from section
* @param string console from section
* @return string updated append with console
*/
global string UpdateSerialConsole (string append, string console) {
y2milestone ("Updating append: %1 with console: %2", append, console);
string ret = System::Bootloader_API::updateSerialConsole(append, console);
y2milestone ("return updated value of append: %1", ret);
if (ret == nil)
bootloaderError ("Error occurred while updating append");
return ret;
}
/**
* Initialize the boot loader (eg. modify firmware, depending on architecture)
* @return boolean true on success
*/
global boolean InitializeBootloader () {
y2milestone ("Initializing bootloader");
boolean ret = System::Bootloader_API::initializeBootloader ();
if (! ret)
bootloaderError ("Error occurred while initializing bootloader");
return ret;
}
/**
* Get contents of files from the library cache
* @return a map filename -> contents, empty map in case of fail
*/
global map<string,string> GetFilesContents () {
y2milestone ("Getting contents of files");
map<string,string> ret = System::Bootloader_API::getFilesContents ();
if (ret == nil)
{
y2error ("Getting contents of files failed");
return $[];
}
return ret;
}
/**
* Set the contents of all files to library cache
* @param files a map filename -> contents
* @return boolean true on success
*/
global boolean SetFilesContents (map<string,string> files) {
y2milestone ("Storing contents of files");
boolean ret = System::Bootloader_API::setFilesContents (files);
if (! ret)
y2error ("Setting file contents failed");
return ret;
}
/**
* Analyse content of MBR
*
* @param string device name ("/dev/sda")
* @return string result of analyse ("GRUB stage1", "uknown",...)
*/
global string examineMBR (string device)
{
string ret = System::Bootloader_API::examineMBR (device);
y2milestone("Device: %1 includes in MBR: %2", device, ret);
return ret;
}
} //end of include
/*
* Local variables:
* mode: ycp
* mode: font-lock
* mode: auto-fill
* indent-level: 4
* fill-column: 78
* End:
*/
ACC SHELL 2018