From e45c73e66fc18d27bdf5797876fbeb07786a4af1 Mon Sep 17 00:00:00 2001
From: Jimmy Tang 
Date: Tue, 22 Mar 2011 22:24:07 +0000
Subject: [PATCH] Touch up Makefile to depend on StatFS.hs

---
 Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 08e2f59..4ae8392 100644
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ SysConfig.hs: configure.hs TestConfig.hs
        hsc2hs $<
        perl -i -pe 's/^{-# INCLUDE.*//' $@
 
-$(bins): SysConfig.hs Touch.hs
+$(bins): SysConfig.hs Touch.hs StatFS.hs
        $(GHCMAKE) $@
 
 git-annex.1: doc/git-annex.mdwn
-- 
1.7.4.1

StatFS.hs never gets depended on and compiled, the makefile was just missing something

Thanks, done! Interested to hear if StatFS.hs works on OSX (no warning) or is a no-op (with warning). --Joey

for now it gives a warning, it looks like it should be easy enough to add OSX support, I guess it's a case of just digging around documentation to find the equivalent calls/headers. I'll give it a go at making this feature work on OSX and get back to you.

jtang@exia:~/develop/git-annex $ make
hsc2hs StatFS.hsc
StatFS.hsc:85:2: warning: #warning free space checking code not available for this OS
StatFS.hsc:85:2: warning: #warning free space checking code not available for this OS
StatFS.hsc:85:2: warning: #warning free space checking code not available for this OS

Just did some minor digging around and checking, this seems to satisfy the compilers etc... I have yet to confirm that it really is working as expected. Also it might be better to check for a darwin operating system instead of apple I think, though I don't know of any one really using a pure darwin OS. But for now it works (I think)

From fbfe27c2e19906ac02e3673b91bffa920f6dae5d Mon Sep 17 00:00:00 2001
From: Jimmy Tang 
Date: Wed, 23 Mar 2011 08:15:39 +0000
Subject: [PATCH] Define (__APPLE__) in StatFS

At least on OSX 10.6.6 it appears to have the same defintions as
FreeBSD. The build process doesn't complain and the code is enabled,
this needs to be tested and checked more.
---
 StatFS.hsc |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/StatFS.hsc b/StatFS.hsc
index 8b453dc..45fd7e4 100644
--- a/StatFS.hsc
+++ b/StatFS.hsc
@@ -53,7 +53,7 @@ import Foreign.C.String
 import Data.ByteString (useAsCString)
 import Data.ByteString.Char8 (pack)
 
-#if defined (__FreeBSD__)
+#if defined (__FreeBSD__) || defined(__APPLE__)
 # include 
 # include 
 #else
@@ -84,7 +84,7 @@ data CStatfs
 #ifdef UNKNOWN
 #warning free space checking code not available for this OS
 #else
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__APPLE__)
 foreign import ccall unsafe "sys/mount.h statfs"
 #else
 foreign import ccall unsafe "sys/vfs.h statfs64"
-- 
1.7.4.1
Comment by Jimmy Wed Mar 23 08:21:30 2011
There's a simple test -- just configure annex.diskreserve to be say, 10 megabytes less than the total free space on your disk. Then try to git annex get a 11 mb file, and a 9 mb file. :)
Comment by joey Wed Mar 23 15:05:12 2011

Alternatively, you can just load it up in ghci and see if it reports numbers that make sense:

joey@gnu:~/src/git-annex>make StatFS.hs
hsc2hs StatFS.hsc
perl -i -pe 's/^{-# INCLUDE.*//' StatFS.hs
joey@gnu:~/src/git-annex>ghci StatFS.hs
GHCi, version 6.12.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling StatFS           ( StatFS.hs, interpreted )
Ok, modules loaded: StatFS.
*StatFS> s <- getFileSystemStats "."
Loading package bytestring-0.9.1.5 ... linking ... done.
*StatFS> s
Just (FileSystemStats {fsStatBlockSize = 4096, fsStatBlockCount = 7427989, fsStatByteCount = 30425042944, fsStatBytesFree = 2528489472, fsStatBytesAvailable = 2219384832, fsStatBytesUsed = 27896553472})
Comment by joey Wed Mar 23 15:13:33 2011

