@@ -2,7 +2,6 @@
22-- use statfs on Linux and macOS and GetVolumeInformation on Windows
33-- this could still be fooled with symlinks or by disabling journaling on filesystems that support that
44module ProjectM36.FSType where
5−import Foreign
65import Foreign.C.Types
76import Foreign.C.String
87import Foreign.C.Error
@@ -50,25 +49,19 @@ fsTypeSupportJournaling path = do
5049
5150#elif darwin_HOST_OS
5251--Darwin reports journaling directly in the fs flags
53−import Data.Bits
54−#include <sys/param.h>
55−#include <sys/mount.h>
56−type CStatFS = ()
57−foreign import ccall unsafe "sys/mount.h statfs"
58− c_statfs :: CString -> Ptr CStatFS -> IO CInt
5952
60−type CFSFlags = #{type long}
53+type CStatFS = ()
54+foreign import ccall unsafe "cDarwinFSJournaled"
55+ c_DarwinFSJournaled :: CString -> IO CInt
6156
6257fsTypeSupportsJournaling :: FilePath -> IO Bool
63−fsTypeSupportsJournaling path = do
64− struct_statfs <- mallocForeignPtrBytes #{size statfs}
58+fsTypeSupportsJournaling path =
6559 withCString path $ \c_path -> do
66− withForeignPtr struct_statfs $ \ptr_statfs -> do
67− throwErrnoIfMinus1_ "statfs" (c_statfs c_path ptr_statfs)
68− cfsflags <- peekByteOff ptr_statfs #{offset statfs, f_flags} :: IO CFSFlags
69− pure (MNT_JOURNALED .&. cfsflags)
60+ ret <- throwErrnoIfMinus1 "statfs" (c_DarwinFSJournaled c_path)
61+ pure (ret > (0 :: CInt))
7062
7163#elif linux_HOST_OS
64+import Foreign
7265--Linux cannot report journaling, so we just check the filesystem type as a proxy
7366#include <sys/vfs.h>
7467#include <linux/magic.h>