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
/
partitioning
/
loop.ycp
< prev
next >
Wrap
Text File
|
2006-11-29
|
9KB
|
334 lines
/**
* File:
* loop.ycp
*
* Module:
* Configuration loop file setup
*
* Summary:
* Functions for configuration of loop file setup
*
* Authors:
* Thomas Fehr <fehr@suse.de>
*
* $Id: loop.ycp 32189 2006-08-07 11:21:35Z fehr $
*
*/
{
textdomain "storage";
import "Wizard";
import "Storage";
import "FileSystems";
import "Partitions";
import "Label";
include "partitioning/partition_defines.ycp";
include "partitioning/custom_part_dialogs.ycp";
include "partitioning/custom_part_lib.ycp";
/**
* LoopDlgHelp
* @return string
*/
define string LoopDlgHelp( string pb, string cb, string sb )
``{
// help text richtext format
// %1 is replaced by description text for file pathname
string helptext = sformat( _("
<p><b>%1:</b><br>This must be an absolute path to the file
containing the data for the encrypted loop device to set up.</p>
"), pb );
// help text richtext format, continued
// %1 is replaced by description text for create button
helptext = helptext + sformat( _("
<p><b>%1:</b><br>If this is checked, the file will be
created with the size given in the next field. <b>NOTE:</b> If the
file already exists, all data in it is lost.</p>
"), cb );
// help text richtext format, continued
// %1 is replaced by description text for file size
helptext = helptext + sformat( _("
<p><b>%1:</b><br>This is the size of the loop file.
The file system to create in the encrypted loop device will have
this size.</p>
"), sb );
// help text richtext format, continued
helptext = helptext + _("
<p><b>NOTE:</b>During installation, there cannot be any consistency
checks about file size and path names because the file system is not
accessible. It will be created at the end of installation. Be
careful about the size and path name you provide.</p>
");
return helptext;
};
/**
* LoopExpertDlg dialog
* edit loop options
*/
define map<string,any> LoopExpertDlg( boolean edit, map<string,any> part, map<symbol,map> file_systems )
``{
string caption = "";
if( edit )
{
// heading text
caption = sformat( _("Edit Loop Device Setup of %1"),
part["fpath"]:"" );
}
else
{
// heading text
caption = _("Create New Loop Device Setup");
}
// label text
string pb = _("P&ath Name of File");
// label text
string cb = _("C&reate Loop File");
// label text
string sb = _("Si&ze of Loop File");
term contents = `VBox( `HSpacing( 60 ),
`HBox( `HSpacing(2),
LoopOptionsDlg(pb,cb,sb),
`HSpacing(20)
),
`VSpacing(1),
`HBox( FormatDlg( part, file_systems ),
`HSpacing(2),
`Top(`ReplacePoint( `id(`mount_dlg_rp),
MountDlg( part, [] )))
)
);
contents = `VBox(
`Heading(caption),
`VSpacing(1),
`VStretch(),
contents,
`VSpacing(1),
`VStretch(),
`HBox(
`PushButton(`id(`ok), `opt(`default),
Label::OKButton() ),
`PushButton(`id(`cancel), Label::CancelButton() )
));
/////////////////////////////////////////////////////////////
// Open main dialog for Raid
/////////////////////////////////////////////////////////////
string ht = LoopDlgHelp( deletechars(pb,"&"),
deletechars(cb,"&"),
deletechars(sb,"&"));
UI::OpenDialog( `opt(`decorated ),
`HBox( `HWeight(30,`RichText(ht)),
`HStretch(),
`HSpacing(1),
`HWeight(70, contents ),
`HSpacing(1),
`HStretch()
));
////////////////////////////////////////////////////////////////
// configure main dialog for the first call
string lsize = ByteToHumanStringWithZero(part["size_k"]:0*1024);
UI::ChangeWidget( `id(`loop_path), `Value, part["fpath"]:"" );
UI::ChangeWidget( `id(`loop_path), `ValidChars,
FileSystems::nchars + "-._:/" );
UI::ChangeWidget( `id(`loop_create), `Value, part["create_file"]:false );
UI::ChangeWidget( `id(`loop_size), `Value, lsize );
UI::ChangeWidget( `id(`loop_size), `Enabled, part["create_file"]:false );
UI::ChangeWidget( `id(`crypt_fs), `Enabled, true );
map<string,any> retval = eval(part);
symbol ret = `ok;
retval = HandlePartWidgetChanges( true, ret, file_systems, part, retval );
repeat
{
ret = (symbol)UI::UserInput();
y2milestone( "LoopExpertDlg %1", ret);
////////////////////////////////////////////////////////////
if( ret != `cancel )
{
retval = HandlePartWidgetChanges( false, ret, file_systems, part,
retval );
}
if( ret == `loop_create )
{
retval["create_file"] = UI::QueryWidget( `id(`loop_create), `Value );
UI::ChangeWidget( `id(`loop_size), `Enabled,
retval["create_file"]:false );
if( retval["create_file"]:false )
{
retval["format"] = true;
UI::ChangeWidget( `id(`format), `Value, true );
}
}
if( ret == `ok )
{
retval["fpath"] = UI::QueryWidget(`id(`loop_path), `Value);
retval["create_file"] = UI::QueryWidget(`id(`loop_create), `Value);
lsize = (string)UI::QueryWidget(`id(`loop_size), `Value);
integer nsize = kmgt_str_to_byte( lsize );
retval["size_k"] = nsize/1024;
y2milestone( "LoopExpertDlg size:%1 num:%2", lsize, nsize );
y2milestone( "LoopExpertDlg retval:%1", retval );
if( !check_max_size( nsize, 0 ) )
{
ret = `again;
continue;
}
if( size(retval["fpath"]:"")==0 ||
substring( retval["fpath"]:" ", 0, 1)!="/" )
{
// popup text
Popup::Error( sformat(_("The file name \"%1\" is invalid.
Use an absolute path name.
"), retval["fpath"]:" " ));
ret = `again;
continue;
}
if( !retval["create_file"]:false )
{
integer s = 0;
s = (integer)SCR::Read( .target.size, retval["fpath"]:"" );
y2milestone( "loop file size:%1", s );
if( Mode::normal () )
{
if( s<0 )
{
// popup text
Popup::Error( sformat(_("The file name \"%1\" does not exist
and the flag for create is off. Either use an existing file or activate
the create flag."), retval["fpath"]:" " ));
ret = `again;
continue;
}
else
retval["size_k"] = s/1024;
}
}
if( !retval["format"]:false && retval["create_file"]:false )
{
// popup text
Popup::Error( _("You chose to create the crypt file, but did not specify
that it should be formatted. This does not make sense.
Also check the format option.
"));
ret = `again;
continue;
}
map ret_mp = CheckOkMount( part["device"]:"", part, retval );
retval = ret_mp["map"]:$[];
y2milestone( "LoopExpertDlg ret_mp %1 part %2", ret_mp, part );
if( !ret_mp["ok"]:false )
{
if( ret_mp["field"]:`none != `none )
UI::SetFocus(`id( ret_mp["field"]:`none ));
ret = `again;
continue;
}
if( size(retval["mount"]:"")==0 )
{
// popup text
Popup::Error( _("Provide a mount point."));
ret = `again;
continue;
}
ret_mp = CheckDeviceFinalOk( retval );
if( !ret_mp["ok"]:false )
{
ret = `again;
}
else
{
retval = ret_mp["map"]:$[];
}
}
} until( ret == `ok || ret == `cancel || ret == `next ||
ret == `back || ret == `abort );
retval["symbol"] = ret;
y2milestone( "LoopExpertDlg ret:%1 retval=%2", ret, retval );
UI::CloseDialog();
return retval;
}
/**
* LoopSetup dialog
*
* Provide dialog for settings of loop device related parameters
*/
define symbol LoopSetup( boolean edit )
``{
string id = Storage::GetWizardKey();
string key = "/dev/loop";
y2milestone( "LoopSetup edit %1 id %2", edit, id );
map<string,any> part = $[];
map<string,map> tg = Storage::GetTargetMap();
if( edit )
{
part = Storage::GetPartition( tg, id );
}
else
{
part["device"] = Storage::GetLoopDevice();
part["type"] = `loop;
part["format"] = true;
part["enc_type"] = `twofish;
part["size_k"] = 50*1024;
part["used_fs"] = `ext3;
}
y2milestone( "LoopSetup part %1", part );
part = LoopExpertDlg( edit, part, (map <symbol, map>)
filter( any k, map e,
FileSystems::GetAllFileSystems(false, false),
``(e[`crypt]:false)));
symbol ret = part["symbol"]:`next;
// remove symbol key from data
part = filter( string key, any value, part, ``( key != "symbol" ));
if( ret == `ok )
{
Storage::UpdateLoop( part["device"]:"", part["fpath"]:"",
part["create_file"]:false,
part["size_k"]:0 );
Storage::ChangeVolumeProperties( part );
}
else if( !edit )
{
Storage::DeleteDevice( "/dev/loop", part["device"]:"" );
}
y2milestone( "LoopSetup ret = %1", ret );
return ret;
}
}