[gparted] Remove unnecessary sector_size parameter from Get_New_Partition methods



commit 24fa553385005a0beb97c8d0b1899b3d4a5df227
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Dec 16 20:15:58 2015 +0000

    Remove unnecessary sector_size parameter from Get_New_Partition methods
    
    The sector_size parameter is unnecessary as the value can be retrieved
    from the sector size of the selected Partition object on which the
    create new, copy & paste or resize/move operation is being performed.
    
    For the create new and resize/move operations it is trivial as the
    existing unallocated or in use Partition object on which the operation
    is being perform already contains the correct sector size.  For the copy
    & paste operation, which can copy across disk devices of different
    sector sizes, we merely have to use the sector size of the existing
    selected (destination) Partition object rather than copied (source)
    Partition object.  Hence these relevant lines in the new code:
    
        Dialog_Partition_Copy::set_data(selected_partition, copied_partition)
            new_partition = copied_partition.clone();
            ...
            new_partition->sector_size = selected_partition.sector_size;

 include/Dialog_Base_Partition.h |    6 +++---
 include/Dialog_Partition_Copy.h |    2 +-
 include/Dialog_Partition_New.h  |    2 +-
 src/Dialog_Base_Partition.cc    |   18 ++++++++----------
 src/Dialog_Partition_Copy.cc    |    5 +++--
 src/Dialog_Partition_New.cc     |   18 +++++++++++-------
 src/GParted_Core.cc             |    4 ++--
 src/Win_GParted.cc              |    6 +++---
 8 files changed, 32 insertions(+), 29 deletions(-)
---
diff --git a/include/Dialog_Base_Partition.h b/include/Dialog_Base_Partition.h
index 031d6b2..5ca0d83 100644
--- a/include/Dialog_Base_Partition.h
+++ b/include/Dialog_Base_Partition.h
@@ -41,8 +41,8 @@ public:
        ~Dialog_Base_Partition( ) ;
 
        void Set_Resizer( bool extended ) ;
-       const Partition & Get_New_Partition( Byte_Value sector_size );
-       
+       const Partition & Get_New_Partition();
+
 protected:
        enum SPINBUTTON {
                BEFORE  = 0,
@@ -56,7 +56,7 @@ protected:
                PASTE           = 2
        };
 
-       void prepare_new_partition( Byte_Value sector_size );
+       void prepare_new_partition();
 
        void Set_Confirm_Button( CONFIRMBUTTON button_type ) ;
        void Set_MinMax_Text( Sector min, Sector max ) ;
diff --git a/include/Dialog_Partition_Copy.h b/include/Dialog_Partition_Copy.h
index 7196f0f..7675c1f 100644
--- a/include/Dialog_Partition_Copy.h
+++ b/include/Dialog_Partition_Copy.h
@@ -31,7 +31,7 @@ public:
                               const Partition & copied_partition );
        ~Dialog_Partition_Copy();
 
-       const Partition & Get_New_Partition( Byte_Value sector_size );
+       const Partition & Get_New_Partition();
 
 private:
        Dialog_Partition_Copy( const Dialog_Partition_Copy & src );              // Not implemented copy 
constructor
diff --git a/include/Dialog_Partition_New.h b/include/Dialog_Partition_New.h
index 6e1dbb1..7c69882 100644
--- a/include/Dialog_Partition_New.h
+++ b/include/Dialog_Partition_New.h
@@ -37,7 +37,7 @@ public:
                             const std::vector<FS> & FILESYSTEMS );
        ~Dialog_Partition_New();
 
-       const Partition & Get_New_Partition( Byte_Value sector_size );
+       const Partition & Get_New_Partition();
 
 private:
        Dialog_Partition_New( const Dialog_Partition_New & src );              // Not implemented copy 
constructor
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index 18907c7..fc14c81 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -137,31 +137,29 @@ void Dialog_Base_Partition::Set_Resizer( bool extended )
        this ->show_all_children() ;
 }
 
-const Partition & Dialog_Base_Partition::Get_New_Partition( Byte_Value sector_size )
+const Partition & Dialog_Base_Partition::Get_New_Partition()
 {
        g_assert( new_partition != NULL );  // Bug: Not initialised by derived Dialog_Partition_*() 
constructor calling set_data()
 
-       prepare_new_partition( sector_size );
+       prepare_new_partition();
        return *new_partition;
 }
 
