mirror of
https://github.com/AltraMayor/f3.git
synced 2025-09-15 01:56:39 -04:00
f3probe: add a friendly way to enter sizes
This patch allows any number passed as parameters to use a unit. For example, the parameter --debug-real-size=1G sets a real size of 1GB.
This commit is contained in:
parent
1db68aa268
commit
adb8aaec84
39
f3probe.c
39
f3probe.c
@ -79,14 +79,47 @@ static long long arg_to_long_long(const struct argp_state *state,
|
||||
{
|
||||
char *end;
|
||||
long long ll = strtoll(arg, &end, 0);
|
||||
if (!arg)
|
||||
if (end == arg)
|
||||
argp_error(state, "An integer must be provided");
|
||||
if (!*arg || *end)
|
||||
|
||||
/* Deal with units. */
|
||||
switch (*end) {
|
||||
case 's':
|
||||
case 'S': /* Sectors */
|
||||
ll <<= 9;
|
||||
end++;
|
||||
break;
|
||||
|
||||
case 'k':
|
||||
case 'K': /* KB */
|
||||
ll <<= 10;
|
||||
end++;
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
case 'M': /* MB */
|
||||
ll <<= 20;
|
||||
end++;
|
||||
break;
|
||||
|
||||
case 'g':
|
||||
case 'G': /* GB */
|
||||
ll <<= 30;
|
||||
end++;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
case 'T': /* TB */
|
||||
ll <<= 40;
|
||||
end++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (*end)
|
||||
argp_error(state, "`%s' is not an integer", arg);
|
||||
return ll;
|
||||
}
|
||||
|
||||
/* XXX Add a friendly way to enter real and fake sizes: 1, 1k, 1m, 1g... */
|
||||
static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
||||
{
|
||||
struct args *args = state->input;
|
||||
|
Loading…
x
Reference in New Issue
Block a user