Skip to content

Commit bcd2a76

Browse files
committed
Allow unix 2.8.6
1 parent aa63e5a commit bcd2a76

File tree

5 files changed

+57
-7
lines changed

5 files changed

+57
-7
lines changed

blockio/blockio.cabal

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff 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

blockio/src-linux/System/FS/BlockIO/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{-# LANGUAGE CPP #-}
2-
32
module System.FS.BlockIO.Internal (
43
ioHasBlockIO
54
) where
65

76
import qualified System.FS.API as FS
87
import System.FS.API (FsPath, Handle (..), HasFS)
98
import System.FS.BlockIO.API (Advice (..), FileOffset, HasBlockIO)
9+
import qualified System.FS.BlockIO.Internal.Fcntl as Fcntl
1010
import qualified System.FS.BlockIO.IO.Internal as IOI
1111
import System.FS.IO (HandleIO)
1212
import 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)
1414
import qualified System.Posix.Files as Unix
1515
import qualified System.Posix.Unistd as Unix
1616

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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

blockio/src-macos/System/FS/BlockIO/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ module System.FS.BlockIO.Internal (
55
import qualified System.FS.API as FS
66
import System.FS.API (FsPath, Handle (..), HasFS)
77
import System.FS.BlockIO.API (Advice (..), FileOffset, HasBlockIO)
8+
import qualified System.FS.BlockIO.Internal.Fcntl as Unix
89
import qualified System.FS.BlockIO.IO.Internal as IOI
910
import qualified System.FS.BlockIO.Serial as Serial
1011
import System.FS.IO (HandleIO)
1112
import qualified System.FS.IO.Handle as FS
12-
import qualified System.Posix.Fcntl as Unix
1313
import qualified System.Posix.Files as Unix
1414
import qualified System.Posix.Unistd as Unix
1515

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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

0 commit comments

Comments
 (0)