-void Dialog_Base_Partition::prepare_new_partition( Byte_Value sector_size )
+void Dialog_Base_Partition::prepare_new_partition()
 {
        g_assert( new_partition != NULL );  // Bug: Not initialised by derived Dialog_Partition_*() 
constructor calling set_data()
 
-       //set sector size of new partition
-       new_partition->sector_size = sector_size;
        Sector old_size = new_partition->get_sector_length();
 
        //FIXME:  Partition size is limited to just less than 1024 TeraBytes due
        //        to the maximum value of signed 4 byte integer.
        if ( ORIG_BEFORE != spinbutton_before .get_value_as_int() )
-               new_partition->sector_start = START + Sector(spinbutton_before.get_value_as_int()) * 
(MEBIBYTE / sector_size);
+               new_partition->sector_start = START + Sector(spinbutton_before.get_value_as_int()) * 
(MEBIBYTE / new_partition->sector_size);
 
        if ( ORIG_AFTER != spinbutton_after .get_value_as_int() )
                new_partition->sector_end =
                        new_partition->sector_start
-                       + Sector(spinbutton_size .get_value_as_int()) * (MEBIBYTE / sector_size)
+                       + Sector(spinbutton_size.get_value_as_int()) * (MEBIBYTE / new_partition->sector_size)
                        - 1 /* one sector short of exact mebibyte multiple */;
 
        //due to loss of precision during calcs from Sector -> MiB and back, it is possible
@@ -172,9 +170,9 @@ void Dialog_Base_Partition::prepare_new_partition( Byte_Value sector_size )
                new_partition->sector_end = START + total_length - 1;
 
        //grow a bit into small freespace ( < 1MiB ) 
-       if ( (new_partition->sector_start - START) < (MEBIBYTE / sector_size) )
+       if ( (new_partition->sector_start - START) < (MEBIBYTE / new_partition->sector_size) )
                new_partition->sector_start = START;
-       if ( ( START + total_length -1 - new_partition->sector_end ) < (MEBIBYTE / sector_size) )
+       if ( ( START + total_length - 1 - new_partition->sector_end ) < (MEBIBYTE / 
new_partition->sector_size) )
                new_partition->sector_end = START + total_length - 1;
 
        //set alignment
@@ -232,7 +230,7 @@ void Dialog_Base_Partition::prepare_new_partition( Byte_Value sector_size )
                }
        }
 
-       new_partition->free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / 
sector_size);
+       new_partition->free_space_before = Sector(spinbutton_before.get_value_as_int()) * (MEBIBYTE / 
new_partition->sector_size);
 
        //if the original before value has not changed, then set indicator to keep start sector unchanged
        if ( ORIG_BEFORE == spinbutton_before .get_value_as_int() )
