File tree Expand file tree Collapse file tree 5 files changed +57
-7
lines changed
src-linux/System/FS/BlockIO
src-macos/System/FS/BlockIO Expand file tree Collapse file tree 5 files changed +57
-7
lines changed Original file line number Diff line number Diff line change @@ -93,17 +93,21 @@ library
9393
9494 if os(linux)
9595 hs-source-dirs : src-linux
96- other-modules : System.FS.BlockIO.Internal
97- build-depends : unix ^>= 2.8.7
96+ build-depends : unix ^>= 2.8.6
97+ other-modules :
98+ System.FS.BlockIO.Internal
99+ System.FS.BlockIO.Internal.Fcntl
98100
99101 if !flag(serialblockio)
100102 other-modules : System.FS.BlockIO.Async
101103 build-depends : blockio-uring ^>= 0.1
102104
103105 elif os(osx)
104106 hs-source-dirs : src-macos
105- build-depends : unix ^>= 2.8.7
106- other-modules : System.FS.BlockIO.Internal
107+ build-depends : unix ^>= 2.8.6
108+ other-modules :
109+ System.FS.BlockIO.Internal
110+ System.FS.BlockIO.Internal.Fcntl
107111
108112 elif os(windows)
109113 hs-source-dirs : src-windows
Original file line number Diff line number Diff line change 11{-# LANGUAGE CPP #-}
2-
32module System.FS.BlockIO.Internal (
43 ioHasBlockIO
54 ) where
65
76import qualified System.FS.API as FS
87import System.FS.API (FsPath , Handle (.. ), HasFS )
98import System.FS.BlockIO.API (Advice (.. ), FileOffset , HasBlockIO )
9+ import qualified System.FS.BlockIO.Internal.Fcntl as Fcntl
1010import qualified System.FS.BlockIO.IO.Internal as IOI
1111import System.FS.IO (HandleIO )
1212import qualified System.FS.IO.Handle as FS
13- import qualified System.Posix.Fcntl as Fcntl
13+ import qualified System.Posix.Fcntl as Fcntl hiding ( fileSetCaching )
1414import qualified System.Posix.Files as Unix
1515import qualified System.Posix.Unistd as Unix
1616
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE CPP #-}
2+ module System.FS.BlockIO.Internal.Fcntl (fileSetCaching ) where
3+
4+ #if MIN_VERSION_unix(2,8,7)
5+
6+ import System.Posix.Fcntl (fileSetCaching )
7+
8+ #else
9+
10+ #include <fcntl.h>
11+
12+ import Data.Bits (complement , (.&.) , (.|.) )
13+ import Foreign.C (throwErrnoIfMinus1 , throwErrnoIfMinus1_ )
14+ import System.Posix.Internals
15+ import System.Posix.Types (Fd (Fd ))
16+
17+ -- | For simplification, we considered that Linux !HAS_F_NOCACHE and HAS_O_DIRECT
18+ fileSetCaching :: Fd -> Bool -> IO ()
19+ fileSetCaching (Fd fd) val = do
20+ r <- throwErrnoIfMinus1 " fileSetCaching" (c_fcntl_read fd # {const F_GETFL })
21+ let r' | val = fromIntegral r .&. complement opt_val
22+ | otherwise = fromIntegral r .|. opt_val
23+ throwErrnoIfMinus1_ " fileSetCaching" (c_fcntl_write fd # {const F_SETFL } r')
24+ where
25+ opt_val = # {const O_DIRECT }
26+ #endif
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ module System.FS.BlockIO.Internal (
55import qualified System.FS.API as FS
66import System.FS.API (FsPath , Handle (.. ), HasFS )
77import System.FS.BlockIO.API (Advice (.. ), FileOffset , HasBlockIO )
8+ import qualified System.FS.BlockIO.Internal.Fcntl as Unix
89import qualified System.FS.BlockIO.IO.Internal as IOI
910import qualified System.FS.BlockIO.Serial as Serial
1011import System.FS.IO (HandleIO )
1112import qualified System.FS.IO.Handle as FS
12- import qualified System.Posix.Fcntl as Unix
1313import qualified System.Posix.Files as Unix
1414import qualified System.Posix.Unistd as Unix
1515
Original file line number Diff line number Diff line change 1+ {-# LANGUAGE CPP #-}
2+ module System.FS.BlockIO.Internal.Fcntl (fileSetCaching ) where
3+
4+ #if MIN_VERSION_unix(2,8,7)
5+
6+ import System.Posix.Fcntl (fileSetCaching )
7+
8+ #else
9+
10+ #include <fcntl.h>
11+
12+ import Foreign.C (throwErrnoIfMinus1_ )
13+ import System.Posix.Internals
14+ import System.Posix.Types (Fd (Fd ))
15+
16+ -- | For simplification, we considered that MacOS HAS_F_NOCACHE and !HAS_O_DIRECT
17+ fileSetCaching :: Fd -> Bool -> IO ()
18+ fileSetCaching (Fd fd) val = do
19+ throwErrnoIfMinus1_ " fileSetCaching" (c_fcntl_write fd # {const F_NOCACHE } (if val then 0 else 1 ))
20+ #endif
You can’t perform that action at this time.
0 commit comments