[parted-devel] [PATCH 1/3] parted: factor out disk geometry printing into separate function
Petr Uzel
petr.uzel at suse.cz
Fri Mar 11 12:49:59 UTC 2011
* parted/parted.c (_print_disk_geometry): New function.
(do_print): Use _print_disk_geometry.
Signed-off-by: Petr Uzel <petr.uzel at suse.cz>
---
parted/parted.c | 40 +++++++++++++++++++++++-----------------
1 files changed, 23 insertions(+), 17 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index 9b4c1f2..08ab4aa 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1381,6 +1381,27 @@ partition_print (PedPartition* part)
return 1;
}
+static void
+_print_disk_geometry (const PedDevice *dev)
+{
+ PED_ASSERT (dev != NULL);
+ const PedCHSGeometry* chs = &dev->bios_geom;
+ char* cyl_size = ped_unit_format_custom (dev,
+ chs->heads * chs->sectors,
+ PED_UNIT_KILOBYTE);
+
+ if (opt_machine_mode) {
+ printf ("%d:%d:%d:%s;\n",
+ chs->cylinders, chs->heads, chs->sectors, cyl_size);
+ } else {
+ printf (_("BIOS cylinder,head,sector geometry: %d,%d,%d. "
+ "Each cylinder is %s.\n"),
+ chs->cylinders, chs->heads, chs->sectors, cyl_size);
+ }
+
+ free (cyl_size);
+}
+
static int
do_print (PedDevice** dev)
{
@@ -1511,23 +1532,8 @@ do_print (PedDevice** dev)
free (end);
if (ped_unit_get_default () == PED_UNIT_CHS
- || ped_unit_get_default () == PED_UNIT_CYLINDER) {
- PedCHSGeometry* chs = &(*dev)->bios_geom;
- char* cyl_size = ped_unit_format_custom (*dev,
- chs->heads * chs->sectors,
- PED_UNIT_KILOBYTE);
-
- if (opt_machine_mode) {
- printf ("%d:%d:%d:%s;\n",
- chs->cylinders, chs->heads, chs->sectors, cyl_size);
- } else {
- printf (_("BIOS cylinder,head,sector geometry: %d,%d,%d. "
- "Each cylinder is %s.\n"),
- chs->cylinders, chs->heads, chs->sectors, cyl_size);
- }
-
- free (cyl_size);
- }
+ || ped_unit_get_default () == PED_UNIT_CYLINDER)
+ _print_disk_geometry (*dev);
if (!opt_machine_mode) {
printf (_("Partition Table: %s\n"), disk->type->name);
--
1.7.3.4
More information about the parted-devel
mailing list