@@ -56,6 +56,11 @@ module System.Posix.Files.Common (
5656 isBlockDevice , isCharacterDevice , isNamedPipe , isRegularFile ,
5757 isDirectory , isSymbolicLink , isSocket ,
5858
59+ #if MIN_VERSION_base(4,10,0)
60+ fileBlockSize ,
61+ fileBlocks ,
62+ #endif
63+
5964 -- * Setting file sizes
6065 setFdSize ,
6166
@@ -255,6 +260,16 @@ specialDeviceID :: FileStatus -> DeviceID
255260-- | Size of the file in bytes. If this file is a symbolic link the size is
256261-- the length of the pathname it contains.
257262fileSize :: FileStatus -> FileOffset
263+ #if MIN_VERSION_base(4,10,0)
264+ -- | Number of blocks allocated for this file, in units of
265+ -- 512-bytes. Returns @Nothing@ if @st_blocks@ is not supported on this
266+ -- platform.
267+ fileBlocks :: FileStatus -> Maybe CBlkCnt
268+ -- | Gives the preferred block size for efficient filesystem I/O in
269+ -- bytes. Returns @Nothing@ if @st_blocksize@ is not supported on this
270+ -- platform.
271+ fileBlockSize :: FileStatus -> Maybe CBlkSize
272+ #endif
258273-- | Time of last access.
259274accessTime :: FileStatus -> EpochTime
260275-- | Time of last access in sub-second resolution. Depends on the timestamp resolution of the
@@ -294,6 +309,21 @@ modificationTime (FileStatus stat) =
294309statusChangeTime (FileStatus stat) =
295310 unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_ctime)
296311
312+ #if MIN_VERSION_base(4,10,0)
313+ #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
314+ fileBlocks (FileStatus stat) =
315+ Just $ unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_blocks)
316+ #else
317+ fileBlocks _ = Nothing
318+ #endif
319+ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
320+ fileBlockSize (FileStatus stat) =
321+ Just $ unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_blksize)
322+ #else
323+ fileBlockSize _ = Nothing
324+ #endif
325+ #endif
326+
297327accessTimeHiRes (FileStatus stat) =
298328 unsafePerformIO $ withForeignPtr stat $ \ stat_ptr -> do
299329 sec <- (# peek struct stat, st_atime) stat_ptr :: IO EpochTime
0 commit comments