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

Bug#471323: support powers of 1024 when parsing user input (kiB, MiB, ...)



Package: partman-base
Severity: wishlist
Tags: patch

This patch allows partman to accept kiB / MiB / etc suffixes that represent
powers of 1024.

-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.18-6-amd64 (SMP w/2 CPU cores)
Locale: LANG=ca_AD.UTF-8, LC_CTYPE=ca_AD.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Index: partman-base/lib/base.sh
===================================================================
--- partman-base/lib/base.sh	(revision 51657)
+++ partman-base/lib/base.sh	(working copy)
@@ -218,10 +218,11 @@
 }
 
 human2longint () {
-	local human suffix int frac longint
+	local human suffix int frac longint i_modifier
 	set -- $*; human="$1$2$3$4$5" # without the spaces
 	human=${human%b} #remove last b
 	human=${human%B} #remove last B
+	i_modifier=${human#${human%i}} ; human=${human%i} # 'i' modifier (if present)
 	suffix=${human#${human%?}} # the last symbol of $human
 	case $suffix in
 	k|K|m|M|g|G|t|T)
@@ -233,6 +234,23 @@
 	esac
 	int="${human%[.,]*}"
 	[ "$int" ] || int=0
+
+	if [ "$i_modifier" = "i" ] ; then
+		local k=1024
+		longint=$(expr "$int" \* $k)
+		case $suffix in
+		m|M|"")
+			longint=$(expr "$longint" \* $k)
+			;;
+		g|G)
+			longint=$(expr "$longint" \* $k \* $k)
+			;;
+		t|T)
+			longint=$(expr "$longint" \* $k \* $k \* $k)
+			;;
+		esac
+	else
+# FIXME!! indentation intentionally omitted to simplify the patch
 	frac=${human#$int}
 	frac="${frac#[.,]}0000" # to be sure there are at least 4 digits
 	frac=${frac%${frac#????}} # only the first 4 digits of $frac
@@ -258,6 +276,7 @@
 		longint=${longint}00
 		;;
 	esac
+	fi
 	echo $longint
 }
 

Reply to: