]> granicus.if.org Git - transmission/commitdiff
(trunk, libT) #5643 'quota support for NetBSD >= 6' -- patch by wiz
authorJordan Lee <jordan@transmissionbt.com>
Sun, 27 Apr 2014 00:02:00 +0000 (00:02 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sun, 27 Apr 2014 00:02:00 +0000 (00:02 +0000)
configure.ac
libtransmission/platform-quota.c

index 27949fb6c5855049a0abd701df79fb83de4e3d56..a92ed7a6ff08feaf079ca4fce552903e2e7def94 100644 (file)
@@ -108,6 +108,7 @@ fi
 AC_SEARCH_LIBS(cos, [m])
 AC_SEARCH_LIBS([socket], [socket net])
 AC_SEARCH_LIBS([gethostbyname], [nsl bind])
+AC_SEARCH_LIBS([quotacursor_skipidtype], [quota])
 PKG_CHECK_MODULES(OPENSSL, [openssl >= $OPENSSL_MINIMUM], , [CHECK_SSL()])
 PKG_CHECK_MODULES(LIBCURL, [libcurl >= $CURL_MINIMUM])
 PKG_CHECK_MODULES(LIBEVENT, [libevent >= $LIBEVENT_MINIMUM])
index 28c2d98dea430f47d2d6f2f9c8f37775b4367215..6a7d545e7164d432b2e91389b4e4d20ee15a5fb4 100644 (file)
  #include <sys/types.h> /* types needed by quota.h */
  #if defined(__FreeBSD__) || defined(__OpenBSD__)
   #include <ufs/ufs/quota.h> /* quotactl() */
+ #elif defined (__NetBSD__)
+  #include <sys/param.h>
+  #ifndef statfs
+   #define statfs statvfs
+  #endif
  #elif defined (__sun)
   #include <sys/fs/ufs_quota.h> /* quotactl */
  #else
@@ -192,6 +197,47 @@ getblkdev (const char * path)
   return device;
 }
 
+#if defined(__NetBSD__) && (__NetBSD_Version__ >= 600000000)
+#include <quota.h>
+
+static int64_t
+getquota (const char * device)
+{
+  struct quotahandle *qh;
+  struct quotakey qk;
+  struct quotaval qv;
+  int64_t limit;
+  int64_t freespace;
+  int64_t spaceused;
+
+  qh = quota_open(device);
+  if (qh == NULL) {
+    return -1;
+  }
+  qk.qk_idtype = QUOTA_IDTYPE_USER;
+  qk.qk_id = getuid();
+  qk.qk_objtype = QUOTA_OBJTYPE_BLOCKS;
+  if (quota_get(qh, &qk, &qv) == -1) {
+    quota_close(qh);
+    return -1;
+  }
+  if (qv.qv_softlimit > 0) {
+    limit = qv.qv_softlimit;
+  }
+  else if (qv.qv_hardlimit > 0) {
+    limit = qv.qv_hardlimit;
+  }
+  else {
+    quota_close(qh);
+    return -1;
+  }
+  spaceused = qv.qv_usage;
+  quota_close(qh);
+
+  freespace = limit - spaceused;
+  return (freespace < 0) ? 0 : freespace;
+}
+#else
 static int64_t
 getquota (const char * device)
 {
@@ -256,6 +302,7 @@ getquota (const char * device)
   /* something went wrong */
   return -1;
 }
+#endif
 
 #ifdef HAVE_XQM
 static int64_t