2011-11-28 05:33:51 -07:00
|
|
|
/* Copyright (C) 2012 Mike Fleetwood
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-01-28 07:25:31 -07:00
|
|
|
#include "../include/LVM2_PV_Info.h"
|
2011-11-28 05:33:51 -07:00
|
|
|
#include "../include/lvm2_pv.h"
|
|
|
|
|
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2012-02-13 05:44:45 -07:00
|
|
|
const Glib::ustring lvm2_pv::get_custom_text( CUSTOM_TEXT ttype, int index )
|
|
|
|
{
|
|
|
|
/*TO TRANSLATORS: these labels will be used in the partition menu */
|
|
|
|
static const Glib::ustring activate_text = _( "Ac_tivate" ) ;
|
|
|
|
static const Glib::ustring deactivate_text = _( "Deac_tivate" ) ;
|
|
|
|
|
|
|
|
switch ( ttype )
|
|
|
|
{
|
|
|
|
case CTEXT_ACTIVATE_FILESYSTEM:
|
|
|
|
return index == 0 ? activate_text : "" ;
|
|
|
|
case CTEXT_DEACTIVATE_FILESYSTEM:
|
|
|
|
return index == 0 ? deactivate_text : "" ;
|
|
|
|
default:
|
|
|
|
return "" ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-28 05:33:51 -07:00
|
|
|
FS lvm2_pv::get_filesystem_support()
|
|
|
|
{
|
|
|
|
FS fs ;
|
|
|
|
fs .filesystem = GParted::FS_LVM2_PV ;
|
|
|
|
|
2012-01-28 07:25:31 -07:00
|
|
|
LVM2_PV_Info lvm2_pv_info ;
|
|
|
|
if ( lvm2_pv_info .is_lvm2_pv_supported() )
|
2011-11-28 05:33:51 -07:00
|
|
|
{
|
2012-01-12 06:15:26 -07:00
|
|
|
fs .read = FS::EXTERNAL ;
|
|
|
|
fs .create = FS::EXTERNAL ;
|
2012-01-15 12:41:28 -07:00
|
|
|
fs .grow = FS::EXTERNAL ;
|
|
|
|
fs .shrink = FS::EXTERNAL ;
|
|
|
|
fs .move = FS::GPARTED ;
|
|
|
|
fs .check = FS::EXTERNAL ;
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return fs ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lvm2_pv::set_used_sectors( Partition & partition )
|
|
|
|
{
|
2012-01-28 07:25:31 -07:00
|
|
|
LVM2_PV_Info lvm2_pv_info ;
|
2012-03-08 08:37:31 -07:00
|
|
|
T = (Sector) lvm2_pv_info .get_size_bytes( partition .get_path() ) ;
|
|
|
|
N = (Sector) lvm2_pv_info .get_free_bytes( partition .get_path() ) ;
|
|
|
|
if ( T > -1 && N > -1 )
|
|
|
|
{
|
|
|
|
T = Utils::round( T / double(partition .sector_size) ) ;
|
|
|
|
N = Utils::round( N / double(partition .sector_size) ) ;
|
|
|
|
partition .set_sector_usage( T, N ) ;
|
|
|
|
}
|
2012-02-09 13:58:55 -07:00
|
|
|
|
2012-02-12 07:44:50 -07:00
|
|
|
std::vector<Glib::ustring> error_messages = lvm2_pv_info .get_error_messages( partition .get_path() ) ;
|
2012-02-09 13:58:55 -07:00
|
|
|
if ( ! error_messages .empty() )
|
|
|
|
{
|
|
|
|
for ( unsigned int i = 0 ; i < error_messages .size() ; i ++ )
|
|
|
|
partition .messages .push_back( error_messages [ i ] ) ;
|
|
|
|
}
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void lvm2_pv::read_label( Partition & partition )
|
|
|
|
{
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::write_label( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
void lvm2_pv::read_uuid( Partition & partition )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::write_uuid( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operationdetail )
|
|
|
|
{
|
2012-01-12 06:15:26 -07:00
|
|
|
return ! execute_command( "lvm pvcreate -M 2 " + new_partition .get_path(), operationdetail ) ;
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
|
|
|
|
{
|
2012-01-15 12:41:28 -07:00
|
|
|
Glib::ustring size = "" ;
|
|
|
|
if ( ! fill_partition )
|
|
|
|
size = " --setphysicalvolumesize " +
|
|
|
|
Utils::num_to_str( floor( Utils::sector_to_unit(
|
|
|
|
partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K " ;
|
|
|
|
return ! execute_command( "lvm pvresize -v " + size + partition_new .get_path(), operationdetail ) ;
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::move( const Partition & partition_new
|
|
|
|
, const Partition & partition_old
|
|
|
|
, OperationDetail & operationdetail
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::copy( const Glib::ustring & src_part_path
|
|
|
|
, const Glib::ustring & dest_part_path
|
|
|
|
, OperationDetail & operationdetail )
|
|
|
|
{
|
2012-01-15 12:41:28 -07:00
|
|
|
//Copy not implemented.
|
|
|
|
// Metadata fully describing a Volume Group is stored at the start of
|
|
|
|
// each Physical Volume member. Internally LVM2 primarily uses UUIDs
|
|
|
|
// to uniquely identify all objects (PVs, VG and LVs) but the interface
|
|
|
|
// uses device names and VG and LV names. The general case of copying
|
|
|
|
// a PV could confuse LVM2 because it will result in duplicate objects,
|
|
|
|
// or even duplicate partial VGs and LVs if they span multiple PVs, so
|
|
|
|
// it is not safe and should be achieved using other LVM2 commands. A
|
|
|
|
// specific case of copying a PV is the right action when it is as part
|
|
|
|
// of the transfer of an exported VG to a remote machine via storage
|
|
|
|
// which will be detached from the local machine and attached to the
|
|
|
|
// remote machine, but would probably fit better at a VG manipulation
|
|
|
|
// layer. Thus copying of PVs is not implemented.
|
2011-11-28 05:33:51 -07:00
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & operationdetail )
|
|
|
|
{
|
2012-01-15 12:41:28 -07:00
|
|
|
return ! execute_command( "lvm pvck -v " + partition .get_path(), operationdetail ) ;
|
2011-11-28 05:33:51 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} //GParted
|