bug-parted
[Top][All Lists]
Advanced

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

bug#24502: [PATCH] libparted: Show partition boundaries in sectors by de


From: John Pittman
Subject: bug#24502: [PATCH] libparted: Show partition boundaries in sectors by default
Date: Wed, 21 Sep 2016 15:22:28 -0400

In parted, by default, we print disk size and partition
boundaries in compact form.  As partition boundaries fall
on sector boundaries, this is not useful for administration
and should be changed.  This patch changes the default_unit
to sectors and adjusts the content of _print_disk_info.
PedUnit, uf_unit (user friendly unit), is used to adjust the
output dependent on the default unit chosen from the
command line.

The full disk size will be shown in both sectors and
compact for convenience, while the partition boundaries
will only be shown in sectors.  Partition boundary unit and
full disk default compact output will still be changeable via
the 'u' option on the command line, but full disk sector
output will not.

Many partition tools have already migrated to default sector
use. It offers a 'one-stop-shop' through parted -l, and
aligns more closely with the needs of partition
administration activities.

Signed-off-by: John Pittman <address@hidden>
---
 libparted/unit.c |  2 +-
 parted/parted.c  | 36 ++++++++++++++++++++++++++----------
 2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/libparted/unit.c b/libparted/unit.c
index e545985..c167464 100644
--- a/libparted/unit.c
+++ b/libparted/unit.c
@@ -67,7 +67,7 @@
 #endif /* ENABLE_NLS */
 
 
-static PedUnit default_unit = PED_UNIT_COMPACT;
+static PedUnit default_unit = PED_UNIT_SECTOR;
 static const char* unit_names[] = {
        "s",
        "B",
diff --git a/parted/parted.c b/parted/parted.c
index b20d432..682451d 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -711,12 +711,19 @@ do_mkpart (PedDevice** dev)
                 if (!added_ok)
                         goto error_remove_part;
 
+                PedUnit default_unit = ped_unit_get_default (), uf_unit;
+
+                if (default_unit == PED_UNIT_SECTOR)
+                        uf_unit = PED_UNIT_COMPACT;
+                else
+                        uf_unit = default_unit;
+
                 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);
-                        end_sol   = ped_unit_format (*dev, part->geom.end);
+                        start_usr = ped_unit_format_custom (*dev, start, 
uf_unit);
+                        end_usr   = ped_unit_format_custom (*dev, end, 
uf_unit);
+                        start_sol = ped_unit_format_custom (*dev, 
part->geom.start, uf_unit);
+                        end_sol   = ped_unit_format_custom (*dev, 
part->geom.end, uf_unit);
 
                         /* In script mode failure to use specified values is 
fatal.
                          * However, in interactive mode, it merely elicits a 
warning
@@ -950,10 +957,18 @@ _print_disk_info (const PedDevice *dev, const PedDisk 
*disk)
                                          "md", "loopback"};
 
         char* start = ped_unit_format (dev, 0);
-        PedUnit default_unit = ped_unit_get_default ();
-        char* end = ped_unit_format_byte (dev, dev->length * dev->sector_size
+        PedUnit default_unit = ped_unit_get_default (), uf_unit;
+
+        if (default_unit == PED_UNIT_SECTOR)
+                uf_unit = PED_UNIT_COMPACT;
+        else
+                uf_unit = default_unit;
+
+        char* end = ped_unit_format_custom_byte (dev, dev->length * 
dev->sector_size
                                     - (default_unit == PED_UNIT_CHS ||
-                                       default_unit == PED_UNIT_CYLINDER));
+                                       default_unit == PED_UNIT_CYLINDER), 
uf_unit);
+        char* end_sect = ped_unit_format_custom_byte (dev, dev->length * 
dev->sector_size,
+                                                                 
PED_UNIT_SECTOR);
 
         const char* pt_name = disk ? disk->type->name : "unknown";
         char *disk_flags = disk_print_flags (disk);
@@ -968,20 +983,21 @@ _print_disk_info (const PedDevice *dev, const PedDisk 
*disk)
                                         break;
 
             }
-            printf ("%s:%s:%s:%lld:%lld:%s:%s:%s;\n",
-                    dev->path, end, transport[dev->type],
+            printf ("%s:%s:%s:%s:%lld:%lld:%s:%s:%s;\n",
+                    dev->path, end, end_sect, transport[dev->type],
                     dev->sector_size, dev->phys_sector_size,
                     pt_name, dev->model, disk_flags);
         } else {
             printf (_("Model: %s (%s)\n"),
                     dev->model, transport[dev->type]);
-            printf (_("Disk %s: %s\n"), dev->path, end);
+            printf (_("Disk %s: %s: %s\n"), dev->path, end, end_sect);
             printf (_("Sector size (logical/physical): %lldB/%lldB\n"),
                     dev->sector_size, dev->phys_sector_size);
         }
 
         free (start);
         free (end);
+       free (end_sect);
 
         if (ped_unit_get_default () == PED_UNIT_CHS
             || ped_unit_get_default () == PED_UNIT_CYLINDER)
-- 
2.5.5






reply via email to

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