On Wed, Dec 12, 2007 at 03:16:46PM -0800, Randy Dunlap wrote:
> On Thu, 13 Dec 2007 00:09:52 +0100 Karel Zak wrote:
> >  It seems like a chaos between KiB, MiB, (2^N) and kB, MB, GB, (10^N).
> > 
> >  Does anyone understand this code?  I don't believe it's a bug -- it's
> >  too stupid...
> 
> It looks to me like someone decided that only K could mean 2^N
> and any other suffix means 10^M.

 Yes. A proposed patch is below.

    Karel



>From 00855c890465670ba76934229dd6881647934e22 Mon Sep 17 00:00:00 2001
From: Karel Zak <[EMAIL PROTECTED]>
Date: Thu, 13 Dec 2007 01:06:44 +0100
Subject: [PATCH] fdisk: calculate +size{K,M,G} in 2^N

fdisk(8) does not calculate partition size (+sizeM or +sizeG)
in MiB or GiB correctly. It uses 10^N instead 2^N.

This patch cleanups +size[kKmMgG] to:

   +size    -- bytes
   +sizek   -- kB   (10^3)
   +sizeK   -- KiB  (2^10)
   +sizem   -- MB   (10^6)
   +sizeM   -- MiB  (2^20)
   +sizeg   -- GB   (10^9)
   +sizeG   -- GiB  (2^30)

Signed-off-by: Karel Zak <[EMAIL PROTECTED]>
---
 fdisk/fdisk.c |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c
index c5e3f06..0accb20 100644
--- a/fdisk/fdisk.c
+++ b/fdisk/fdisk.c
@@ -1174,7 +1174,7 @@ read_int(unsigned int low, unsigned int dflt, unsigned 
int high,
 
                        i = atoi(line_ptr+1);
 
-                       while (isdigit(*++line_ptr))
+                       while (isdigit(*++line_ptr))
                                use_default = 0;
 
                        switch (*line_ptr) {
@@ -1184,18 +1184,22 @@ read_int(unsigned int low, unsigned int dflt, unsigned 
int high,
                                                i *= heads * sectors;
                                        break;
                                case 'K':
-                                       absolute = 1024;
+                                       absolute = 2 << 10;     /* KiB */
                                        break;
                                case 'k':
-                                       absolute = 1000;
+                                       absolute = 1000;        /* kB */
                                        break;
-                               case 'm':
                                case 'M':
-                                       absolute = 1000000;
+                                       absolute = 2 << 19;     /* MiB */
+                                       break;
+                               case 'm':
+                                       absolute = 1000000;     /* MB */
                                        break;
-                               case 'g':
                                case 'G':
-                                       absolute = 1000000000;
+                                       absolute = 2 << 29;     /* GiB */
+                                       break;
+                               case 'g':
+                                       absolute = 1000000000;  /* GB */
                                        break;
                                default:
                                        break;
@@ -2061,7 +2065,7 @@ add_partition(int n, int sys) {
                stop = limit;
        } else {
                snprintf(mesg, sizeof(mesg),
-                        _("Last %s or +size or +sizeM or +sizeK"),
+                        _("Last %s or +size, +sizeK, +sizeM or +sizeG"),
                         str_units(SINGULAR));
                stop = read_int(cround(start), cround(limit), cround(limit),
                                cround(start), mesg);
-- 
1.5.3.1

-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to