]> andersk Git - moira.git/commitdiff
Allow quotas to be specified in a form like '500mb' rather than '500000'
authorzacheiss <zacheiss>
Mon, 22 Sep 2003 20:44:16 +0000 (20:44 +0000)
committerzacheiss <zacheiss>
Mon, 22 Sep 2003 20:44:16 +0000 (20:44 +0000)
or '1gb' instead of '1000000'.

clients/moira/f_defs.h
clients/moira/quota.c

index b69ea23c92321dbb2311b8226f5d69b90ca6cd2e..824ebceecc24a5fcb7ec272e5cae415eebcbfbf1 100644 (file)
@@ -143,6 +143,7 @@ int GetQuotaByFilesys(int argc, char **argv);
 int AddQuota(int argc, char **argv);
 int UpdateQuota(int argc, char **argv);
 int DeleteQuota(int argc, char **argv);
+char *ParseQuotaString(char *quota);
 
 /* user.c */
 
index 96adfad2efcbfd9030c3f6d471b736f0b6d260bd..9ad0a40e55829fe90f66a114b5c57889746cd30f 100644 (file)
@@ -150,6 +150,7 @@ static char **GetQuotaArgs(Bool quota)
 {
   char **args = malloc(MAX_ARGS_SIZE * sizeof(char *));
   int af;
+  char *canon;
 
   if (!args)
     {
@@ -206,6 +207,11 @@ static char **GetQuotaArgs(Bool quota)
        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;
 }
@@ -362,6 +368,7 @@ static void RealUpdateQuota(char **info)
 {
   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)
@@ -370,6 +377,12 @@ static void RealUpdateQuota(char **info)
       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)
       {
@@ -475,3 +488,44 @@ int DeleteQuota(int argc, char **argv)
   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;
+}
This page took 0.054049 seconds and 5 git commands to generate.