[parted-devel] [PATCH] parted: restore partition_print
Wang Dong
dongdwdw at linux.vnet.ibm.com
Fri Mar 31 10:31:48 UTC 2017
The function partition_print is used to print out some
basic information of a partition. It was implemented
in v1.8 but ripped out later.
Compared with the old version of this function, some changes
are introduced to restore it.
1. ped_file_system_probe persede ped_file_system_open and
ped_file_system_close to get the file system type.
2. the file system resizing part is removed.
Signed-off-by: Wang Dong <dongdwdw at linux.vnet.ibm.com>
Reviewed-by: Andre Wild <wild at linux.vnet.ibm.com>¶¶
Signed-off-by: Hendrik Brueckner <brueckner at linux.vnet.ibm.com>¶
---
doc/parted.texi | 4 +---
parted/parted.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/doc/parted.texi b/doc/parted.texi
index ac23ef6..c8a62bc 100644
--- a/doc/parted.texi
+++ b/doc/parted.texi
@@ -692,9 +692,7 @@ Minor Start End Type Filesystem Flags
Minor: 1
Flags: boot, lba
File System: fat32
-Size: 945.000Mb (0%)
-Minimum size: 84.361Mb (0%)
-Maximum size: 2445.679Mb (100%)
+Size: 945.0Mb (0%)
@end group
@end example
@end deffn
diff --git a/parted/parted.c b/parted/parted.c
index 90d06e0..50b0bab 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -924,9 +924,47 @@ partition_print_flags (PedPartition const *part)
return res;
}
+/* Prints a sector out, first in compact form, and then with a percentage.
+ * Eg: 32Gb (40%)
+ */
+static void
+print_sector_compact_and_percent (PedSector sector, PedDevice* dev)
+{
+ char* compact;
+ char* percent;
+
+ if (ped_unit_get_default() == PED_UNIT_PERCENT)
+ compact = ped_unit_format (dev, sector);
+ else
+ compact = ped_unit_format_custom (dev, sector, PED_UNIT_COMPACT);
+
+ percent = ped_unit_format_custom (dev, sector, PED_UNIT_PERCENT);
+
+ printf ("%s (%s)\n", compact, percent);
+
+ free (compact);
+ free (percent);
+}
+
static int
partition_print (PedPartition* part)
{
+ PedFileSystemType* fs_type;
+ char* flags;
+
+ fs_type = ped_file_system_probe (&part->geom);
+ flags = partition_print_flags (part);
+
+ printf (_("Minor: %d\n"), part->num);
+ printf (_("Flags: %s\n"), flags);
+ printf (_("File System: %s\n"), fs_type? fs_type->name : _("Not detected"));
+ printf (_("Size: "));
+ print_sector_compact_and_percent (part->geom.length, part->geom.dev);
+
+ printf ("\n");
+
+ free (flags);
+
return 1;
}
--
2.8.4
More information about the parted-devel
mailing list