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
/
modules
/
OSRSwap.ycp
< prev
next >
Wrap
Text File
|
2006-11-29
|
4KB
|
149 lines
/**
* File:
* OSRSwap.ycp
*
* Module:
* YaST OS Repair. Automatic error detection & repair tool for Linux.
*
* Summary:
* YaST OS Repair. Automatic error detection & repair tool for Linux.
*
* Author:
* Johannes Buchhold <jbuch@suse.de>
*
* $Id: OSRSwap.ycp 25357 2005-09-05 15:16:52Z jsuchome $
*/
{
module "OSRSwap";
import "OSRExecute";
import "OSRPopup";
import "Mode";
import "Storage";
import "Partitions";
textdomain "repair";
/**
* Create swap area on a swap partition.
*/
global define symbol Repair( string target )``{
//////////////////////////////////////////////////////////////////////////
//
// Repair swap area with mkswap
//
//////////////////////////////////////////////////////////////////////////
// "%1": will be replaced with "/dev/hda" or "/dev/sda" ...
string error_message = sformat(_("
The partition %1 has the file system ID 130, but
contains no valid swap area. To create
a valid swap area, press Repair.
Press Skip to not perform the repair.
"), target);
// helptext 1/2
string help_text = _("
<p>A partition with the ID 130 should be
a Linux swap partition. All swap partitions
need a valid swap area, which is created with
the tool mkswap.</p>
") +
// helptext 2/2
_("<p>If you know how to use mkswap,
close this tool and create a new swap area
on the damaged swap partition. Otherwise
close this help dialog and press
Repair for automatic
repair.</p>
");
while( true )
{
if (!OSRPopup::Repair(_("Error Detected"), error_message, help_text))
return `cancel;
UI::OpenDialog(`VBox(`VSpacing(1),
`Label(_("Creating swap area...")),
`VSpacing(1)));
boolean ret = OSRExecute::Command(.local.bash,"/sbin/mkswap "+target);
UI::CloseDialog();
if ( ret ) return `ok;
}
};
/**
* Get all valid swap-partitions.
* @return list The list of valid swap-partitions.
*/
global define list<string> Partitions() ``{
list<string> ret = [];
foreach (string dev, map disk, (map<string,map<string,any> >)Storage::GetTargetMap(), ``{
if( disk["type"]:`CT_UNKNOWN==`CT_DISK )
{
list l = filter (map p, disk["partitions"]:[], ``(
!p["delete"]:false &&
(p["fsid"]:0 == Partitions::fsid_swap ||
p["detected_fs"]:nil == `swap))
);
ret = (list<string>) union (ret, maplist (map p, (list<map<string,any> >)l,
``(p["device"]:"")));
}
});
y2debug ("GetPartitionList ret=%1", ret );
return ret;
};
/**
* Returns a list of names (e.g. ["/dev/hda1", "/dev/hdb3"]) of all
* partitions that can be mounted to the system as swap out of
* the specified list.
*
* @param list partition_list A list of partitions out of which
* the "swapable" partitions are to be returned,
* e.g. ["/dev/hda1", "/dev/hdb3"] -
* @return list The list of partition names that were successfully added
* to the system as swap partitions.
*/
global define list<string> ValidPartitions(list<string> partition_list) ``{
list<string> swap_possible_list = [];
list already_swapped_on = Storage::SwappingPartitions();
foreach(string partition_item, partition_list, ``{
if (contains(already_swapped_on, partition_item) || Mode::test ())
{
// this partition is already swapped on,so it seems to be swapable
swap_possible_list = add( swap_possible_list, partition_item );
}
else
{
// run /sbin/swapon
if ( WFM::Execute (.local.bash, "/sbin/swapon " + partition_item ) == 0)
{
// run /sbin/swapoff
if( WFM::Execute (.local.bash, "/sbin/swapoff " + partition_item ) == 0 ) {
swap_possible_list = add(swap_possible_list, partition_item);
}
else {
y2error("swapoff paritition %1 is not possible",partition_item);
}
}
}
});
return swap_possible_list;
};
}//EOF