diff --git a/src/Dialog_Partition_Copy.cc b/src/Dialog_Partition_Copy.cc
index 3b4d46c..bef5bff 100644
--- a/src/Dialog_Partition_Copy.cc
+++ b/src/Dialog_Partition_Copy.cc
@@ -112,6 +112,7 @@ void Dialog_Partition_Copy::set_data( const Partition & selected_partition, cons
        new_partition->device_path     = selected_partition.device_path;
        new_partition->inside_extended = selected_partition.inside_extended;
        new_partition->type            = selected_partition.inside_extended ? TYPE_LOGICAL : TYPE_PRIMARY;
+       new_partition->sector_size     = selected_partition.sector_size;
        //Handle situation where src sector size is smaller than dst sector size and an additional partial 
dst sector is required.
        new_partition->set_sector_usage(
                        (   ( ( copied_partition .sectors_used + copied_partition .sectors_unused ) * 
copied_partition .sector_size )
@@ -124,12 +125,12 @@ void Dialog_Partition_Copy::set_data( const Partition & selected_partition, cons
        this ->show_all_children() ;
 }
 
-const Partition & Dialog_Partition_Copy::Get_New_Partition( Byte_Value sector_size )
+const Partition & Dialog_Partition_Copy::Get_New_Partition()
 {
        g_assert( new_partition != NULL );  // Bug: Not initialised by constructor calling set_data()
 
        //first call baseclass to get the correct new partition
-       Dialog_Base_Partition::prepare_new_partition( sector_size );
+       Dialog_Base_Partition::prepare_new_partition();
 
        //set proper name and status for partition
        new_partition->status = STAT_COPY;
diff --git a/src/Dialog_Partition_New.cc b/src/Dialog_Partition_New.cc
index 5dc7651..4c0fef0 100644
--- a/src/Dialog_Partition_New.cc
+++ b/src/Dialog_Partition_New.cc
@@ -184,7 +184,7 @@ void Dialog_Partition_New::set_data( const Device & device,
        this ->show_all_children() ;
 }
 
-const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_size )
+const Partition & Dialog_Partition_New::Get_New_Partition()
 {
        g_assert( new_partition != NULL );  // Bug: Not initialised by constructor calling set_data()
 
@@ -202,8 +202,11 @@ const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_siz
 
        //FIXME:  Partition size is limited to just less than 1024 TeraBytes due
        //        to the maximum value of signed 4 byte integer.
-       new_start = START + (Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / sector_size)) ;
-       new_end  = new_start + (Sector(spinbutton_size .get_value_as_int()) * (MEBIBYTE / sector_size)) - 1 ;
+       new_start = START + Sector(spinbutton_before.get_value_as_int()) *
+                           (MEBIBYTE / new_partition->sector_size);
+       new_end  = new_start + Sector(spinbutton_size.get_value_as_int()) *
+                              (MEBIBYTE / new_partition->sector_size)
+                            - 1;
        
        /* due to loss of precision during calcs from Sector -> MiB and back, it is possible the new 
         * partition thinks it's bigger then it can be. Here we try to solve this.*/
@@ -213,15 +216,16 @@ const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_siz
                new_end = new_partition->sector_end;
 
        // Grow new partition a bit if freespaces are < 1 MiB
-       if ( new_start - new_partition->sector_start < MEBIBYTE / sector_size )
+       if ( new_start - new_partition->sector_start < MEBIBYTE / new_partition->sector_size )
                new_start = new_partition->sector_start;
-       if ( new_partition->sector_end - new_end < MEBIBYTE / sector_size )
+       if ( new_partition->sector_end - new_end < MEBIBYTE / new_partition->sector_size )
                new_end = new_partition->sector_end;
 
        // Copy a final few values needed from the original unallocated partition before
        // resetting the Partition object and populating it as the new partition.
        Glib::ustring device_path = new_partition->device_path;
        bool whole_device = new_partition->whole_device;
+       Sector sector_size = new_partition->sector_size;
        bool inside_extended = new_partition->inside_extended;
        new_partition->Reset();
        new_partition->Set( device_path,
@@ -268,7 +272,7 @@ const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_siz
                        break;
        }
 
-       new_partition->free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / 
sector_size);
+       new_partition->free_space_before = Sector(spinbutton_before .get_value_as_int()) * (MEBIBYTE / 
new_partition->sector_size);
 
        // Create unallocated space within this new extended partition
        //
@@ -298,7 +302,7 @@ const Partition & Dialog_Partition_New::Get_New_Partition( Byte_Value sector_siz
                                              new_partition->whole_device,
                                              new_partition->sector_start,
                                              new_partition->sector_end,
-                                             sector_size,
+                                             new_partition->sector_size,
                                              true );
                new_partition->logicals.push_back_adopt( unallocated );
        }
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 59fa485..8265147 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -1250,8 +1250,8 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
                // PED_PARTITION_NORMAL, PED_PARTITION_LOGICAL and PED_PARTITION_EXTENDED.
                // Partitions, ranges of blocks, with other bits set representing free
                // space and disk label meta-data, PED_PARTITION_FREESPACE and
-               // PED_PARTITION_METADATA bits respectively, are ignore and GParted
-               // creates it own unallocated partitions and accounts for partition
+               // PED_PARTITION_METADATA bits respectively, are ignored and GParted
+               // creates its own unallocated partitions and accounts for partition
                // tables.
                // References:
                // *   struct PedPartition and type PedPartitionType
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index b9ea0f2..2e7e7b4 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1741,7 +1741,7 @@ void Win_GParted::activate_resize()
        {
                dialog .hide() ;
 
-               Partition * part_temp = dialog.Get_New_Partition( devices[current_device].sector_size 
).clone();
+               Partition * part_temp = dialog.Get_New_Partition().clone();
 
                // When resizing/moving a partition which already exists on the disk all
                // possible operations could be pending so only try merging with the
@@ -1850,7 +1850,7 @@ void Win_GParted::activate_paste()
 
                                Operation * operation = new OperationCopy( devices[current_device],
                                                                           *selected_partition_ptr,
-                                                                          dialog.Get_New_Partition( 
devices[current_device].sector_size ),
+                                                                          dialog.Get_New_Partition(),
                                                                           *copied_partition );
                                operation ->icon = render_icon( Gtk::Stock::COPY, Gtk::ICON_SIZE_MENU );
 
@@ -1968,7 +1968,7 @@ void Win_GParted::activate_new()
                        new_count++ ;
                        Operation * operation = new OperationCreate( devices[current_device],
                                                                     *selected_partition_ptr,
-                                                                    dialog.Get_New_Partition( 
devices[current_device].sector_size ) );
+                                                                    dialog.Get_New_Partition() );
                        operation ->icon = render_icon( Gtk::Stock::NEW, Gtk::ICON_SIZE_MENU );
 
                        Add_Operation( operation );


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