From 02085e5e069b2f0c49a1dbf45bb2538cac993545 Mon Sep 17 00:00:00 2001 From: Frank Lahm Date: Sun, 6 Mar 2011 16:01:51 +0100 Subject: [PATCH] Fix option volsizelimit an prepare 2.2 release --- NEWS | 6 ++++++ VERSION | 2 +- etc/afpd/volume.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index f40686f5..78791dc2 100644 --- 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 1b6bd7a9..61618788 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2beta2 \ No newline at end of file +2.2 \ No newline at end of file diff --git a/etc/afpd/volume.c b/etc/afpd/volume.c index 7596a750..50514ae3 100644 --- a/etc/afpd/volume.c +++ b/etc/afpd/volume.c @@ -45,6 +45,9 @@ char *strchr (), *strrchr (); #include #include #include +#include +#include + #ifdef CNID_DB #include @@ -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); -- 2.39.2