home *** CD-ROM | disk | FTP | other *** search
- /**
- * File:
- * lvm_lib.ycp
- *
- * Module:
- * LVM
- *
- * Summary:
- * main lib for defines, which are not lv or pv specific
- *
- * Authors:
- * mike <mike@suse.de>
- *
- * $Id: lvm_lib.ycp 27442 2006-01-30 14:53:09Z fehr $
- *
- */
-
- {
-
-
- include "partitioning/partition_defines.ycp";
- include "partitioning/signatures.ycp";
-
- textdomain "storage";
-
- define string lvmVg( string vg )
- {
- integer pos = search( vg, "/" );
- if( pos!=nil )
- return( substring( vg, pos+1 ));
- else
- return( vg );
- }
-
- //////////////////////////////////////////////////////////////////////
- // get a list of all volume groups in the targetMap
-
- define list get_vgs( map<string,map> targetMap )
- ``{
- list lvm_vg = [];
-
- foreach( string dev, map devmap, targetMap,
- ``{
- if ( devmap["type"]:`CT_UNKNOWN==`CT_LVM )
- {
- // add a found volume group
- lvm_vg = add( lvm_vg, substring(dev, 5) );
- }
- });
- return( lvm_vg );
- };
-
- //////////////////////////////////////////////////////////////////////
- // pesize to byte
- // in: <number>[kKmM][bB]
- //
- // return "0" if input is invalid
- //
- // pesize is valid 8K to 512M in power of 2
- // 8 is 8k
- // 16K == 16k == 16KB == 16kb
- define integer pesize_str_to_byte( string input )
- ``{
- integer num = kmgt_str_to_byte( input );
- if( findfirstnotof( input, "0123456789 " ) == nil )
- num = num*1024;
-
- integer ret = num;
-
- if( ret % 1024 != 0 )
- ret = 0;
- else
- {
- while( num>1 && ret>0 )
- {
- if( num%2 != 0 )
- ret = 0;
- else
- num = num/2;
- }
- }
- if( ret < 8*1024 || ret > 524288*1024 )
- {
- ret = 0;
- }
- return( ret );
- };
-
-
- //////////////////////////////////////////////////////////////////////
- // Let the User create a new Volume group: open dialog ...
- // return: the changed targetMap and lvm_vgs and cancelled
-
- define map addVolumeGroup( map vg, map<string,map> targetMap, list lvm_vgs )
- ``{
- boolean cancelled = true;
- string current_vg = "";
- integer pesize = 0;
-
-
- // has the user cancelled the dialog?
- if( size(vg)>0 )
- {
- // Now the user has created a new vg: make it the current vg
- current_vg = vg["vgname"]:"error";
- lvm_vgs = add( lvm_vgs, current_vg);
- pesize = vg["pesize"]:0;
-
- // Display current vg:
- if (UI::WidgetExists(`id(`rvg)) && UI::WidgetExists(`id(`vg)))
- {
- new_vg_list( lvm_vgs );
- UI::ChangeWidget( `id(`vg), `Value, current_vg);
- }
- cancelled = !Storage::CreateLvmVg( current_vg, pesize,
- vg["lvm2"]:true );
- }
- else
- {
- cancelled = true;
- }
-
- return( $[ "cancelled" : cancelled, "vg" : current_vg ]);
- };
-
- //////////////////////////////////////////////////////////////////////
- // Remove the specified volume group
- // return: boolean if removal was succesful
-
- define boolean removeVolumeGroup( string current_vg )
- ``{
- return( Storage::DeleteLvmVg( current_vg ));
- };
- }
-