bug-parted
[Top][All Lists]
Advanced

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

[PATCH parted 5/7] parted: change warnings when initial constrained mkpa


From: Hans de Goede
Subject: [PATCH parted 5/7] parted: change warnings when initial constrained mkpart fails
Date: Wed, 10 Feb 2010 14:12:59 +0100

In do_mkpart we first try to create a partition using a constraint
derived from the user input intersected with the devices alignment
needs. And if that fails we try again without any constraint.

However the warning given when this happens only takes into account
the user not getting what he asked for, while the alignment might be
a problem too (or even the only problem). So this patch adds a check
to see if the user really did not get what he asked before giving that
warning, and adds a new check + warning to see if the created partition
is properly aligned.
*parted/parted.c (do_mkpart,do_mkpartfs): change warnings when initial
constrained mkpart fails.
---
 parted/parted.c |   59 ++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index 69451a8..2c7b469 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -178,6 +178,8 @@ static TimerContext timer_context;
 
 static int _print_list ();
 static void _done (PedDevice* dev);
+static bool partition_align_check (PedDisk const *disk,
+                        PedPartition const *part, enum AlignmentType a_type);
 
 static void
 _timer_handler (PedTimer* timer, void* context)
@@ -833,7 +835,12 @@ do_mkpart (PedDevice** dev)
                 added_ok = ped_disk_add_partition (disk, part,
                                                         constraint_any);
                 ped_constraint_destroy (constraint_any);
-                if (added_ok) {
+
+                if (!added_ok)
+                        goto error_remove_part;
+
+                if (!ped_geometry_test_sector_inside(range_start, 
part->geom.start) ||
+                    !ped_geometry_test_sector_inside(range_end, 
part->geom.end)) {
                         start_usr = ped_unit_format (*dev, start);
                         end_usr   = ped_unit_format (*dev, end);
                         start_sol = ped_unit_format (*dev, part->geom.start);
@@ -867,8 +874,23 @@ do_mkpart (PedDevice** dev)
                                         /* undo partition addition */
                                         goto error_remove_part;
                         }
-                } else {
-                        goto error_remove_part;
+                }
+
+                if ((alignment == ALIGNMENT_OPTIMAL &&
+                     !partition_align_check(disk, part, PA_OPTIMUM)) ||
+                    (alignment == ALIGNMENT_MINIMAL &&
+                     !partition_align_check(disk, part, PA_MINIMUM))) {
+                        if (ped_exception_throw(
+                                PED_EXCEPTION_WARNING,
+                                (opt_script_mode
+                                 ? PED_EXCEPTION_OK
+                                 : PED_EXCEPTION_IGNORE_CANCEL),
+                                _("The resulting partition is not properly "
+                                  "aligned for best performance.")) ==
+                            PED_EXCEPTION_CANCEL) {
+                                /* undo partition addition */
+                                goto error_remove_part;
+                        }
                 }
         } else {
                 ped_exception_leave_all();
@@ -1018,8 +1040,16 @@ do_mkpartfs (PedDevice** dev)
         if (!added_ok) {
                 ped_exception_leave_all();
 
-                if (ped_disk_add_partition (disk, part,
-                                        ped_constraint_any (*dev))) {
+                PedConstraint *constraint_any = ped_constraint_any (*dev);
+                bool added_ok = ped_disk_add_partition (disk, part,
+                                                        constraint_any);
+                ped_constraint_destroy (constraint_any);
+
+                if (!added_ok)
+                        goto error_remove_part;
+
+                if (!ped_geometry_test_sector_inside(range_start, 
part->geom.start) ||
+                    !ped_geometry_test_sector_inside(range_end, 
part->geom.end)) {
                         start_usr = ped_unit_format (*dev, start);
                         end_usr   = ped_unit_format (*dev, end);
                         start_sol = ped_unit_format (*dev, part->geom.start);
@@ -1048,8 +1078,23 @@ do_mkpartfs (PedDevice** dev)
                                         /* undo partition addition */
                                         goto error_remove_part;
                         }
-                } else {
-                        goto error_remove_part;
+                }
+
+                if ((alignment == ALIGNMENT_OPTIMAL &&
+                     !partition_align_check(disk, part, PA_OPTIMUM)) ||
+                    (alignment == ALIGNMENT_MINIMAL &&
+                     !partition_align_check(disk, part, PA_MINIMUM))) {
+                        if (ped_exception_throw(
+                                PED_EXCEPTION_WARNING,
+                                (opt_script_mode
+                                 ? PED_EXCEPTION_OK
+                                 : PED_EXCEPTION_IGNORE_CANCEL),
+                                _("The resulting partition is not properly "
+                                  "aligned for best performance.")) ==
+                            PED_EXCEPTION_CANCEL) {
+                                /* undo partition addition */
+                                goto error_remove_part;
+                        }
                 }
         } else {
                 ped_exception_leave_all();
-- 
1.6.6





reply via email to

[Prev in Thread] Current Thread [Next in Thread]