@@ -49,7 +49,8 @@ module System.Posix.Files.Common (
4949 getFdStatus ,
5050 -- ** Querying file status
5151 deviceID , fileID , fileMode , linkCount , fileOwner , fileGroup ,
52- specialDeviceID , fileSize , accessTime , modificationTime ,
52+ specialDeviceID , fileSize , fileBlockSize ,
53+ fileBlocks , accessTime , modificationTime ,
5354 statusChangeTime ,
5455 accessTimeHiRes , modificationTimeHiRes , statusChangeTimeHiRes ,
5556 setFdTimesHiRes , touchFd ,
@@ -250,6 +251,10 @@ specialDeviceID :: FileStatus -> DeviceID
250251-- | Size of the file in bytes. If this file is a symbolic link the size is
251252-- the length of the pathname it contains.
252253fileSize :: FileStatus -> FileOffset
254+ -- | Number of block blocks allocated for this file, in units of 512-byte.
255+ fileBlocks :: FileStatus -> Maybe CBlkCnt
256+ -- | Gives the preferred block size for efficient filesystem I/O in bytes.
257+ fileBlockSize :: FileStatus -> Maybe CBlkSize
253258-- | Time of last access.
254259accessTime :: FileStatus -> EpochTime
255260-- | Time of last access in sub-second resolution.
@@ -286,6 +291,22 @@ modificationTime (FileStatus stat) =
286291statusChangeTime (FileStatus stat) =
287292 unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_ctime)
288293
294+ #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
295+ fileBlocks (FileStatus stat) =
296+ Just $ unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_blocks)
297+ #else
298+ {-# WARNING fileBlockSize "fileBlockSize: not available on this platform" #-}
299+ fileBlocks _ = Nothing
300+ #endif
301+
302+ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
303+ fileBlockSize (FileStatus stat) =
304+ Just $ unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_blksize)
305+ #else
306+ {-# WARNING fileBlockSize "fileBlockSize: not available on this platform" #-}
307+ fileBlockSize _ = Nothing
308+ #endif
309+
289310accessTimeHiRes (FileStatus stat) =
290311 unsafePerformIO $ withForeignPtr stat $ \ stat_ptr -> do
291312 sec <- (# peek struct stat, st_atime) stat_ptr :: IO EpochTime
0 commit comments