[gparted] Simplify logic in MB_Needed_for_Boot_Record() et al



commit 67b07f86e649fb66ed7b7b0bddf4826ba2a5fc1d
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Thu Oct 21 07:33:30 2021 +0100

    Simplify logic in MB_Needed_for_Boot_Record() et al
    
    The first two clauses say is the partition object type unallocated
    inside an extended partition, or a logical partition (which only occur
    inside an extended partition).  As these are the only two partition
    object types which can occur inside an extended partition, this is
    equivalent to saying is the partition object inside an extended
    partition.  Simplify.

 src/Dialog_Base_Partition.cc | 18 +++++++-----------
 src/Win_GParted.cc           | 17 ++++++-----------
 2 files changed, 13 insertions(+), 22 deletions(-)
---
diff --git a/src/Dialog_Base_Partition.cc b/src/Dialog_Base_Partition.cc
index a025ac49..67b43b81 100644
--- a/src/Dialog_Base_Partition.cc
+++ b/src/Dialog_Base_Partition.cc
@@ -499,19 +499,15 @@ void Dialog_Base_Partition::Set_MinMax_Text( Sector min, Sector max )
        label_minmax .set_text( str_temp ) ; 
 }
 
+
 int Dialog_Base_Partition::MB_Needed_for_Boot_Record( const Partition & partition )
 {
-       //Determine if space is needed for the Master Boot Record or
-       //  the Extended Boot Record.  Generally an an additional track or MEBIBYTE
-       //  is required so for our purposes reserve a MEBIBYTE in front of the partition.
-       //  NOTE:  This logic also contained in Win_GParted::set_valid_operations
-       if (   (   partition .inside_extended
-               && partition .type == TYPE_UNALLOCATED
-              )
-           || ( partition .type == TYPE_LOGICAL )
-                                            /* Beginning of disk device */
-           || (partition.sector_start < (MEBIBYTE / partition.sector_size))
-          )
+       // Determine if space needs reserving for the partition table or the EBR (Extended
+       // Boot Record).  Generally a track or MEBIBYTE is reserved.  For our purposes
+       // reserve a MEBIBYTE at the start of the partition.
+       // NOTE: This logic also contained in Win_GParted::set_valid_operations()
+       if (partition.inside_extended                                 ||
+           partition.sector_start < MEBIBYTE / partition.sector_size   )
                return 1 ;
        else
                return 0 ;
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 3bf5054d..c836529b 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -1354,17 +1354,12 @@ void Win_GParted::set_valid_operations()
                        else
                                required_size = copied_filesystem_ptn.get_byte_length();
 
-                       //Determine if space is needed for the Master Boot Record or
-                       //  the Extended Boot Record.  Generally an an additional track or MEBIBYTE
-                       //  is required so for our purposes reserve a MEBIBYTE in front of the partition.
-                       //  NOTE:  This logic also contained in 
Dialog_Base_Partition::MB_Needed_for_Boot_Record
-                       if (   (   selected_partition_ptr->inside_extended
-                               && selected_partition_ptr->type == TYPE_UNALLOCATED
-                              )
-                           || ( selected_partition_ptr->type == TYPE_LOGICAL )
-                                                            /* Beginning of disk device */
-                           || (selected_partition_ptr->sector_start < (MEBIBYTE / 
selected_partition_ptr->sector_size))
-                          )
+                       // Determine if space needs reserving for the partition table or the EBR (Extended
+                       // Boot Record).  Generally a track or MEBIBYTE is reserved.  For our purposes
+                       // reserve a MEBIBYTE at the start of the partition.
+                       // NOTE: This logic also contained in 
Dialog_Base_Partition::MB_Needed_for_Boot_Record()
+                       if (selected_partition_ptr->inside_extended                                           
    ||
+                           selected_partition_ptr->sector_start < MEBIBYTE / 
selected_partition_ptr->sector_size   )
                                required_size += MEBIBYTE;
 
                        //Determine if space is needed for the Extended Boot Record for a logical partition


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