[parted-devel] [PATCH 2/4] parted: print disk flags

bcl at redhat.com bcl at redhat.com
Sat Jan 28 00:59:03 UTC 2012


This adds a 'Disk Flags:' line the displays the active disk flags.
In machine mode this is appended to the disk info line, after the
device model.

* parted/parted.c (disk_print_flags): New function
(_print_disk_info): Add Disk Flags information.
---
 parted/parted.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/parted/parted.c b/parted/parted.c
index 4220265..b0d1508 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -825,6 +825,43 @@ partition_print (PedPartition* part)
         return 1;
 }
 
+static char*
+disk_print_flags (PedDisk* disk)
+{
+        PedDiskFlag     flag;
+        int             first_flag;
+        const char*     name;
+        char*           res = ped_malloc(1);
+        void*           _res = res;
+
+        *res = '\0';
+        if (!disk)
+            return res;
+
+        first_flag = 1;
+        for (flag = ped_disk_flag_next (0); flag;
+             flag = ped_disk_flag_next (flag)) {
+                if (ped_disk_get_flag (disk, flag)) {
+                        if (first_flag)
+                                first_flag = 0;
+                        else {
+                                _res = res;
+                                ped_realloc (&_res, strlen (res) + 1 + 2);
+                                res = _res;
+                                strncat (res, ", ", 2);
+                        }
+
+                        name = _(ped_disk_flag_get_name (flag));
+                        _res = res;
+                        ped_realloc (&_res, strlen (res) + 1 + strlen (name));
+                        res = _res;
+                        strcat(res, name);
+                }
+        }
+
+        return res;
+}
+
 static void
 _print_disk_geometry (const PedDevice *dev)
 {
@@ -862,6 +899,7 @@ _print_disk_info (const PedDevice *dev, const PedDisk *disk)
                                        default_unit == PED_UNIT_CYLINDER));
 
         const char* pt_name = disk ? disk->type->name : "unknown";
+        char *disk_flags = disk_print_flags (disk);
 
         if (opt_machine_mode) {
             switch (default_unit) {
@@ -873,10 +911,10 @@ _print_disk_info (const PedDevice *dev, const PedDisk *disk)
                                         break;
 
             }
-            printf ("%s:%s:%s:%lld:%lld:%s:%s;\n",
+            printf ("%s:%s:%s:%lld:%lld:%s:%s:%s;\n",
                     dev->path, end, transport[dev->type],
                     dev->sector_size, dev->phys_sector_size,
-                    pt_name, dev->model);
+                    pt_name, dev->model, disk_flags);
         } else {
             printf (_("Model: %s (%s)\n"),
                     dev->model, transport[dev->type]);
@@ -894,7 +932,9 @@ _print_disk_info (const PedDevice *dev, const PedDisk *disk)
 
         if (!opt_machine_mode) {
             printf (_("Partition Table: %s\n"), pt_name);
+            printf (_("Disk Flags: %s\n"), disk_flags);
         }
+        free (disk_flags);
 }
 
 static int
-- 
1.7.6.5




More information about the parted-devel mailing list