bug-parted
[Top][All Lists]
Advanced

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

parted: Size column in "parted print" desired


From: Branden Robinson
Subject: parted: Size column in "parted print" desired
Date: Mon, 8 Apr 2002 18:00:23 -0500
User-agent: Mutt/1.2.5i

Package: parted
Version: 1.4.24-3
Severity: wishlist
Tags: patch

Hi,

The pgi package creates installers with a text-mode interface
that uses parted for partitioning.  We here at Progeny thought
would be nice if parted's "print" function would report the size
of each partition along with the other information it displays.

We thought it would be even nicer if the reported size was made
"human-readable" by reporting the size in the most appropriate
units: terabytes, gigabytes, megabytes, or kilobytes.

And we thought it would be nicest of all if we supplied you with
a patch to implement this.

This patch is tested and appears to work hunky-dory.

# parted /dev/hda print
Disk geometry for /dev/hda: 0.000-19092.937 megabytes
Disk label type: msdos
Minor    Start       End     Size   Type      Filesystem  Flags
1          0.031    274.548   274M  primary   ext2        boot
2        274.548    400.056   125M  primary   linux-swap  
3        400.056  19092.875    18G  extended              lba
5        400.087   1427.651     1G  logical   ext2        
6       1427.682   3474.997     1G  logical   ext2        
7       3475.028  16088.532    12G  logical   ext2        
8      16088.563  19092.875     2G  logical   ext2        

diff -urN parted-1.4.24/parted/parted.c parted-1.4.24.print_size/parted/parted.c
--- parted-1.4.24/parted/parted.c       Sun Sep 30 02:45:38 2001
+++ parted-1.4.24.print_size/parted/parted.c    Mon Apr  8 17:40:27 2002
@@ -744,6 +744,8 @@
        int                     first_flag;
        int                     has_extended;
        int                     has_name;
+       int                     sect_size, unit_size;
+       char                    unit;
 
        disk = ped_disk_open (*dev);
        if (!disk)
@@ -759,7 +761,7 @@
        has_name = ped_disk_type_check_feature (disk->type,
                                         PED_DISK_TYPE_PARTITION_NAME);
 
-       printf (_("Minor    Start       End     "));
+       printf (_("Minor    Start       End     Size   "));
        if (has_extended)
                printf (_("Type      "));
        printf (_("Filesystem  "));
@@ -781,6 +783,24 @@
                printf ("%10.3f %10.3f  ",
                        (int) part->geom.start * 1.0 / MEGABYTE_SECTORS,
                        (int) part->geom.end * 1.0 / MEGABYTE_SECTORS);
+
+               sect_size = (part->geom.end - part->geom.start) * 1.0 / 
MEGABYTE_SECTORS;
+
+               if (sect_size > (1024.0 * 1024.0)) {
+                       unit_size = (int) sect_size / (1024.0 * 1024.0);
+                       unit = 'T';
+               } else if (sect_size > 1024.0) {
+                       unit_size = (int) sect_size / 1024.0;
+                       unit = 'G';
+               } else if (sect_size > 1.0) {
+                       unit_size = (int) sect_size;
+                       unit = 'M';
+               } else {
+                       unit_size = (int) sect_size * 1024.0;
+                       unit = 'k';
+               }
+
+               printf ("%4d%c  ", unit_size, unit);
 
                if (has_extended)
                        printf ("%-9s ",

-- 
Branden Robinson          | GPG signed/encrypted mail welcome
address@hidden       | 1024D/9C0BCBFB
Consultant                | D5F6 D4C9 E25B 3D37 068C
Progeny Linux Systems     | 72E8 0F42 191A 9C0B CBFB



reply via email to

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