be a no-op on non-linux, non-freebsd systems
Todo later: use POSIX statvfs Note: Re OSX, see http://code.google.com/p/xmobar/issues/detail?id=28 Apparently xmobar's code will work on OSX, probably __FreeBSD__ is defined there.
This commit is contained in:
parent
8ede2e255f
commit
aa1bc31e0a
1 changed files with 13 additions and 1 deletions
14
StatFS.hsc
14
StatFS.hsc
|
@ -1,7 +1,7 @@
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
-- |
|
-- |
|
||||||
--
|
--
|
||||||
-- (This code comes from xmobar)
|
-- (This code originally comes from xmobar)
|
||||||
--
|
--
|
||||||
-- Module : StatFS
|
-- Module : StatFS
|
||||||
-- Copyright : (c) Jose A Ortega Ruiz
|
-- Copyright : (c) Jose A Ortega Ruiz
|
||||||
|
@ -57,7 +57,11 @@ import Data.ByteString.Char8 (pack)
|
||||||
# include <sys/param.h>
|
# include <sys/param.h>
|
||||||
# include <sys/mount.h>
|
# include <sys/mount.h>
|
||||||
#else
|
#else
|
||||||
|
#if defined (__linux__)
|
||||||
#include <sys/vfs.h>
|
#include <sys/vfs.h>
|
||||||
|
#else
|
||||||
|
#define UNKNOWN
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
data FileSystemStats = FileSystemStats {
|
data FileSystemStats = FileSystemStats {
|
||||||
|
@ -77,18 +81,25 @@ data FileSystemStats = FileSystemStats {
|
||||||
|
|
||||||
data CStatfs
|
data CStatfs
|
||||||
|
|
||||||
|
#ifdef UNKNOWN
|
||||||
|
#warning free space checking code not available for this OS
|
||||||
|
#else
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
foreign import ccall unsafe "sys/mount.h statfs"
|
foreign import ccall unsafe "sys/mount.h statfs"
|
||||||
#else
|
#else
|
||||||
foreign import ccall unsafe "sys/vfs.h statfs64"
|
foreign import ccall unsafe "sys/vfs.h statfs64"
|
||||||
#endif
|
#endif
|
||||||
c_statfs :: CString -> Ptr CStatfs -> IO CInt
|
c_statfs :: CString -> Ptr CStatfs -> IO CInt
|
||||||
|
#endif
|
||||||
|
|
||||||
toI :: CLong -> Integer
|
toI :: CLong -> Integer
|
||||||
toI = toInteger
|
toI = toInteger
|
||||||
|
|
||||||
getFileSystemStats :: String -> IO (Maybe FileSystemStats)
|
getFileSystemStats :: String -> IO (Maybe FileSystemStats)
|
||||||
getFileSystemStats path =
|
getFileSystemStats path =
|
||||||
|
#ifdef UNKNOWN
|
||||||
|
return Nothing
|
||||||
|
#else
|
||||||
allocaBytes (#size struct statfs) $ \vfs ->
|
allocaBytes (#size struct statfs) $ \vfs ->
|
||||||
useAsCString (pack path) $ \cpath -> do
|
useAsCString (pack path) $ \cpath -> do
|
||||||
res <- c_statfs cpath vfs
|
res <- c_statfs cpath vfs
|
||||||
|
@ -107,3 +118,4 @@ getFileSystemStats path =
|
||||||
, fsStatBytesAvailable = toI bavail * bpb
|
, fsStatBytesAvailable = toI bavail * bpb
|
||||||
, fsStatBytesUsed = toI (bcount - bfree) * bpb
|
, fsStatBytesUsed = toI (bcount - bfree) * bpb
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue