[gparted] Only set lvm partition flag on tables which support it (#746204)



commit e9cc0b15a5517809379448b06ea1eeb42f6ac01b
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Mar 14 10:43:59 2015 +0000

    Only set lvm partition flag on tables which support it (#746204)
    
    Attempting to create a new partition on a pc98 partition table fails
    with the following libparted error:
    
        The flag 'lvm' is not available for pc98 disk labels.
    
    This has been broken since LVM2 Physical Volume read-write support was
    first added in this commit:
    
        c3ab62591b73266f43b379d9a7aef3be13f3c384
        Add creation of LVM2 PVs (#670171)
    
    Fix by only clearing and setting the lvm partition flag when the type of
    the partition table supports it.  When creating a partition to contain
    an LVM2 PV and the lvm flag is not support add the following message to
    the operation results to explain that setting the lvm partition flag was
    skipped and why:
    
        Skip setting unsupported partition flag: lvm
    
    Bug 746204 - Creating partitions on pc98 table fails with lvm flag not
                 available

 src/GParted_Core.cc |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index b207e4c..4733619 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3187,13 +3187,16 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
                        if ( ! lp_fs_type )
                                lp_fs_type = ped_file_system_type_get( "ext2" );
 
+                       bool supports_lvm_flag = ped_partition_is_flag_available( lp_partition, 
PED_PARTITION_LVM );
+
                        if ( lp_fs_type && partition.filesystem != FS_LVM2_PV )
                        {
                                // Also clear any libparted LVM flag so that it doesn't
                                // override the file system type
-                               if ( ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 0 ) &&
-                                    ped_partition_set_system( lp_partition, lp_fs_type )         &&
-                                    commit( lp_disk )                                               )
+                               if ( ( ! supports_lvm_flag                                          ||
+                                      ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 0 )    ) &&
+                                    ped_partition_set_system( lp_partition, lp_fs_type )                &&
+                                    commit( lp_disk )                                                      )
                                {
                                        operationdetail.get_last_child().add_child(
                                                OperationDetail( String::ucompose( _("new partition type: 
%1"),
@@ -3205,7 +3208,8 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
                        }
                        else if ( partition.filesystem == FS_LVM2_PV )
                        {
-                               if ( ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 1 ) &&
+                               if ( supports_lvm_flag                                            &&
+                                    ped_partition_set_flag( lp_partition, PED_PARTITION_LVM, 1 ) &&
                                     commit( lp_disk )                                               )
                                {
                                        operationdetail.get_last_child().add_child(
@@ -3215,6 +3219,15 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
                                                                 FONT_ITALIC ) );
                                        return_value = true;
                                }
+                               else if ( ! supports_lvm_flag )
+                               {
+                                       operationdetail.get_last_child().add_child(
+                                               OperationDetail( String::ucompose( _("Skip setting 
unsupported partition flag: %1"),
+                                                                                  
ped_partition_flag_get_name( PED_PARTITION_LVM ) ),
+                                                                STATUS_NONE,
+                                                                FONT_ITALIC ) );
+                                       return_value = true;
+                               }
                        }
                }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]