Skip to contentSkip to conversation

master - libdm: Add dm_size_to_string to libdevmapper.

PATCH Alasdair Kergon 1 participant 1 message Jul 27, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=af1c7bf0c71f9cc132e9cf211eb1512078af0081
Commit:        af1c7bf0c71f9cc132e9cf211eb1512078af0081
Parent:        fa11ddd7df9cd29956cb2610d4a730980734b8c2
Author:        Alasdair G Kergon <[email protected]>
AuthorDate:    Mon Jul 27 21:30:20 2015 +0100
Committer:     Alasdair G Kergon <[email protected]>
CommitterDate: Mon Jul 27 21:30:20 2015 +0100

libdm: Add dm_size_to_string to libdevmapper.

Moved out from lib/display and a little documentation added. It's tuned to LVM's requirements historically and its behaviour might not always be what you would expect.

---
 configure.in                        |    2 +-
 lib/display/display.c               |  156 ++--------------------------------
 libdm/.exported_symbols.DM_1_02_104 |    1 +
 libdm/libdevmapper.h                |   26 ++++++
 libdm/libdm-string.c                |  157 ++++++++++++++++++++++++++++++++++-
 5 files changed, 193 insertions(+), 149 deletions(-)
configure.in +1 -1
index c2cd69a..e273e1d 100644
@@ -1726,7 +1726,7 @@ if test "$BUILD_CMIRRORD" = yes; then
 fi
 
 if test "$BUILD_LVMLOCKD" = yes; then
-	AC_CHECK_FUNCS(clock_gettime strtoull,,hard_bailout) 
+	AC_CHECK_FUNCS(clock_gettime strtoull,,hard_bailout)
 fi
 
 if test "$BUILD_LVMPOLLD" = yes; then
lib/display/display.c +9 -147

183 lines not on this page · raw message

libdm/.exported_symbols.DM_1_02_104 new file +1 -0
new file mode 100644
index 0000000..7bd144d
@@ -0,0 +1 @@
+dm_size_to_string
libdm/libdevmapper.h +26 -0
index 6523c70..3a900be 100644
@@ -1532,6 +1532,32 @@ int dm_strncpy(char *dest, const char *src, size_t n);
 uint64_t dm_units_to_factor(const char *units, char *unit_type,
 			    int strict, const char **endptr);
 
+/*
+ * Type of unit specifier used by dm_size_to_string().
+ */
+typedef enum {
+	DM_SIZE_LONG = 0,	/* Megabyte */
+	DM_SIZE_SHORT = 1,	/* MB or MiB */
+	DM_SIZE_UNIT = 2	/* M or m */
+} dm_size_suffix_t;
+
+/*
+ * Convert a size (in 512-byte sectors) into a printable string using units of unit_type.
+ * An upper-case unit_type indicates output units based on powers of 1000 are
+ * required; a lower-case unit_type indicates powers of 1024.
+ * For correct operation, unit_factor must be one of:
+ * 	0 - the correct value will be calculated internally;
+ *   or the output from dm_units_to_factor() corresponding to unit_type;
+ *   or 'u' or 'U', an arbitrary number of bytes to use as the power base.
+ * Set include_suffix to 1 to include a suffix of suffix_type.
+ * Set use_si_units to 0 for suffixes that don't distinguish between 1000 and 1024.
+ * Set use_si_units to 1 for a suffix that does distinguish.
+ */
+const char *dm_size_to_string(struct dm_pool *mem, uint64_t size,
+			      char unit_type, int use_si_units, 
+			      uint64_t unit_factor, int include_suffix, 
+			      dm_size_suffix_t suffix_type);
+
 /**************************
  * file/stream manipulation
  **************************/
libdm/libdm-string.c +156 -1

167 lines not on this page · raw message