on master help sign in
compiled journal check and tested on darwin
commitd697aa891bdea75c319dbab49f56452d7a056b2d authorAgentM <agentm@themactionfaction.com> dateSun 15 Oct 2017, 22:01 (9 years ago) parentf64726c
4 files changed+42−18
cbits/darwin_statfs.c+22 project-m36.cabal+3−1 src/lib/ProjectM36/FSType.hsc+7−14 src/lib/ProjectM36/Server.hs+10−3
cbits/darwin_statfs.cnew file+22
@@ -0,0 +1,22 @@
1+#include <sys/param.h>
2+#include <sys/mount.h>
3+#include <stdio.h>
4+
5+#ifndef _PROJECT_M36_STATFS_
6+#define _PROJECT_M36_STATFS_
7+
8+int cDarwinFSJournaled(const char* path)
9+{
10+ struct statfs s = {0};
11+ int ret = statfs(path, &s);
12+ if(ret < 0)
13+ {
14+ /* error */
15+ return ret;
16+ }
17+ else
18+ {
19+ return s.f_flags & MNT_JOURNALED;
20+ }
21+}
22+#endif
project-m36.cabal+3−1
@@ -154,7 +154,7 @@ Library
154154 Build-Depends: Win32 >= 2.3
155155 Other-Modules: ProjectM36.Win32Handle
156156 else
157− C-sources: cbits/DirectoryFsync.c
157+ C-sources: cbits/DirectoryFsync.c, cbits/darwin_statfs.c
158158 Build-Depends: unix
159159 CC-Options: -fPIC
160160 Hs-Source-Dirs: ./src/lib
@@ -534,3 +534,5 @@ Executable handles
534534 HS-Source-Dirs: ./src/bin
535535 if flag(profiler)
536536 GHC-Prof-Options: -fprof-auto -rtsopts -threaded -Wall
537+
538+
src/lib/ProjectM36/FSType.hsc+7−14
@@ -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>
src/lib/ProjectM36/Server.hs+10−3
@@ -16,7 +16,8 @@ import Control.Distributed.Process (Process, register, getSelfPid)
1616import Control.Distributed.Process.ManagedProcess (defaultProcess, UnhandledMessagePolicy(..), ProcessDefinition(..), handleCall, serve, InitHandler, InitResult(..))
1717import Control.Concurrent.MVar (putMVar, MVar)
1818import System.IO (stderr, hPutStrLn)
19−
19+import System.FilePath (takeDirectory)
20+import System.Directory (doesDirectoryExist)
2021
2122-- the state should be a mapping of remote connection to the disconnected transaction- the graph should be the same, so discon must be removed from the stm tuple
2223--trying to refactor this for less repetition is very challenging because the return type cannot be polymorphic or the distributed-process call gets confused and drops messages
@@ -83,8 +84,14 @@ checkFSType performCheck strat =
8384 NoPersistence -> pure True
8485 MinimalPersistence _ -> pure True
8586 CrashSafePersistence path ->
86− if performCheck then
87− fsTypeSupportsJournaling path
87+ if performCheck then do
88+ -- if the path does not (yet) exist, then walk back a step- the db directory may not yet have been created
89+ fullpathexists <- doesDirectoryExist path
90+ let fscheckpath = if fullpathexists then
91+ path
92+ else
93+ takeDirectory path
94+ fsTypeSupportsJournaling fscheckpath
8895 else
8996 pure True
9097