home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 January, February, March & April
/
Chip-Cover-CD-2007-02.iso
/
boot
/
i386
/
root
/
usr
/
share
/
YaST2
/
include
/
bootloader
/
routines
/
lib_iface.ycp
< prev
next >
Wrap
Text File
|
2006-11-29
|
11KB
|
369 lines
/**
* 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 34433 2006-11-16 16:28:10Z jplack $
*
* WARNING:
* To be included to BootCommon.ycp only
* Use import "BootCommon" instead.
*/
{
textdomain "bootloader";
import "System::Bootloader_API";
import "Storage";
/**
* Loader the library has been initialized to use
*/
string library_initialized = nil;
/**
* 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 () {
map<string,list<string> > md_info = $[];
map<string,any> mountpoints = mapmap (string k, list v,
(map<string,list>)Storage::GetMountPoints (),
{
// detect all raid1 md devices and mark them in md_info
any device = v[0]:nil;
if (v[3]:"" == "raid1")
md_info[(string)device]=[];
return $[ k : device ];
});
mountpoints = filter (string k, any v, mountpoints, {
string tmpdir = (string)SCR::Read (.target.tmpdir);
integer tmp_sz = size (tmpdir);
return is (v, string) && substring (k, 0, tmp_sz) != tmpdir;
});
if (! Stage::initial ())
{
// get what's really mounted
list<map<string,any> > mounted_list = (list<map<string,any> >)
SCR::Read (.proc.mounts);
map<string,string> mounted = listmap (map<string,any> m, mounted_list, {
return $[ m["file"]:"" : m["spec"]:"" ];
});
y2milestone ("Really mounted: %1", mounted);
mountpoints = filter (string k, any v, mountpoints, {
return mounted[k]:nil == v;
});
}
y2milestone ("Detected mountpoints: %1", mountpoints);
map<string,map> tm = (map<string,map>)Storage::GetTargetMap ();
list<list<list> > pi = maplist (string disk, map info, tm,
{
if (info["type"]:`CT_UNKNOWN==`CT_LVM)
return [];
if (info["type"]:`CT_UNKNOWN==`CT_EVMS)
return [];
list partitions = info["partitions"]:[];
list<list> parts = maplist (map p, (list<map>)partitions, {
string raid = "";
if( p["used_by_type"]:`UB_NONE==`UB_MD )
raid = p["used_by"]:"";
string device = p["device"]:"";
// We only pass along RAID1 devices as all other causes
// severe breakage in the bootloader stack
if (raid != "") {
raid = "/dev/" + raid;
if (haskey (md_info, raid)) {
list<string> members = md_info[raid]:[];
members = add (members, device);
md_info[raid] = members;
}
}
any nr = p["nr"]:nil;
if (nr == nil)
nr = 0;
string nr_str = sformat ("%1", nr);
/* FIXME: And the other information about the disk ?:
p["fsid"] = LibStorage::PartitionInfo::swig_id_get(info);
p["fstype"] = Partitions::FsIdToString( p["fsid"]:0 );
p["region"] = [ LibStorage::PartitionInfo::swig_cylStart_get(info),
LibStorage::PartitionInfo::swig_cylSize_get(info) ];
p["type"] = toSymbol( conv_ptype, t );
p["boot"] = true;
*/
return [ device, disk, nr_str, tostring(p["fsid"]:0),
p["fstype"]:"unknown", tostring(p["type"]:nil),
tostring(p["region", 0]:0), tostring(p["region", 1]:0)
];
});
return parts;
});
list<list> partinfo = flatten (pi);
partinfo = filter (list p, partinfo, {return p != nil && p != [];});
y2milestone ("Information about partitioning: %1", partinfo);
y2milestone ("Information about MD arrays: %1", md_info);
System::Bootloader_API::setMountPoints ((map<string,string>) mountpoints);
System::Bootloader_API::setPartitions ((list<list<string> >) partinfo);
System::Bootloader_API::setMDArrays ((map<string,list<string> >) md_info);
}
/**
* 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;
y2milestone ("Initializing lib for %1", loader);
System::Bootloader_API::setLoaderType (loader);
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,string> > sections) {
y2milestone ("Storing bootloader sections %1", sections);
sections = maplist (map<string,string> s, sections, {
s["__modified"] = "1";
s = filter (string key, string value, s, {
return (! is (value, string)) || (value != "");
});
return s;
});
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,string> > GetSections () {
y2milestone ("Reading bootloader sections");
list<map<string,string> > 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;
}
/**
* 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
* @return boolean true on success
*/
global boolean ReadFiles () {
y2milestone ("Reading Files");
boolean ret = System::Bootloader_API::readSettings ();
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;
}
/**
* 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;
}
} //end of include
/*
* Local variables:
* mode: ycp
* mode: font-lock
* mode: auto-fill
* indent-level: 4
* fill-column: 78
* End:
*/