[parted-devel] print devices

Debarshi Ray debarshi.ray at gmail.com
Thu Dec 7 14:53:22 CET 2006


I have fixed the '-0.00kB issue'. In line 1273 of parted/parted.c I
find it unnecessary to subtract 1 from the product of dev->length and
dev->sector_size.

I have also added an extra else-if branch in
ped_unit_format_cutom_byte function in libparted/unit.c so that sizes
below 10kB are  shown in bytes. I did this to maintain uniformity with
the way the other units are divided into slabs, and to keep it similar
to GParted. In GParted zero sized devices are shown as '0.00 B' and
not '0.00 kB'.

Is it ok?

Happy hacking,
Debarshi
-- 
Universities are places of knowledge.  The freshman each bring a
little in with them, and the seniors take none away, so knowledge
accumulates.
-------------- next part --------------
From 21b9a71ed5202d189d3bdd1f47163e2fa2e9fb99 Mon Sep 17 00:00:00 2001
From: Debarshi Ray <rishi at gnu.org>
Date: Fri, 8 Dec 2006 00:51:06 +0530
Subject: Zero sized device is shown as 0.00B and not -0.00kB.

---
 libparted/unit.c |   20 +++++++++++---------
 parted/parted.c  |   12 +++---------
 2 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/libparted/unit.c b/libparted/unit.c
index ac4d74e..9e1f35a 100644
--- a/libparted/unit.c
+++ b/libparted/unit.c
@@ -221,15 +221,17 @@ ped_unit_format_custom_byte (PedDevice* 
 		return ped_strdup (buf);
 	}
 	
-	if (unit == PED_UNIT_COMPACT) {
-		if (byte >= 10LL * PED_TERABYTE_SIZE)
-			unit = PED_UNIT_TERABYTE;
-		else if (byte >= 10LL * PED_GIGABYTE_SIZE)
-			unit = PED_UNIT_GIGABYTE;
-		else if (byte >= 10LL * PED_MEGABYTE_SIZE)
-			unit = PED_UNIT_MEGABYTE;
-		else
-			unit = PED_UNIT_KILOBYTE;
+        if (unit == PED_UNIT_COMPACT) {
+                if (byte >= 10LL * PED_TERABYTE_SIZE)
+                        unit = PED_UNIT_TERABYTE;
+                else if (byte >= 10LL * PED_GIGABYTE_SIZE)
+                        unit = PED_UNIT_GIGABYTE;
+                else if (byte >= 10LL * PED_MEGABYTE_SIZE)
+                        unit = PED_UNIT_MEGABYTE;
+                else if (byte >= 10LL * PED_KILOBYTE_SIZE)
+                        unit = PED_UNIT_KILOBYTE;
+                else
+                        unit = PED_UNIT_BYTE;
 	}
 
 	/* IEEE754 says that 100.5 has to be rounded to 100 (by printf) */
diff --git a/parted/parted.c b/parted/parted.c
index 68b86ad..7e259f2 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1270,16 +1270,10 @@ do_print (PedDevice** dev)
                 ped_device_probe_all();
 
                 while ((current_dev = ped_device_get_next(current_dev))) {
-                        if(current_dev->length)
-                                end = ped_unit_format_byte (current_dev,
+                        end = ped_unit_format_byte (current_dev,
                                              current_dev->length
-					     * current_dev->sector_size
-                                             - 1);
-			else {
-				end = ped_malloc(sizeof(char) * 7);
-				strcpy(end, "0.00B");
-			}
-		        printf ("%s (%s)\n", current_dev->path, end);
+                                             * current_dev->sector_size);
+                        printf ("%s (%s)\n", current_dev->path, end);
                         ped_free(end);
                 }    
 
-- 
1.4.2.4


More information about the parted-devel mailing list