{- |This module provides an interface to the system mount and umount functions. -} module System.Linux.Mount ( -- * Bindings to system functions mount , umount , umountWith , forceUmount -- *MountFlag , MountFlag -- **Constructors , mntRdonly , mntNosuid , mntNodev , mntNoexec , mntSynchronous , mntRemount , mntMandlock , mntDirsync , mntNoatime , mntNodiratime , mntBind , mntMove , mntRec , mntSilent , mntPosixacl , mntUnbindable , mntPrivate , mntSlave , mntShared , mntRelatime , mntKernmount , mntIVersion , mntStrictatime , mntActive , mntNouser -- * DriverData , DriverData -- **Constructors , noData -- *UmountFlag , UmountFlag -- **Constructors , umntForce , umntDetach , umntExpire , umntNofollow ) where #include import Data.Bits import Foreign import Foreign.C import Foreign.Marshal.Alloc -- | Mounts a filesystem. mount :: String -- ^ device file -> FilePath -- ^ mount point -> String -- ^ filesystem type -> [MountFlag] -- ^ list of mount options -> DriverData -- ^ driver specific options -> IO () mount dev dir typ xs (DriverData ptr) = throwErrnoIfMinus1_ "mount" $ do cdev <- newCString dev cdir <- newCString dir ctype <- newCString typ ret <- c_mount cdev cdir ctype (genMountFlag xs) ptr free cdev free cdir free ctype return ret foreign import ccall unsafe "mount" c_mount :: Ptr CChar -> Ptr CChar -> Ptr CChar -> CULong -> Ptr a -> IO CInt -- | Umounts a filesystem. umount :: String -- ^ mount point -> IO () umount str = throwErrnoIfMinus1_ "umount" (withCString str (\cstr -> (c_umount cstr))) foreign import ccall unsafe "umount" c_umount :: Ptr CChar -> IO CInt -- | Umounts a filesystem using specific umount options. umountWith :: UmountFlag -- ^ umount options -> String -- ^ mount point -> IO () umountWith flag str = genUmount2 flag str "umountWith" -- |Forces the filesystem umount (@forceUmount str = 'umountWith' 'umntForce' str@). forceUmount :: String -- ^ mount point -> IO () forceUmount str = genUmount2 umntForce str "forceUmount" genUmount2 (UmountFlag flag) str errmsg = throwErrnoIfMinus1_ errmsg (withCString str (\cstr -> c_umount2 cstr flag)) foreign import ccall unsafe "umount2" c_umount2 :: Ptr CChar -> CInt -> IO CInt -- |MountFlag specifies the filesystem independent options to be used -- when mounting a filesystem newtype MountFlag = MountFlag CULong mntNoflag = MountFlag 0 -- |DriverData specifies the filesystem dependent options to be used -- when mounting a filesystem; the content of DriverData is passed -- directly to the filesystem driver. newtype DriverData = DriverData (Ptr ()) noData :: DriverData noData = DriverData nullPtr combine (MountFlag a) (MountFlag b) = MountFlag (a .|. b) getInt (MountFlag a) = a genMountFlag flags = getInt $ foldl combine (MountFlag 0) flags -- |UmountFlag specifies the filesystem independent options to be used -- when umounting a filesystem newtype UmountFlag = UmountFlag CInt #enum UmountFlag, UmountFlag, umntForce=MNT_FORCE, umntDetach=MNT_DETACH, umntExpire=MNT_EXPIRE, umntNofollow=UMOUNT_NOFOLLOW #enum MountFlag, MountFlag, mntRdonly=MS_RDONLY, mntNosuid=MS_NOSUID, mntNodev=MS_NODEV, mntNoexec=MS_NOEXEC, mntSynchronous=MS_SYNCHRONOUS, mntRemount=MS_REMOUNT, mntMandlock=MS_MANDLOCK, mntDirsync=MS_DIRSYNC, mntNoatime=MS_NOATIME, mntNodiratime=MS_NODIRATIME, mntBind=MS_BIND, mntMove=MS_MOVE, mntRec=MS_REC, mntSilent=MS_SILENT, mntPosixacl=MS_POSIXACL, mntUnbindable=MS_UNBINDABLE, mntPrivate=MS_PRIVATE, mntSlave=MS_SLAVE, mntShared=MS_SHARED, mntRelatime=MS_RELATIME, mntKernmount=MS_KERNMOUNT, mntIVersion=MS_I_VERSION, mntStrictatime=MS_STRICTATIME, mntActive=MS_ACTIVE, mntNouser=MS_NOUSER