{-# LINE 1 "System/Posix/Files/Common.hsc" #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE Trustworthy #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NumDecimals #-}
module System.Posix.Files.Common (
unionFileModes, intersectFileModes,
nullFileMode,
ownerReadMode, ownerWriteMode, ownerExecuteMode, ownerModes,
groupReadMode, groupWriteMode, groupExecuteMode, groupModes,
otherReadMode, otherWriteMode, otherExecuteMode, otherModes,
setUserIDMode, setGroupIDMode,
stdFileMode, accessModes,
fileTypeModes,
blockSpecialMode, characterSpecialMode, namedPipeMode, regularFileMode,
directoryMode, symbolicLinkMode, socketMode,
setFdMode, setFileCreationMask,
FileStatus(..),
getFdStatus,
deviceID, fileID, fileMode, linkCount, fileOwner, fileGroup,
specialDeviceID, fileSize, accessTime, modificationTime,
statusChangeTime,
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
setFdTimesHiRes, touchFd,
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,
isDirectory, isSymbolicLink, isSocket,
fileBlockSize,
fileBlocks,
StatxFlags(..),
pattern EmptyPath,
pattern NoAutoMount,
pattern SymlinkNoFollow,
pattern SyncAsStat,
pattern ForceSync,
pattern DontSync,
defaultStatxFlags,
StatxMask(..),
pattern StatxType,
pattern StatxMode,
pattern StatxNlink,
pattern StatxUid,
pattern StatxGid,
pattern StatxAtime,
pattern StatxMtime,
pattern StatxCtime,
pattern StatxBtime,
pattern StatxIno,
pattern StatxSize,
pattern StatxBlocks,
pattern StatxMntId,
pattern StatxBasicStats,
pattern StatxAll,
defaultStatxMask,
ExtendedFileStatus(..),
CAttributes(..),
getExtendedFileStatus_,
fileBlockSizeX,
linkCountX,
fileOwnerX,
fileGroupX,
fileModeX,
fileIDX,
fileSizeX,
fileBlocksX,
accessTimeHiResX,
creationTimeHiResX,
statusChangeTimeHiResX,
modificationTimeHiResX,
deviceIDX,
specialDeviceIDX,
mountIDX,
fileCompressedX,
fileImmutableX,
fileAppendX,
fileNoDumpX,
fileEncryptedX,
fileVerityX,
fileDaxX,
isBlockDeviceX,
isCharacterDeviceX,
isNamedPipeX,
isRegularFileX,
isDirectoryX,
isSymbolicLinkX,
isSocketX,
haveStatx,
setFdSize,
setFdOwnerAndGroup,
PathVar(..), getFdPathVar, pathVarConst,
{-# LINE 138 "System/Posix/Files/Common.hsc" #-}
CTimeSpec(..),
toCTimeSpec,
c_utimensat,
{-# LINE 142 "System/Posix/Files/Common.hsc" #-}
{-# LINE 147 "System/Posix/Files/Common.hsc" #-}
CTimeVal(..),
toCTimeVal,
c_utimes,
{-# LINE 151 "System/Posix/Files/Common.hsc" #-}
c_lutimes,
{-# LINE 153 "System/Posix/Files/Common.hsc" #-}
) where
import System.Posix.Types
import System.IO.Unsafe
import Data.Bits
import Data.Int
import Data.Ratio
import Data.Word
{-# LINE 162 "System/Posix/Files/Common.hsc" #-}
import Data.Time.Clock (secondsToNominalDiffTime)
import Data.Fixed (Fixed(..))
{-# LINE 165 "System/Posix/Files/Common.hsc" #-}
import Data.Time.Clock.POSIX (POSIXTime)
import System.Posix.Internals
import Foreign.C
import Foreign.ForeignPtr
{-# LINE 170 "System/Posix/Files/Common.hsc" #-}
import Foreign.Marshal (withArray)
{-# LINE 172 "System/Posix/Files/Common.hsc" #-}
import Foreign.Ptr
import Foreign.Storable
{-# LINE 179 "System/Posix/Files/Common.hsc" #-}
nullFileMode :: FileMode
nullFileMode = 0
ownerReadMode :: FileMode
ownerReadMode = (256)
{-# LINE 193 "System/Posix/Files/Common.hsc" #-}
ownerWriteMode :: FileMode
ownerWriteMode = (128)
{-# LINE 197 "System/Posix/Files/Common.hsc" #-}
ownerExecuteMode :: FileMode
ownerExecuteMode = (64)
{-# LINE 201 "System/Posix/Files/Common.hsc" #-}
groupReadMode :: FileMode
groupReadMode = (32)
{-# LINE 205 "System/Posix/Files/Common.hsc" #-}
groupWriteMode :: FileMode
groupWriteMode = (16)
{-# LINE 209 "System/Posix/Files/Common.hsc" #-}
groupExecuteMode :: FileMode
groupExecuteMode = (8)
{-# LINE 213 "System/Posix/Files/Common.hsc" #-}
otherReadMode :: FileMode
otherReadMode = (4)
{-# LINE 217 "System/Posix/Files/Common.hsc" #-}
otherWriteMode :: FileMode
otherWriteMode = (2)
{-# LINE 221 "System/Posix/Files/Common.hsc" #-}
otherExecuteMode :: FileMode
otherExecuteMode = (1)
{-# LINE 225 "System/Posix/Files/Common.hsc" #-}
setUserIDMode :: FileMode
setUserIDMode = (2048)
{-# LINE 229 "System/Posix/Files/Common.hsc" #-}
setGroupIDMode :: FileMode
setGroupIDMode = (1024)
{-# LINE 233 "System/Posix/Files/Common.hsc" #-}
stdFileMode :: FileMode
stdFileMode = ownerReadMode .|. ownerWriteMode .|.
groupReadMode .|. groupWriteMode .|.
otherReadMode .|. otherWriteMode
ownerModes :: FileMode
ownerModes = (448)
{-# LINE 243 "System/Posix/Files/Common.hsc" #-}
groupModes :: FileMode
groupModes = (56)
{-# LINE 247 "System/Posix/Files/Common.hsc" #-}
otherModes :: FileMode
otherModes = (7)
{-# LINE 251 "System/Posix/Files/Common.hsc" #-}
accessModes :: FileMode
accessModes = ownerModes .|. groupModes .|. otherModes
unionFileModes :: FileMode -> FileMode -> FileMode
unionFileModes m1 m2 = m1 .|. m2
intersectFileModes :: FileMode -> FileMode -> FileMode
intersectFileModes m1 m2 = m1 .&. m2
fileTypeModes :: FileMode
fileTypeModes = (61440)
{-# LINE 268 "System/Posix/Files/Common.hsc" #-}
blockSpecialMode :: FileMode
blockSpecialMode = (24576)
{-# LINE 271 "System/Posix/Files/Common.hsc" #-}
characterSpecialMode :: FileMode
characterSpecialMode = (8192)
{-# LINE 274 "System/Posix/Files/Common.hsc" #-}
namedPipeMode :: FileMode
namedPipeMode = (4096)
{-# LINE 277 "System/Posix/Files/Common.hsc" #-}
regularFileMode :: FileMode
regularFileMode = (32768)
{-# LINE 280 "System/Posix/Files/Common.hsc" #-}
directoryMode :: FileMode
directoryMode = (16384)
{-# LINE 283 "System/Posix/Files/Common.hsc" #-}
symbolicLinkMode :: FileMode
symbolicLinkMode = (40960)
{-# LINE 286 "System/Posix/Files/Common.hsc" #-}
socketMode :: FileMode
socketMode = (49152)
{-# LINE 289 "System/Posix/Files/Common.hsc" #-}
{-# LINE 291 "System/Posix/Files/Common.hsc" #-}
setFdMode :: Fd -> FileMode -> IO ()
setFdMode (Fd fd) m =
throwErrnoIfMinus1_ "setFdMode" (c_fchmod fd m)
foreign import ccall unsafe "fchmod"
c_fchmod :: CInt -> CMode -> IO CInt
{-# LINE 310 "System/Posix/Files/Common.hsc" #-}
setFileCreationMask :: FileMode -> IO FileMode
setFileCreationMask mask = c_umask mask
newtype FileStatus = FileStatus (ForeignPtr CStat)
deviceID :: FileStatus -> DeviceID
fileID :: FileStatus -> FileID
fileMode :: FileStatus -> FileMode
linkCount :: FileStatus -> LinkCount
fileOwner :: FileStatus -> UserID
fileGroup :: FileStatus -> GroupID
specialDeviceID :: FileStatus -> DeviceID
fileSize :: FileStatus -> FileOffset
fileBlocks :: FileStatus -> Maybe CBlkCnt
fileBlockSize :: FileStatus -> Maybe CBlkSize
accessTime :: FileStatus -> EpochTime
accessTimeHiRes :: FileStatus -> POSIXTime
modificationTime :: FileStatus -> EpochTime
modificationTimeHiRes :: FileStatus -> POSIXTime
statusChangeTime :: FileStatus -> EpochTime
statusChangeTimeHiRes :: FileStatus -> POSIXTime
deviceID (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 0))
{-# LINE 377 "System/Posix/Files/Common.hsc" #-}
fileID (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 8))
{-# LINE 379 "System/Posix/Files/Common.hsc" #-}
fileMode (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 24))
{-# LINE 381 "System/Posix/Files/Common.hsc" #-}
linkCount (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 16))
{-# LINE 383 "System/Posix/Files/Common.hsc" #-}
fileOwner (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 28))
{-# LINE 385 "System/Posix/Files/Common.hsc" #-}
fileGroup (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 32))
{-# LINE 387 "System/Posix/Files/Common.hsc" #-}
specialDeviceID (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 40))
{-# LINE 389 "System/Posix/Files/Common.hsc" #-}
fileSize (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 48))
{-# LINE 391 "System/Posix/Files/Common.hsc" #-}
accessTime (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 72))
{-# LINE 393 "System/Posix/Files/Common.hsc" #-}
modificationTime (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 88))
{-# LINE 395 "System/Posix/Files/Common.hsc" #-}
statusChangeTime (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 104))
{-# LINE 397 "System/Posix/Files/Common.hsc" #-}
{-# LINE 399 "System/Posix/Files/Common.hsc" #-}
fileBlocks (FileStatus stat) =
Just $ unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 64))
{-# LINE 401 "System/Posix/Files/Common.hsc" #-}
{-# LINE 404 "System/Posix/Files/Common.hsc" #-}
{-# LINE 405 "System/Posix/Files/Common.hsc" #-}
fileBlockSize (FileStatus stat) =
Just $ unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 56))
{-# LINE 407 "System/Posix/Files/Common.hsc" #-}
{-# LINE 410 "System/Posix/Files/Common.hsc" #-}
accessTimeHiRes (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 72)) stat_ptr :: IO EpochTime
{-# LINE 414 "System/Posix/Files/Common.hsc" #-}
{-# LINE 415 "System/Posix/Files/Common.hsc" #-}
nsec <- ((\hsc_ptr -> peekByteOff hsc_ptr 80)) stat_ptr :: IO (Int64)
{-# LINE 416 "System/Posix/Files/Common.hsc" #-}
let frac = toInteger nsec % 10^(9::Int)
{-# LINE 432 "System/Posix/Files/Common.hsc" #-}
return $ fromRational $ toRational sec + frac
modificationTimeHiRes (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 88)) stat_ptr :: IO EpochTime
{-# LINE 437 "System/Posix/Files/Common.hsc" #-}
{-# LINE 438 "System/Posix/Files/Common.hsc" #-}
nsec <- ((\hsc_ptr -> peekByteOff hsc_ptr 96)) stat_ptr :: IO (Int64)
{-# LINE 439 "System/Posix/Files/Common.hsc" #-}
let frac = toInteger nsec % 10^(9::Int)
{-# LINE 455 "System/Posix/Files/Common.hsc" #-}
return $ fromRational $ toRational sec + frac
statusChangeTimeHiRes (FileStatus stat) =
unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 104)) stat_ptr :: IO EpochTime
{-# LINE 460 "System/Posix/Files/Common.hsc" #-}
{-# LINE 461 "System/Posix/Files/Common.hsc" #-}
nsec <- ((\hsc_ptr -> peekByteOff hsc_ptr 112)) stat_ptr :: IO (Int64)
{-# LINE 462 "System/Posix/Files/Common.hsc" #-}
let frac = toInteger nsec % 10^(9::Int)
{-# LINE 478 "System/Posix/Files/Common.hsc" #-}
return $ fromRational $ toRational sec + frac
isBlockDevice :: FileStatus -> Bool
isCharacterDevice :: FileStatus -> Bool
isNamedPipe :: FileStatus -> Bool
isRegularFile :: FileStatus -> Bool
isDirectory :: FileStatus -> Bool
isSymbolicLink :: FileStatus -> Bool
isSocket :: FileStatus -> Bool
isBlockDevice stat =
(fileMode stat `intersectFileModes` fileTypeModes) == blockSpecialMode
isCharacterDevice stat =
(fileMode stat `intersectFileModes` fileTypeModes) == characterSpecialMode
isNamedPipe stat =
(fileMode stat `intersectFileModes` fileTypeModes) == namedPipeMode
isRegularFile stat =
(fileMode stat `intersectFileModes` fileTypeModes) == regularFileMode
isDirectory stat =
(fileMode stat `intersectFileModes` fileTypeModes) == directoryMode
isSymbolicLink stat =
(fileMode stat `intersectFileModes` fileTypeModes) == symbolicLinkMode
isSocket stat =
(fileMode stat `intersectFileModes` fileTypeModes) == socketMode
getFdStatus :: Fd -> IO FileStatus
getFdStatus (Fd fd) = do
fp <- mallocForeignPtrBytes (144)
{-# LINE 516 "System/Posix/Files/Common.hsc" #-}
withForeignPtr fp $ \p ->
throwErrnoIfMinus1_ "getFdStatus" (c_fstat fd p)
return (FileStatus fp)
{-# LINE 524 "System/Posix/Files/Common.hsc" #-}
data CTimeSpec = CTimeSpec EpochTime CLong
instance Storable CTimeSpec where
sizeOf _ = (16)
{-# LINE 528 "System/Posix/Files/Common.hsc" #-}
alignment _ = alignment (undefined :: CInt)
poke p (CTimeSpec sec nsec) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p sec
{-# LINE 531 "System/Posix/Files/Common.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p nsec
{-# LINE 532 "System/Posix/Files/Common.hsc" #-}
peek p = do
sec <- (\hsc_ptr -> peekByteOff hsc_ptr 0) p
{-# LINE 534 "System/Posix/Files/Common.hsc" #-}
nsec <- (\hsc_ptr -> peekByteOff hsc_ptr 8) p
{-# LINE 535 "System/Posix/Files/Common.hsc" #-}
return $ CTimeSpec sec nsec
toCTimeSpec :: POSIXTime -> CTimeSpec
toCTimeSpec t = CTimeSpec (CTime sec) (truncate $ 10^(9::Int) * frac)
where
(sec, frac) = if (frac' < 0) then (sec' - 1, frac' + 1) else (sec', frac')
(sec', frac') = properFraction $ toRational t
{-# LINE 543 "System/Posix/Files/Common.hsc" #-}
{-# LINE 545 "System/Posix/Files/Common.hsc" #-}
foreign import capi unsafe "sys/stat.h utimensat"
c_utimensat :: CInt -> CString -> Ptr CTimeSpec -> CInt -> IO CInt
{-# LINE 548 "System/Posix/Files/Common.hsc" #-}
{-# LINE 550 "System/Posix/Files/Common.hsc" #-}
foreign import capi unsafe "sys/stat.h futimens"
c_futimens :: CInt -> Ptr CTimeSpec -> IO CInt
{-# LINE 553 "System/Posix/Files/Common.hsc" #-}
data CTimeVal = CTimeVal CLong CLong
instance Storable CTimeVal where
sizeOf _ = (16)
{-# LINE 558 "System/Posix/Files/Common.hsc" #-}
alignment _ = alignment (undefined :: CInt)
poke p (CTimeVal sec usec) = do
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p sec
{-# LINE 561 "System/Posix/Files/Common.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p usec
{-# LINE 562 "System/Posix/Files/Common.hsc" #-}
peek p = do
sec <- (\hsc_ptr -> peekByteOff hsc_ptr 0) p
{-# LINE 564 "System/Posix/Files/Common.hsc" #-}
usec <- (\hsc_ptr -> peekByteOff hsc_ptr 8) p
{-# LINE 565 "System/Posix/Files/Common.hsc" #-}
return $ CTimeVal sec usec
toCTimeVal :: POSIXTime -> CTimeVal
toCTimeVal t = CTimeVal sec (truncate $ 10^(6::Int) * frac)
where
(sec, frac) = if (frac' < 0) then (sec' - 1, frac' + 1) else (sec', frac')
(sec', frac') = properFraction $ toRational t
foreign import capi unsafe "sys/time.h utimes"
c_utimes :: CString -> Ptr CTimeVal -> IO CInt
{-# LINE 577 "System/Posix/Files/Common.hsc" #-}
foreign import capi unsafe "sys/time.h lutimes"
c_lutimes :: CString -> Ptr CTimeVal -> IO CInt
{-# LINE 580 "System/Posix/Files/Common.hsc" #-}
{-# LINE 582 "System/Posix/Files/Common.hsc" #-}
foreign import capi unsafe "sys/time.h futimes"
c_futimes :: CInt -> Ptr CTimeVal -> IO CInt
{-# LINE 585 "System/Posix/Files/Common.hsc" #-}
{-# LINE 594 "System/Posix/Files/Common.hsc" #-}
setFdTimesHiRes :: Fd -> POSIXTime -> POSIXTime -> IO ()
{-# LINE 611 "System/Posix/Files/Common.hsc" #-}
setFdTimesHiRes (Fd fd) atime mtime =
withArray [toCTimeSpec atime, toCTimeSpec mtime] $ \times ->
throwErrnoIfMinus1_ "setFdTimesHiRes" (c_futimens fd times)
{-# LINE 623 "System/Posix/Files/Common.hsc" #-}
touchFd :: Fd -> IO ()
{-# LINE 637 "System/Posix/Files/Common.hsc" #-}
touchFd (Fd fd) =
throwErrnoIfMinus1_ "touchFd" (c_futimes fd nullPtr)
{-# LINE 644 "System/Posix/Files/Common.hsc" #-}
{-# LINE 649 "System/Posix/Files/Common.hsc" #-}
setFdOwnerAndGroup :: Fd -> UserID -> GroupID -> IO ()
setFdOwnerAndGroup (Fd fd) uid gid =
throwErrnoIfMinus1_ "setFdOwnerAndGroup" (c_fchown fd uid gid)
foreign import ccall unsafe "fchown"
c_fchown :: CInt -> CUid -> CGid -> IO CInt
{-# LINE 668 "System/Posix/Files/Common.hsc" #-}
setFdSize :: Fd -> FileOffset -> IO ()
setFdSize (Fd fd) off =
throwErrnoIfMinus1_ "setFdSize" (c_ftruncate fd off)
data PathVar
= FileSizeBits
| LinkLimit
| InputLineLimit
| InputQueueLimit
| FileNameLimit
| PathNameLimit
| PipeBufferLimit
| SymbolicLinkLimit
| SetOwnerAndGroupIsRestricted
| FileNamesAreNotTruncated
| VDisableChar
| AsyncIOAvailable
| PrioIOAvailable
| SyncIOAvailable
pathVarConst :: PathVar -> CInt
pathVarConst v = case v of
LinkLimit -> (0)
{-# LINE 707 "System/Posix/Files/Common.hsc" #-}
InputLineLimit -> (1)
{-# LINE 708 "System/Posix/Files/Common.hsc" #-}
InputQueueLimit -> (2)
{-# LINE 709 "System/Posix/Files/Common.hsc" #-}
FileNameLimit -> (3)
{-# LINE 710 "System/Posix/Files/Common.hsc" #-}
PathNameLimit -> (4)
{-# LINE 711 "System/Posix/Files/Common.hsc" #-}
PipeBufferLimit -> (5)
{-# LINE 712 "System/Posix/Files/Common.hsc" #-}
SetOwnerAndGroupIsRestricted -> (6)
{-# LINE 713 "System/Posix/Files/Common.hsc" #-}
FileNamesAreNotTruncated -> (7)
{-# LINE 714 "System/Posix/Files/Common.hsc" #-}
VDisableChar -> (8)
{-# LINE 715 "System/Posix/Files/Common.hsc" #-}
{-# LINE 717 "System/Posix/Files/Common.hsc" #-}
SyncIOAvailable -> (9)
{-# LINE 718 "System/Posix/Files/Common.hsc" #-}
{-# LINE 721 "System/Posix/Files/Common.hsc" #-}
{-# LINE 723 "System/Posix/Files/Common.hsc" #-}
AsyncIOAvailable -> (10)
{-# LINE 724 "System/Posix/Files/Common.hsc" #-}
{-# LINE 727 "System/Posix/Files/Common.hsc" #-}
{-# LINE 729 "System/Posix/Files/Common.hsc" #-}
PrioIOAvailable -> (11)
{-# LINE 730 "System/Posix/Files/Common.hsc" #-}
{-# LINE 733 "System/Posix/Files/Common.hsc" #-}
{-# LINE 737 "System/Posix/Files/Common.hsc" #-}
FileSizeBits -> error "_PC_FILESIZEBITS not available"
{-# LINE 739 "System/Posix/Files/Common.hsc" #-}
{-# LINE 743 "System/Posix/Files/Common.hsc" #-}
SymbolicLinkLimit -> error "_PC_SYMLINK_MAX not available"
{-# LINE 745 "System/Posix/Files/Common.hsc" #-}
getFdPathVar :: Fd -> PathVar -> IO Limit
getFdPathVar (Fd fd) v =
throwErrnoIfMinus1 "getFdPathVar" $
c_fpathconf fd (pathVarConst v)
foreign import ccall unsafe "fpathconf"
c_fpathconf :: CInt -> CInt -> IO CLong
newtype {-# CTYPE "__u64" #-} CAttributes = CAttributes Word64
deriving (Read, Show, Eq, Ord, Storable, Num, Bits)
newtype StatxFlags = StatxFlags CInt deriving (Read, Show, Eq, Ord, Integral, Num, Enum, Bits, Real)
instance Semigroup StatxFlags where
a <> b = a .|. b
instance Monoid StatxFlags where
mappend = (<>)
mempty = 0
pattern EmptyPath :: StatxFlags
{-# LINE 801 "System/Posix/Files/Common.hsc" #-}
pattern EmptyPath = StatxFlags (4096)
{-# LINE 802 "System/Posix/Files/Common.hsc" #-}
{-# LINE 805 "System/Posix/Files/Common.hsc" #-}
pattern NoAutoMount :: StatxFlags
{-# LINE 812 "System/Posix/Files/Common.hsc" #-}
pattern NoAutoMount = StatxFlags (2048)
{-# LINE 813 "System/Posix/Files/Common.hsc" #-}
{-# LINE 816 "System/Posix/Files/Common.hsc" #-}
pattern SymlinkNoFollow :: StatxFlags
{-# LINE 820 "System/Posix/Files/Common.hsc" #-}
pattern SymlinkNoFollow = StatxFlags (256)
{-# LINE 821 "System/Posix/Files/Common.hsc" #-}
{-# LINE 824 "System/Posix/Files/Common.hsc" #-}
pattern SyncAsStat :: StatxFlags
{-# LINE 828 "System/Posix/Files/Common.hsc" #-}
pattern SyncAsStat = StatxFlags (0)
{-# LINE 829 "System/Posix/Files/Common.hsc" #-}
{-# LINE 832 "System/Posix/Files/Common.hsc" #-}
pattern ForceSync :: StatxFlags
{-# LINE 837 "System/Posix/Files/Common.hsc" #-}
pattern ForceSync = StatxFlags (8192)
{-# LINE 838 "System/Posix/Files/Common.hsc" #-}
{-# LINE 841 "System/Posix/Files/Common.hsc" #-}
pattern DontSync :: StatxFlags
{-# LINE 847 "System/Posix/Files/Common.hsc" #-}
pattern DontSync = StatxFlags (16384)
{-# LINE 848 "System/Posix/Files/Common.hsc" #-}
{-# LINE 851 "System/Posix/Files/Common.hsc" #-}
defaultStatxFlags :: StatxFlags
defaultStatxFlags = mempty
newtype StatxMask = StatxMask CInt deriving (Read, Show, Eq, Ord, Integral, Num, Enum, Bits, Real)
instance Semigroup StatxMask where
a <> b = a .|. b
instance Monoid StatxMask where
mappend = (<>)
mempty = 0
pattern StatxType :: StatxMask
{-# LINE 872 "System/Posix/Files/Common.hsc" #-}
pattern StatxType = StatxMask (1)
{-# LINE 873 "System/Posix/Files/Common.hsc" #-}
{-# LINE 876 "System/Posix/Files/Common.hsc" #-}
pattern StatxMode :: StatxMask
{-# LINE 880 "System/Posix/Files/Common.hsc" #-}
pattern StatxMode = StatxMask (2)
{-# LINE 881 "System/Posix/Files/Common.hsc" #-}
{-# LINE 884 "System/Posix/Files/Common.hsc" #-}
pattern StatxNlink :: StatxMask
{-# LINE 888 "System/Posix/Files/Common.hsc" #-}
pattern StatxNlink = StatxMask (4)
{-# LINE 889 "System/Posix/Files/Common.hsc" #-}
{-# LINE 892 "System/Posix/Files/Common.hsc" #-}
pattern StatxUid :: StatxMask
{-# LINE 896 "System/Posix/Files/Common.hsc" #-}
pattern StatxUid = StatxMask (8)
{-# LINE 897 "System/Posix/Files/Common.hsc" #-}
{-# LINE 900 "System/Posix/Files/Common.hsc" #-}
pattern StatxGid :: StatxMask
{-# LINE 904 "System/Posix/Files/Common.hsc" #-}
pattern StatxGid = StatxMask (16)
{-# LINE 905 "System/Posix/Files/Common.hsc" #-}
{-# LINE 908 "System/Posix/Files/Common.hsc" #-}
pattern StatxAtime :: StatxMask
{-# LINE 912 "System/Posix/Files/Common.hsc" #-}
pattern StatxAtime = StatxMask (32)
{-# LINE 913 "System/Posix/Files/Common.hsc" #-}
{-# LINE 916 "System/Posix/Files/Common.hsc" #-}
pattern StatxMtime :: StatxMask
{-# LINE 920 "System/Posix/Files/Common.hsc" #-}
pattern StatxMtime = StatxMask (64)
{-# LINE 921 "System/Posix/Files/Common.hsc" #-}
{-# LINE 924 "System/Posix/Files/Common.hsc" #-}
pattern StatxCtime :: StatxMask
{-# LINE 928 "System/Posix/Files/Common.hsc" #-}
pattern StatxCtime = StatxMask (128)
{-# LINE 929 "System/Posix/Files/Common.hsc" #-}
{-# LINE 932 "System/Posix/Files/Common.hsc" #-}
pattern StatxBtime :: StatxMask
{-# LINE 936 "System/Posix/Files/Common.hsc" #-}
pattern StatxBtime = StatxMask (2048)
{-# LINE 937 "System/Posix/Files/Common.hsc" #-}
{-# LINE 940 "System/Posix/Files/Common.hsc" #-}
pattern StatxMntId :: StatxMask
{-# LINE 944 "System/Posix/Files/Common.hsc" #-}
pattern StatxMntId = StatxMask (4096)
{-# LINE 945 "System/Posix/Files/Common.hsc" #-}
{-# LINE 948 "System/Posix/Files/Common.hsc" #-}
pattern StatxIno :: StatxMask
{-# LINE 952 "System/Posix/Files/Common.hsc" #-}
pattern StatxIno = StatxMask (256)
{-# LINE 953 "System/Posix/Files/Common.hsc" #-}
{-# LINE 956 "System/Posix/Files/Common.hsc" #-}
pattern StatxSize :: StatxMask
{-# LINE 960 "System/Posix/Files/Common.hsc" #-}
pattern StatxSize = StatxMask (512)
{-# LINE 961 "System/Posix/Files/Common.hsc" #-}
{-# LINE 964 "System/Posix/Files/Common.hsc" #-}
pattern StatxBlocks :: StatxMask
{-# LINE 968 "System/Posix/Files/Common.hsc" #-}
pattern StatxBlocks = StatxMask (1024)
{-# LINE 969 "System/Posix/Files/Common.hsc" #-}
{-# LINE 972 "System/Posix/Files/Common.hsc" #-}
pattern StatxBasicStats :: StatxMask
{-# LINE 976 "System/Posix/Files/Common.hsc" #-}
pattern StatxBasicStats = StatxMask (2047)
{-# LINE 977 "System/Posix/Files/Common.hsc" #-}
{-# LINE 980 "System/Posix/Files/Common.hsc" #-}
pattern StatxAll :: StatxMask
{-# LINE 984 "System/Posix/Files/Common.hsc" #-}
pattern StatxAll = StatxMask (4095)
{-# LINE 985 "System/Posix/Files/Common.hsc" #-}
{-# LINE 988 "System/Posix/Files/Common.hsc" #-}
defaultStatxMask :: StatxMask
defaultStatxMask = mempty
newtype ExtendedFileStatus = ExtendedFileStatus (ForeignPtr CStatx)
fileBlockSizeX :: ExtendedFileStatus -> CBlkSize
{-# LINE 999 "System/Posix/Files/Common.hsc" #-}
fileAttributesX :: ExtendedFileStatus -> CAttributes
{-# LINE 1002 "System/Posix/Files/Common.hsc" #-}
linkCountX :: ExtendedFileStatus -> CNlink
fileOwnerX :: ExtendedFileStatus -> UserID
fileGroupX :: ExtendedFileStatus -> GroupID
fileModeX :: ExtendedFileStatus -> FileMode
fileIDX :: ExtendedFileStatus -> FileID
fileSizeX :: ExtendedFileStatus -> Word64
fileBlocksX :: ExtendedFileStatus -> Word64
{-# LINE 1020 "System/Posix/Files/Common.hsc" #-}
fileAttributesMaskX :: ExtendedFileStatus -> CAttributes
{-# LINE 1023 "System/Posix/Files/Common.hsc" #-}
accessTimeHiResX :: ExtendedFileStatus -> POSIXTime
creationTimeHiResX :: ExtendedFileStatus -> POSIXTime
statusChangeTimeHiResX :: ExtendedFileStatus -> POSIXTime
modificationTimeHiResX :: ExtendedFileStatus -> POSIXTime
deviceIDX :: ExtendedFileStatus -> DeviceID
specialDeviceIDX :: ExtendedFileStatus -> DeviceID
mountIDX :: ExtendedFileStatus -> Word64
fileCompressedX :: ExtendedFileStatus -> Bool
fileImmutableX :: ExtendedFileStatus -> Bool
fileAppendX :: ExtendedFileStatus -> Bool
fileNoDumpX :: ExtendedFileStatus -> Bool
fileEncryptedX :: ExtendedFileStatus -> Bool
fileVerityX :: ExtendedFileStatus -> Bool
fileDaxX :: ExtendedFileStatus -> Bool
isBlockDeviceX :: ExtendedFileStatus -> Bool
isCharacterDeviceX :: ExtendedFileStatus -> Bool
isNamedPipeX :: ExtendedFileStatus -> Bool
isRegularFileX :: ExtendedFileStatus -> Bool
isDirectoryX :: ExtendedFileStatus -> Bool
isSymbolicLinkX :: ExtendedFileStatus -> Bool
isSocketX :: ExtendedFileStatus -> Bool
isBlockDeviceX statx =
(fileModeX statx `intersectFileModes` fileTypeModes) == blockSpecialMode
isCharacterDeviceX statx =
(fileModeX statx `intersectFileModes` fileTypeModes) == characterSpecialMode
isNamedPipeX statx =
(fileModeX statx `intersectFileModes` fileTypeModes) == namedPipeMode
isRegularFileX statx =
(fileModeX statx `intersectFileModes` fileTypeModes) == regularFileMode
isDirectoryX statx =
(fileModeX statx `intersectFileModes` fileTypeModes) == directoryMode
isSymbolicLinkX statx =
(fileModeX statx `intersectFileModes` fileTypeModes) == symbolicLinkMode
isSocketX statx =
(fileModeX statx `intersectFileModes` fileTypeModes) == socketMode
{-# LINE 1096 "System/Posix/Files/Common.hsc" #-}
testFlag :: ExtendedFileStatus -> CAttributes -> Bool
testFlag ex flag =
let attributes = fileAttributesX ex
attributes_mask = fileAttributesMaskX ex
in (attributes .&. attributes_mask .&. flag) /= 0
{-# LINE 1103 "System/Posix/Files/Common.hsc" #-}
fileCompressedX ex = testFlag ex (4)
{-# LINE 1104 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1108 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1109 "System/Posix/Files/Common.hsc" #-}
fileImmutableX ex = testFlag ex (16)
{-# LINE 1110 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1114 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1115 "System/Posix/Files/Common.hsc" #-}
fileAppendX ex = testFlag ex (32)
{-# LINE 1116 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1120 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1121 "System/Posix/Files/Common.hsc" #-}
fileNoDumpX ex = testFlag ex (64)
{-# LINE 1122 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1126 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1127 "System/Posix/Files/Common.hsc" #-}
fileEncryptedX ex = testFlag ex (2048)
{-# LINE 1128 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1132 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1133 "System/Posix/Files/Common.hsc" #-}
fileVerityX ex = testFlag ex (1048576)
{-# LINE 1134 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1138 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1139 "System/Posix/Files/Common.hsc" #-}
fileDaxX ex = testFlag ex (2097152)
{-# LINE 1140 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1144 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1146 "System/Posix/Files/Common.hsc" #-}
deviceIDX (ExtendedFileStatus statx) = unsafePerformIO $ do
major <- withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 136)) :: IO CUInt
{-# LINE 1148 "System/Posix/Files/Common.hsc" #-}
minor <- withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 140)) :: IO CUInt
{-# LINE 1149 "System/Posix/Files/Common.hsc" #-}
c_makedev major minor
{-# LINE 1154 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1155 "System/Posix/Files/Common.hsc" #-}
specialDeviceIDX (ExtendedFileStatus statx) = unsafePerformIO $ do
major <- withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 128)) :: IO CUInt
{-# LINE 1157 "System/Posix/Files/Common.hsc" #-}
minor <- withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 132)) :: IO CUInt
{-# LINE 1158 "System/Posix/Files/Common.hsc" #-}
c_makedev major minor
{-# LINE 1163 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1164 "System/Posix/Files/Common.hsc" #-}
mountIDX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 144))
{-# LINE 1166 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1170 "System/Posix/Files/Common.hsc" #-}
fileBlockSizeX (ExtendedFileStatus statx) = unsafePerformIO $ do
r <- withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 4)) :: IO Word32
{-# LINE 1172 "System/Posix/Files/Common.hsc" #-}
return $ CBlkSize (fromIntegral r)
fileAttributesX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 8))
{-# LINE 1175 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1176 "System/Posix/Files/Common.hsc" #-}
linkCountX (ExtendedFileStatus statx) = unsafePerformIO $ do
links <- withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 16)) :: IO Word32
{-# LINE 1178 "System/Posix/Files/Common.hsc" #-}
return $ CNlink (fromIntegral links)
{-# LINE 1183 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1184 "System/Posix/Files/Common.hsc" #-}
fileOwnerX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 20))
{-# LINE 1186 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1190 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1191 "System/Posix/Files/Common.hsc" #-}
fileGroupX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 24))
{-# LINE 1193 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1197 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1198 "System/Posix/Files/Common.hsc" #-}
fileModeX (ExtendedFileStatus statx) = unsafePerformIO $ do
r <- withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 28)) :: IO Word16
{-# LINE 1200 "System/Posix/Files/Common.hsc" #-}
return $ CMode $ fromIntegral r
{-# LINE 1205 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1206 "System/Posix/Files/Common.hsc" #-}
fileIDX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 32))
{-# LINE 1208 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1212 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1213 "System/Posix/Files/Common.hsc" #-}
fileSizeX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 40)) :: Word64
{-# LINE 1215 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1219 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1220 "System/Posix/Files/Common.hsc" #-}
fileBlocksX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 48)) :: Word64
{-# LINE 1222 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1226 "System/Posix/Files/Common.hsc" #-}
fileAttributesMaskX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ ((\hsc_ptr -> peekByteOff hsc_ptr 56))
{-# LINE 1228 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1229 "System/Posix/Files/Common.hsc" #-}
accessTimeHiResX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ \statx_ptr -> do
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 64)) statx_ptr :: IO EpochTime
{-# LINE 1232 "System/Posix/Files/Common.hsc" #-}
nsec <- ((\hsc_ptr -> peekByteOff hsc_ptr 72)) statx_ptr :: IO (Int32)
{-# LINE 1233 "System/Posix/Files/Common.hsc" #-}
return $ timeHiResToNominalDiffTime sec nsec
{-# LINE 1238 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1239 "System/Posix/Files/Common.hsc" #-}
creationTimeHiResX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ \statx_ptr -> do
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 80)) statx_ptr :: IO EpochTime
{-# LINE 1242 "System/Posix/Files/Common.hsc" #-}
nsec <- ((\hsc_ptr -> peekByteOff hsc_ptr 88)) statx_ptr :: IO (Int32)
{-# LINE 1243 "System/Posix/Files/Common.hsc" #-}
return $ timeHiResToNominalDiffTime sec nsec
{-# LINE 1248 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1249 "System/Posix/Files/Common.hsc" #-}
statusChangeTimeHiResX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ \statx_ptr -> do
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 96)) statx_ptr :: IO EpochTime
{-# LINE 1252 "System/Posix/Files/Common.hsc" #-}
nsec <- ((\hsc_ptr -> peekByteOff hsc_ptr 104)) statx_ptr :: IO (Int32)
{-# LINE 1253 "System/Posix/Files/Common.hsc" #-}
return $ timeHiResToNominalDiffTime sec nsec
{-# LINE 1258 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1259 "System/Posix/Files/Common.hsc" #-}
modificationTimeHiResX (ExtendedFileStatus statx) =
unsafePerformIO $ withForeignPtr statx $ \statx_ptr -> do
sec <- ((\hsc_ptr -> peekByteOff hsc_ptr 112)) statx_ptr :: IO EpochTime
{-# LINE 1262 "System/Posix/Files/Common.hsc" #-}
nsec <- ((\hsc_ptr -> peekByteOff hsc_ptr 120)) statx_ptr :: IO (Int32)
{-# LINE 1263 "System/Posix/Files/Common.hsc" #-}
return $ timeHiResToNominalDiffTime sec nsec
{-# LINE 1268 "System/Posix/Files/Common.hsc" #-}
timeHiResToNominalDiffTime :: EpochTime -> Int32 -> POSIXTime
timeHiResToNominalDiffTime (CTime sec) nsec = secondsToNominalDiffTime $ MkFixed $ toInteger sec * 1e12 + toInteger nsec * 1e3
{-# LINE 1318 "System/Posix/Files/Common.hsc" #-}
data {-# CTYPE "struct statx" #-} CStatx
{-# LINE 1322 "System/Posix/Files/Common.hsc" #-}
foreign import capi unsafe "sys/stat.h statx"
c_statx :: CInt -> CFilePath -> CInt -> CInt -> Ptr CStatx -> IO CInt
{-# LINE 1326 "System/Posix/Files/Common.hsc" #-}
foreign import capi unsafe "sys/sysmacros.h makedev"
c_makedev :: CUInt -> CUInt -> IO CDev
{-# LINE 1329 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1330 "System/Posix/Files/Common.hsc" #-}
getExtendedFileStatus_ :: Maybe Fd
-> CString
-> StatxFlags
-> StatxMask
-> IO ExtendedFileStatus
{-# LINE 1338 "System/Posix/Files/Common.hsc" #-}
getExtendedFileStatus_ fdMay str (StatxFlags flags) (StatxMask masks) = do
fp <- mallocForeignPtrBytes (256)
{-# LINE 1340 "System/Posix/Files/Common.hsc" #-}
withForeignPtr fp $ \p ->
throwErrnoIfMinus1_ "getExtendedFileStatus_" (c_statx c_fd str flags masks p)
return (ExtendedFileStatus fp)
where
c_fd = maybe (-100) (\ (Fd fd) -> fd) fdMay
{-# LINE 1345 "System/Posix/Files/Common.hsc" #-}
{-# LINE 1349 "System/Posix/Files/Common.hsc" #-}
haveStatx :: Bool
{-# LINE 1354 "System/Posix/Files/Common.hsc" #-}
haveStatx = True
{-# LINE 1358 "System/Posix/Files/Common.hsc" #-}