janestreet / core_extended

Jane Street Capital's standard library overlay
MIT License
34 stars 9 forks source link

fails to compile on FreeBSD (113.33.00) #8

Closed hannesm closed 8 years ago

hannesm commented 8 years ago
# src/extended_unix_stubs.c:150:55: error: no member named 'dqb_curbytes' in 'struct dqblk64'
# [...]
#                                                       ^~~~~~~~~~~~~~~~~~~~~~~
# src/extended_unix_stubs.c:100:44: note: expanded from macro 'QUOTA_SPACE_USED'
# #  define QUOTA_SPACE_USED(quota) ((quota).dqb_curbytes)
#                                    ~~~~~~~ ^
#1 error generated.
ghost commented 8 years ago

If you have a patch, I can integrate it in the next minor release. Hopefully for the next major release we'll have freebsd builds on our side

magv commented 8 years ago

Here's a patch that fixes compilation for me (on FreeBSD 10.1), and to my knowledge is correct, but is completely untested, since I don't use quotas. In fact, I don't even know if quotactl works on ZFS (or NFS), since it's declaration lies under <ufs/ufs/quota.h>.

--- src/extended_unix_stubs.c.orig  2016-04-28 12:46:22.000000000 +0300
+++ src/extended_unix_stubs.c   2016-06-23 01:58:03.000000000 +0300
@@ -92,7 +92,16 @@
   CAMLreturn(v_ret);
 }

-#if !(defined _LINUX_QUOTA_VERSION) /* BSD, Mac OS */
+#if defined (__FreeBSD__) || defined (__OpenBSD__)
+
+#  define quota_control(device, cmd, id, parg)  \
+     quotactl((device), (cmd), (id), (parg))
+#  define QUOTA_BYTES_PER_SPACE_UNIT DEV_BSIZE
+#  define QUOTA_SPACE_USED(quota) ((quota).dqb_curblocks)
+#  define QUOTA_MODIFY_COMMAND Q_SETQUOTA
+#  define QUOTA_SET_VALID_FIELDS(quota) ((void)quota)
+
+#elif !(defined _LINUX_QUOTA_VERSION) /* Mac OS */

 #  define quota_control(device, cmd, id, parg)  \
      quotactl((device), (cmd), (id), (parg))
seliopou commented 8 years ago

Fixed by e3ba689

magv commented 8 years ago

Why did you set QUOTA_BYTES_PER_SPACE_UNIT to 1 though? As far as I'm aware dqb_curblocks field is expressed in number of blocks, where one block is DEV_BSIZE (=512) bytes.

Now, dqb_curblocks is not really mentioned in any man page I know of, but you can infer it's intended usage by searching for it in quota(1) sources at [1], edquota(1) at [2], or directly look at "dbtob" macro, which is used to convert dqb_curblocks to bytes over at [3](dbtob%28x%29 is x<<DEV_BSHIFT = x*DEV_BSIZE).

[1] http://svnweb.freebsd.org/base/release/10.2.0/usr.bin/quota/quota.c?revision=286717&view=markup [2] http://svnweb.freebsd.org/base/release/10.2.0/usr.sbin/edquota/edquota.c?revision=286717&view=markup [3] http://svnweb.freebsd.org/base/release/10.2.0/sys/sys/param.h?revision=286717&view=markup#l209