]> arthur.barton.de Git - netatalk.git/commitdiff
Fix option volsizelimit an prepare 2.2 release
authorFrank Lahm <franklahm@googlemail.com>
Sun, 6 Mar 2011 15:01:51 +0000 (16:01 +0100)
committerFrank Lahm <franklahm@googlemail.com>
Sun, 6 Mar 2011 15:01:51 +0000 (16:01 +0100)
NEWS
VERSION
etc/afpd/volume.c

diff --git a/NEWS b/NEWS
index f40686f5fdb3814126437f72b66fb6e4eab2818b..78791dc2e00062749f70aaba8b0ebe11c60bc33b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+Changes in 2.2
+==============
+
+* FIX: afpd: fix option volsizelimit to return a usefull value for the
+       volume free space using `du -sh` with popen
+
 Changes in 2.2beta2
 ====================
 
diff --git a/VERSION b/VERSION
index 1b6bd7a95eb7204ddac6728aede66219eeb867b3..616187889b6f131b13f30fcddddc92c8d1ac1198 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.2beta2
\ No newline at end of file
+2.2
\ No newline at end of file
index 7596a75013dcdb973538987337ac05cd67a7fe73..50514ae3aa2a7f562f4cf86ea17522eb5d77c8d8 100644 (file)
@@ -45,6 +45,9 @@ char *strchr (), *strrchr ();
 #include <atalk/logger.h>
 #include <atalk/vfs.h>
 #include <atalk/uuid.h>
+#include <atalk/bstrlib.h>
+#include <atalk/bstradd.h>
+
 
 #ifdef CNID_DB
 #include <atalk/cnid.h>
@@ -1445,10 +1448,45 @@ static int getvolspace(struct vol *vol,
 
 getvolspace_done:
     if (vol->v_limitsize) {
-        /* FIXME: Free could be limit minus (total minus used), */
-        /* which will confuse the client less ? */
-        *xbfree = min(*xbfree, (vol->v_limitsize * 1024 * 1024));
+        bstring cmdstr;
+        if ((cmdstr = bformat("du -sh \"%s\" 2> /dev/null | cut -f1", vol->v_path)) == NULL)
+            return AFPERR_MISC;
+
+        FILE *cmd = popen(cfrombstr(cmdstr), "r");
+        bdestroy(cmdstr);
+        if (cmd == NULL)
+            return AFPERR_MISC;
+
+        char buf[100];
+        fgets(buf, 100, cmd);
+
+        if (pclose(cmd) == -1)
+            return AFPERR_MISC;
+
+        size_t multi = 0;
+        if (buf[strlen(buf) - 2] == 'G' || buf[strlen(buf) - 2] == 'g')
+            /* GB */
+            multi = 1024 * 1024 * 1024;
+        else if (buf[strlen(buf) - 2] == 'M' || buf[strlen(buf) - 2] == 'm')
+            /* MB */
+            multi = 1024 * 1024;
+        else if (buf[strlen(buf) - 2] == 'K' || buf[strlen(buf) - 2] == 'k')
+            /* MB */
+            multi = 1024;
+
+        char *p;
+        if (p = strchr(buf, ','))
+            /* ignore fraction */
+            *p = 0;
+        else
+            /* remove G|M|K char */
+            buf[strlen(buf) - 2] = 0;
+        /* now buf contains only digits */
+        long long used = atoll(buf) * multi;
+        LOG(log_debug, logtype_afpd, "volparams: used on volume: %llu bytes", used);
+
         *xbtotal = min(*xbtotal, (vol->v_limitsize * 1024 * 1024));
+        *xbfree = min(*xbfree, *xbtotal < used ? 0 : *xbtotal - used);
     }
 
     *bfree = min( *xbfree, maxsize);