status->MinQuota = status->MaxQuota = -1;
motd = offmsg = NULL;
if (as->parms[1].items) {
- code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
+ code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
if (code) {
fprintf(stderr,"%s: bad integer specified for quota.\n", pn);
error = 1;
return 1;
}
if (as->parms[0].items) {
- code = util_GetInt32(as->parms[0].items->data, &temp);
+ code = util_GetHumanInt32(as->parms[0].items->data, &temp);
if (code) {
fprintf(stderr,"%s: bad integer specified for cache size.\n", pn);
return 1;
#endif */
#define MAX_AFS_INT32 0x7FFFFFFF
+#define MIN_AFS_INT32 (-MAX_AFS_INT32 - 1)
#define MAX_AFS_UINT32 0xFFFFFFFF
#define MAX_AFS_INT64 0x7FFFFFFFFFFFFFFFL
+#define MIN_AFS_INT64 (-MAX_AFS_INT64 - 1)
#define MAX_AFS_UINT64 0xFFFFFFFFFFFFFFFFL
typedef short afs_int16;
extern char *volutil_PartitionName(int avalue);
extern afs_int32 util_GetInt32(register char *as, afs_int32 * aval);
extern afs_uint32 util_GetUInt32(register char *as, afs_uint32 * aval);
+extern afs_int32 util_GetHumanInt32(register char *as, afs_int32 * aval);
/* winsock_nt.c */
#include <afs/param.h>
#include <string.h>
+#include <errno.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
*aval = total;
return 0;
}
+
+static const char power_letter[] = {
+ 'K', /* kibi */
+ 'M', /* mebi */
+ 'G', /* gibi */
+ 'T', /* tebi */
+};
+
+afs_int32
+util_GetHumanInt32(register char *as, afs_int32 * aval)
+{
+ long value;
+ char * unit;
+ long mult = 1;
+ int exponent = 0;
+
+ errno = 0;
+ value = strtol(as, &unit, 0);
+ if (errno)
+ return -1;
+ if (unit[0] != 0) {
+ for (exponent = 0; exponent < sizeof(power_letter) && power_letter[exponent] != unit[0]; exponent++) {
+ mult *= 1024;
+ }
+ if (exponent == sizeof(power_letter))
+ return -1;
+ }
+ if (value > MAX_AFS_INT32 / mult || value < MIN_AFS_INT32 / mult)
+ return -1;
+
+ *aval = value * mult;
+
+ return 0;
+}
status->MinQuota = status->MaxQuota = -1;
offmsg = NULL;
if (as->parms[1].items) {
- code = util_GetInt32(as->parms[1].items->data, &status->MaxQuota);
+ code = util_GetHumanInt32(as->parms[1].items->data, &status->MaxQuota);
if (code) {
fprintf(stderr, "%s: bad integer specified for quota.\n", pn);
error = 1;
return 1;
}
if (as->parms[0].items) {
- code = util_GetInt32(as->parms[0].items->data, &temp);
+ code = util_GetHumanInt32(as->parms[0].items->data, &temp);
if (code) {
fprintf(stderr, "%s: bad integer specified for cache size.\n",
pn);
if (as->parms[1].items) {
/* -max <quota> */
- code = util_GetInt32(as->parms[1].items->data, &info.maxquota);
+ code = util_GetHumanInt32(as->parms[1].items->data, &info.maxquota);
if (code) {
fprintf(STDERR, "invalid quota value\n");
return code;
}
if (as->parms[3].items) {
- if (!IsNumeric(as->parms[3].items->data)) {
- fprintf(STDERR, "Initial quota %s should be numeric.\n",
- as->parms[3].items->data);
- return EINVAL;
- }
-
- code = util_GetInt32(as->parms[3].items->data, "a);
+ code = util_GetHumanInt32(as->parms[3].items->data, "a);
if (code) {
fprintf(STDERR, "vos: bad integer specified for quota.\n");
return code;