Ok, well it looks like it isn't doing anything useful at all.

jtang@x00:~/develop/git-annex $ make StatFS.hs                                                                                                                                    
hsc2hs StatFS.hsc
perl -i -pe 's/^{-# INCLUDE.*//' StatFS.hs
jtang@x00:~/develop/git-annex $ ghci StatFS.hs                                                                                                                                    
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 1] Compiling StatFS           ( StatFS.hs, interpreted )
Ok, modules loaded: StatFS.
*StatFS> s <- getFileSystemStats "."
Loading package bytestring-0.9.1.7 ... linking ... done.
*StatFS> s
Just (FileSystemStats {fsStatBlockSize = 0, fsStatBlockCount = 1048576, fsStatByteCount = 0, fsStatBytesFree = 0, fsStatBytesAvailable = 0, fsStatBytesUsed = 0})
*StatFS> s <- getFileSystemStats "/"
*StatFS> s
Just (FileSystemStats {fsStatBlockSize = 0, fsStatBlockCount = 1048576, fsStatByteCount = 0, fsStatBytesFree = 0, fsStatBytesAvailable = 0, fsStatBytesUsed = 0})
*StatFS> 
Comment by Jimmy Wed Mar 23 16:02:34 2011

Actually I may have just been stupid and should have read the man page on statfs...

jtang@x00:~/develop/git-annex $ git diff
diff --git a/StatFS.hsc b/StatFS.hsc
index 8b453dc..e10b2dd 100644
--- a/StatFS.hsc
+++ b/StatFS.hsc
@@ -53,7 +53,7 @@ import Foreign.C.String
 import Data.ByteString (useAsCString)
 import Data.ByteString.Char8 (pack)
 
-#if defined (__FreeBSD__)
+#if defined (__FreeBSD__) || defined (__APPLE__)
 # include 
 # include 
 #else
@@ -84,8 +84,8 @@ data CStatfs
 #ifdef UNKNOWN
 #warning free space checking code not available for this OS
 #else
-#if defined(__FreeBSD__)
-foreign import ccall unsafe "sys/mount.h statfs"
+#if defined(__FreeBSD__) || defined (__APPLE__)
+foreign import ccall unsafe "sys/mount.h statfs64"
 #else
 foreign import ccall unsafe "sys/vfs.h statfs64"
 #endif

yields this...

jtang@x00:~/develop/git-annex $ ghci StatFS.hs                                                                                                                                    
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
[1 of 1] Compiling StatFS           ( StatFS.hs, interpreted )
Ok, modules loaded: StatFS.
*StatFS> s <- getFileSystemStats "."
Loading package bytestring-0.9.1.7 ... linking ... done.
*StatFS> s
Just (FileSystemStats {fsStatBlockSize = 4096, fsStatBlockCount = 244106668, fsStatByteCount = 999860912128, fsStatBytesFree = 423097798656, fsStatBytesAvailable = 422835654656, fsStatBytesUsed = 576763113472})
*StatFS> 

we could just stick another if defined (APPLE) instead of what I previously had and it looks like it will do the right thing on OSX.

Comment by Jimmy Wed Mar 23 16:14:22 2011

I forgot to mention that the statfs64 stuff in OSX seems to be deprecated, see http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/statfs64.2.html

on a slightly different note, is anonymous pushing to the "wiki" over git allowed? I'd prefer to be able to edit stuff inline for updating some of my own comments if I can :P

Comment by Jimmy Wed Mar 23 16:23:56 2011

Try the changes I've pushed to use statfs64 on apple.

There is actually a standardized statvfs that I'd rather use, but after the last time that I tried going with the POSIX option first only to find it was not broadly implemented, I was happy to find some already existing code that worked for some OSs.

(While ikiwiki supports anonymous git push, it's a feature we have not rolled out on Branchable.com yet, and anyway, ikiwiki disallows editing existing comments that way. I would, however, be happy to git pull changes from somewhere.)

Comment by joey Wed Mar 23 16:57:56 2011
The latest change looks good, it seems to be returning sensible numbers for me. Just tried it out on a few different mount points and it appears to be working.
Comment by Jimmy Wed Mar 23 17:03:51 2011