- The code of the above-mentioned "unit" command contains a static constant array of units. It looks like this and has "kiB" with lower case “k”, though further down checks names without case sensitivity.
static const char* unit_names[] = {
"s",
"B",
"kB",
"MB",
"GB",
"TB",
"compact",
"cyl",
"chs",
"%",
"kiB",
"MiB",
"GiB",
"TiB"
};
- There is adjustment to be called whenever the partition is created or resized. It looks like this and also checks for "kiB", though with case sensitivity this time.
/* Return true, if str ends with [kMGTPEZY]iB, i.e. IEC units. */static bool
_string_ends_with_iec_unit(const char *str)
{
/* 3 characters for the IEC unit and at least 1 digit */
if (!str || strlen(str) < 4)
return false;
char const *p = str + strlen(str) - 3;
return strchr ("kMGTPEZY", *p) && c_strcasecmp (p+1, "iB") == 0;
}
/* If the selected unit is one of kiB, MiB, GiB or TiB and the partition is not
* only 1 sector long, then adjust the end so that it is one sector before the
* given position. Also adjust range_end accordingly. Thus next partition can
* start immediately after this one.
*
* To be called after end sector is read from the user.
*
*/
static void
_adjust_end_if_iec (PedSector* start, PedSector* end,
PedGeometry* range_end, char* end_input)
{
...
if (_string_ends_with_iec_unit(end_input) || ...) {
*end -= 1;
range_end->start -= 1;
range_end->end -= 1;
}