module System.Linux.Mount
(
mount
, umount
, umountWith
, MountFlag(..)
, DriverData
, noData
, UmountFlag(..)
) where
import Data.ByteString (ByteString, useAsCString, empty)
import Foreign
import Foreign.C
mount :: String
-> FilePath
-> String
-> [MountFlag]
-> DriverData
-> IO ()
mount dev dir typ xs byt =
throwErrnoIfMinus1_ "mount" $
withCString dev $ \cdev ->
withCString dir $ \cdir ->
withCString typ $ \ctyp ->
useAsCString byt $ \cdat->
c_mount cdev
cdir
ctyp
(combineBitMasks xs)
(castPtr cdat)
foreign import ccall unsafe "mount"
c_mount :: Ptr CChar -> Ptr CChar -> Ptr CChar -> CULong -> Ptr a -> IO CInt
umount :: FilePath
-> IO ()
umount str = throwErrnoIfMinus1_ "umount" (withCString str c_umount)
foreign import ccall unsafe "umount"
c_umount :: Ptr CChar -> IO CInt
umountWith :: UmountFlag
-> Bool
-> FilePath
-> IO ()
umountWith flag b str =
throwErrnoIfMinus1_ "umountWith" $
withCString str $ \cstr ->
c_umount2 cstr (fromUmountFlag flag .|.
(if b then 0 else 8)
)
foreign import ccall unsafe "umount2"
c_umount2 :: Ptr CChar -> CInt -> IO CInt
data MountFlag = Rdonly
| Nosuid
| Nodev
| Noexec
| Synchronous
| Remount
| Mandlock
| Dirsync
| Noatime
| Nodiratime
| Bind
| Move
| Rec
| Silent
| Posixacl
| Unbindable
| Private
| Slave
| Shared
| Relatime
| Kernmount
| IVersion
| Strictatime
| Active
| Nouser
deriving (Eq, Read, Show)
fromMountFlag :: MountFlag -> CULong
fromMountFlag Rdonly = msRdonly
fromMountFlag Nosuid = msNosuid
fromMountFlag Nodev = msNodev
fromMountFlag Noexec = msNoexec
fromMountFlag Synchronous = msSynchronous
fromMountFlag Remount = msRemount
fromMountFlag Mandlock = msMandlock
fromMountFlag Dirsync = msDirsync
fromMountFlag Noatime = msNoatime
fromMountFlag Nodiratime = msNodiratime
fromMountFlag Bind = msBind
fromMountFlag Move = msMove
fromMountFlag Rec = msRec
fromMountFlag Silent = msSilent
fromMountFlag Posixacl = msPosixacl
fromMountFlag Unbindable = msUnbindable
fromMountFlag Private = msPrivate
fromMountFlag Slave = msSlave
fromMountFlag Shared = msShared
fromMountFlag Relatime = msRelatime
fromMountFlag Kernmount = msKernmount
fromMountFlag IVersion = msIVersion
fromMountFlag Strictatime = msStrictatime
fromMountFlag Active = msActive
fromMountFlag Nouser = msNouser
type DriverData = ByteString
noData :: DriverData
noData = empty
combineBitMasks :: [MountFlag] -> CULong
combineBitMasks = foldl (.|.) 0 . map fromMountFlag
data UmountFlag = Plain
| Force
| Detach
| Expire
deriving (Eq, Read, Show)
fromUmountFlag :: UmountFlag -> CInt
fromUmountFlag Plain = 0
fromUmountFlag Force = 1
fromUmountFlag Detach = 2
fromUmountFlag Expire = 4
msRdonly :: CULong
msRdonly = 1
msNosuid :: CULong
msNosuid = 2
msNodev :: CULong
msNodev = 4
msNoexec :: CULong
msNoexec = 8
msSynchronous :: CULong
msSynchronous = 16
msRemount :: CULong
msRemount = 32
msMandlock :: CULong
msMandlock = 64
msDirsync :: CULong
msDirsync = 128
msNoatime :: CULong
msNoatime = 1024
msNodiratime :: CULong
msNodiratime = 2048
msBind :: CULong
msBind = 4096
msMove :: CULong
msMove = 8192
msRec :: CULong
msRec = 16384
msSilent :: CULong
msSilent = 32768
msPosixacl :: CULong
msPosixacl = 65536
msUnbindable :: CULong
msUnbindable = 131072
msPrivate :: CULong
msPrivate = 262144
msSlave :: CULong
msSlave = 524288
msShared :: CULong
msShared = 1048576
msRelatime :: CULong
msRelatime = 2097152
msKernmount :: CULong
msKernmount = 4194304
msIVersion :: CULong
msIVersion = 8388608
msStrictatime :: CULong
msStrictatime = 16777216
msActive :: CULong
msActive = 1073741824
msNouser :: CULong
msNouser = (2147483648)