Commit bccd7fd8 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Fixed CASTOR-3043 RFE: strutou64 should handle XiB in addition to G/T/P suffixes

parent 314f6488
......@@ -210,13 +210,14 @@ u_signed64 strutou64(const char *str)
if (! isdigit (*p)) break;
u64 = u64 * 10 + (*p++ - '0');
}
if (*p && ! *(p + 1)) {
if (*p == 'K') u64 *= ONE_KB;
else if (*p == 'M') u64 *= ONE_MB;
else if (*p == 'G') u64 *= ONE_GB;
else if (*p == 'T') u64 *= ONE_TB;
else if (*p == 'P') u64 *= ONE_PB;
}
if (*p && ((! *(p + 1)) || (*(p+1)=='i' && (! *(p + 2))))) {
if (*p == 'K') u64 *= ((*(p+1)=='i') ? ONE_KIB : ONE_KB);
else if (*p == 'M') u64 *= ((*(p+1)=='i') ? ONE_MIB : ONE_MB);
else if (*p == 'G') u64 *= ((*(p+1)=='i') ? ONE_GIB : ONE_GB);
else if (*p == 'T') u64 *= ((*(p+1)=='i') ? ONE_TIB : ONE_TB);
else if (*p == 'P') u64 *= ((*(p+1)=='i') ? ONE_PIB : ONE_PB);
else if (*p == 'H') u64 *= ((*(p+1)=='i') ? ONE_HIB : ONE_HB);
}
return (u64);
}
......@@ -242,14 +243,15 @@ u_signed64 hexstrutou64(const char *str)
u64 = u64 * 16 + (*p++ - 'A' + 10);
}
}
if (*p && ! *(p + 1)) {
if (*p == 'K') u64 *= ONE_KB;
else if (*p == 'M') u64 *= ONE_MB;
else if (*p == 'G') u64 *= ONE_GB;
else if (*p == 'T') u64 *= ONE_TB;
else if (*p == 'P') u64 *= ONE_PB;
}
return (u64);
if (*p && ((! *(p + 1)) || (*(p+1)=='i' && (! *(p + 2))))) {
if (*p == 'K') u64 *= ((*(p+1)=='i') ? ONE_KIB : ONE_KB);
else if (*p == 'M') u64 *= ((*(p+1)=='i') ? ONE_MIB : ONE_MB);
else if (*p == 'G') u64 *= ((*(p+1)=='i') ? ONE_GIB : ONE_GB);
else if (*p == 'T') u64 *= ((*(p+1)=='i') ? ONE_TIB : ONE_TB);
else if (*p == 'P') u64 *= ((*(p+1)=='i') ? ONE_PIB : ONE_PB);
else if (*p == 'H') u64 *= ((*(p+1)=='i') ? ONE_HIB : ONE_HB);
}
return (u64);
}
/* u64tostru- gives the string representation with powers of 2 units of the
......@@ -272,20 +274,23 @@ char *u64tostru(u_signed64 u64,
char unit;
t64 = u64;
if (u64 >= ONE_PB) {
fnum = (double) t64 / (double) ONE_PB;
if (u64 >= ONE_HIB) {
fnum = (double) t64 / (double) ONE_HIB;
unit = 'H';
} else if (u64 >= ONE_PIB) {
fnum = (double) t64 / (double) ONE_PIB;
unit = 'P';
} else if (u64 >= ONE_TB) {
fnum = (double) t64 / (double) ONE_TB;
} else if (u64 >= ONE_TIB) {
fnum = (double) t64 / (double) ONE_TIB;
unit = 'T';
} else if (u64 >= ONE_GB) {
fnum = (double) t64 / (double) ONE_GB;
} else if (u64 >= ONE_GIB) {
fnum = (double) t64 / (double) ONE_GIB;
unit = 'G';
} else if (u64 >= ONE_MB) {
fnum = (double) t64 / (double) ONE_MB;
} else if (u64 >= ONE_MIB) {
fnum = (double) t64 / (double) ONE_MIB;
unit = 'M';
} else if (u64 >= ONE_KB) {
fnum = (double) t64 / (double) ONE_KB;
} else if (u64 >= ONE_KIB) {
fnum = (double) t64 / (double) ONE_KIB;
unit = 'K';
} else {
inum = (int) u64;
......@@ -329,20 +334,23 @@ char *u64tostrsi(u_signed64 u64,
char unit;
t64 = u64;
if (u64 >= 1000000000000000LL) {
fnum = (double) t64 / (double) 1000000000000000LL;
if (u64 >= ONE_HB) {
fnum = (double) t64 / (double) ONE_HB;
unit = 'H';
} else if (u64 >= ONE_PB) {
fnum = (double) t64 / (double) ONE_PB;
unit = 'P';
} else if (u64 >= 1000000000000LL) {
fnum = (double) t64 / (double) 1000000000000LL;
} else if (u64 >= ONE_TB) {
fnum = (double) t64 / (double) ONE_TB;
unit = 'T';
} else if (u64 >= 1000000000) {
fnum = (double) t64 / (double) 1000000000;
} else if (u64 >= ONE_GB) {
fnum = (double) t64 / (double) ONE_GB;
unit = 'G';
} else if (u64 >= 1000000) {
fnum = (double) t64 / (double) 1000000;
} else if (u64 >= ONE_MB) {
fnum = (double) t64 / (double) ONE_MB;
unit = 'M';
} else if (u64 >= 1000) {
fnum = (double) t64 / (double) 1000;
} else if (u64 >= ONE_KB) {
fnum = (double) t64 / (double) ONE_KB;
unit = 'K';
} else {
inum = (int) u64;
......
......@@ -28,14 +28,14 @@
/**
* Checks whether the given string is a size.
* The accepted syntax is :
* [blanks]<digits>[b|k|M|G|T|P]
* [blanks]<digits>[b|k|M|G|T|P]i?
* @return -1 if it is not a size,
* 0 if it is a size with no unit,
* 1 if it is a size with a unit
*/
int check_for_strutou64(char *str) {
/* We accept only the following format */
/* [blanks]<digits>[b|k|M|G|T|P] */
/* [blanks]<digits>[b|k|M|G|T|P]i? */
char *p = (char *) str;
while (isspace (*p)) p++; /* skip leading spaces */
while (*p) {
......@@ -59,6 +59,11 @@ int check_for_strutou64(char *str) {
switch (*++p) {
case '\0':
return(1); /* Ok with unit */
case 'i':
if (*(p+2) == '\0')
return(1); /* Ok with power of 2 unit */
else
return(-1); /* Unit followed by anything, not valid */
default:
return(-1); /* Unit followed by anything, not valid */
}
......
......@@ -43,11 +43,19 @@ typedef signed64 HYPER;
typedef u_signed64 U_HYPER;
typedef U_HYPER TIME_T;
#define ONE_KB 0x400
#define ONE_MB 0x100000
#define ONE_GB 0x40000000
#define ONE_TB 0x10000000000LL
#define ONE_PB 0x4000000000000LL
#define ONE_KIB 0x400
#define ONE_MIB 0x100000
#define ONE_GIB 0x40000000
#define ONE_TIB 0x10000000000LL
#define ONE_PIB 0x4000000000000LL
#define ONE_HIB 0x1000000000000000LL
#define ONE_KB 1000
#define ONE_MB 1000000
#define ONE_GB 1000000000
#define ONE_TB 1000000000000LL
#define ONE_PB 1000000000000000LL
#define ONE_HB 1000000000000000000LL
/*
* Error reporting
......
......@@ -49,16 +49,15 @@ is the model of cartridge.
It must be at most CA_MAXMODELLEN characters long.
.TP
.I native_capacity
in bytes. The number may also have a suffix M or G to indicate Mbyte and
Gbyte respectively.
in bytes. The number may also have a suffix K/M/G/T/P/H to indicate kilo/mega/giga/tera/peta/hexabytes or Ki/Mi/Gi/Ti/Pi/Hi for their powers of 2 version.
For a multi-sided media like DVD, the native capacity corresponds to one side.
.LP
This command requires ADMIN privilege in the Cupv database.
.SH EXAMPLES
.nf
.ft CW
vmgrenterdenmap --mo 9840 --ml R -d 20GC --nc 20G
vmgrenterdenmap --mo 8500 -d 8500C --nc 5G
vmgrenterdenmap --mo 9840 --ml R -d 20GC --nc 20Gi
vmgrenterdenmap --mo 8500 -d 8500C --nc 5Gi
.ft
.fi
.SH EXIT STATUS
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment