Quota tools can report block limit in human friendly form using `-s' options, but they cannot understand such values on user input. Following three patches implements this feature at setquota and edquota tools.
Thanks. I've merged the patches with some modifications.
a) I've folded patch 0004 into patch 0001
b) I've fixed some whitespace damage (spaces at end of line, spaces before tabs)
c) I've added your Signed-off-by to the patches (please acknowledge you are fine with that)
d) I've fixed overflow checks in the conversion functions (checking for overflow with number > value doesn't really work when multiplication or shifts are used...).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Regarding overflow checks, I think they work on unsigned integers. Only conversion from signed type is undefined. Now not all constants in str2number() are marked as unsigned (only the tera multiple is unsigned). I recommend to add the `U' suffix to the literals. (GCC 4.8 will be more aggressive in this area.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You had checks like:
value = number << 10;
if (value < number) Overflow....
But if we use 64-bit type and number == (1 << 54) + (1 << 53), then (number << 10) == (1 << 63) . No value > number but an overflow happened.
Regarding signed vs unsigned constants - assignment of signed constants to unsigned variables which I do is well defined by the C standard AFAIK. So I see no reason why I should change them. I used ULL for the tera multiple because there the constant doesn't fit into 'int' type so I had to put declare it as (unsigned) long long. But maybe I misunderstood you?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You are right. I somehow forgot on less significant bits.
I don't know much about the constants, but what makes tera value so special from the others? How can you be sure other constants fit into `int' type? You don't have to bother answering, I will try to study the specification more.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ah, that's simple but you won't find it in the standard. I blindly assume int has at least 32 bits. Standard doesn't guarantee this (it actually doesn't guarantee much about type sizes) but in practice all architectures I care about have this. More portable would be to use u32 or similar types but who cares...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
0001-Recognize-units-at-block-limits-by-setquota.patch
0002-Recognize-block-limit-units-on-setquota-standard-inp.patch
0003-Recognize-units-at-block-limits-by-edquota.patch
0004-Fix-typo-in-error-message.patch
0005-Recognize-units-at-inode-limits-by-setquota.patch
0006-Recognize-units-at-inode-limits-by-edquota.patch
Patch 0004 corrects two error messages in previous patches. Patched 0005 and 0006 implements the unites at inode numbers.
Thanks. I've merged the patches with some modifications.
a) I've folded patch 0004 into patch 0001
b) I've fixed some whitespace damage (spaces at end of line, spaces before tabs)
c) I've added your Signed-off-by to the patches (please acknowledge you are fine with that)
d) I've fixed overflow checks in the conversion functions (checking for overflow with number > value doesn't really work when multiplication or shifts are used...).
I have no problem with Signed-off.
Regarding overflow checks, I think they work on unsigned integers. Only conversion from signed type is undefined. Now not all constants in str2number() are marked as unsigned (only the tera multiple is unsigned). I recommend to add the `U' suffix to the literals. (GCC 4.8 will be more aggressive in this area.)
You had checks like:
value = number << 10;
if (value < number) Overflow....
But if we use 64-bit type and number == (1 << 54) + (1 << 53), then (number << 10) == (1 << 63) . No value > number but an overflow happened.
Regarding signed vs unsigned constants - assignment of signed constants to unsigned variables which I do is well defined by the C standard AFAIK. So I see no reason why I should change them. I used ULL for the tera multiple because there the constant doesn't fit into 'int' type so I had to put declare it as (unsigned) long long. But maybe I misunderstood you?
You are right. I somehow forgot on less significant bits.
I don't know much about the constants, but what makes tera value so special from the others? How can you be sure other constants fit into `int' type? You don't have to bother answering, I will try to study the specification more.
Ah, that's simple but you won't find it in the standard. I blindly assume int has at least 32 bits. Standard doesn't guarantee this (it actually doesn't guarantee much about type sizes) but in practice all architectures I care about have this. More portable would be to use u32 or similar types but who cares...