int AddQuota(int argc, char **argv);
int UpdateQuota(int argc, char **argv);
int DeleteQuota(int argc, char **argv);
+char *ParseQuotaString(char *quota);
/* user.c */
{
char **args = malloc(MAX_ARGS_SIZE * sizeof(char *));
int af;
+ char *canon;
if (!args)
{
return NULL;
if (!ValidName(args[Q_QUOTA]))
return NULL;
+ canon = ParseQuotaString(args[Q_QUOTA]);
+ if (!canon)
+ return NULL;
+ free(args[Q_QUOTA]);
+ args[Q_QUOTA] = canon;
}
return args;
}
{
int status;
char temp_buf[BUFSIZ];
+ char *canon;
sprintf(temp_buf, "New quota for filesystem %s (in KB)", info[Q_FILESYS]);
if (GetValueFromUser(temp_buf, &info[Q_QUOTA]) == SUB_ERROR)
return;
}
+ canon = ParseQuotaString(info[Q_QUOTA]);
+ if (!canon)
+ return;
+ free(info[Q_QUOTA]);
+ info[Q_QUOTA] = canon;
+
if ((status = do_mr_query("update_quota", 4, info,
NULL, NULL)) != MR_SUCCESS)
{
FreeQueue(top);
return DM_NORMAL;
}
+
+char *ParseQuotaString(char *quota)
+{
+ char *s, *value;
+ float ngigs, nmegs;
+ int calcvalue;
+
+ s = quota;
+ while (*s && (isdigit(*s) || (*s == '.')))
+ s++;
+
+ /* If we didn't find a unit specifier, just return the old value. */
+ if (!*s)
+ return strdup(quota);
+
+ switch (*s) {
+ case 'm':
+ case 'M':
+ /* value specified in megabytes. */
+ if (!sscanf(quota, "%f2", &nmegs))
+ return strdup(quota);
+ calcvalue = (int)(nmegs * 1000);
+ break;
+ case 'g':
+ case 'G':
+ /* value specified in gigabytes. */
+ if (!sscanf(quota, "%f2", &ngigs))
+ return strdup(quota);
+ calcvalue = (int)(ngigs * 1000 * 1000);
+ break;
+ default:
+ /* Couldn't parse it. Just return the old value. */
+ return strdup(quota);
+ }
+
+ value = malloc(BUFSIZ);
+ if (!value)
+ return NULL;
+ sprintf(value, "%d", calcvalue);
+ return value;
+}