@@ -56,6 +56,9 @@ module System.Posix.Files.Common (
5656 isBlockDevice , isCharacterDevice , isNamedPipe , isRegularFile ,
5757 isDirectory , isSymbolicLink , isSocket ,
5858
59+ fileBlockSize ,
60+ fileBlocks ,
61+
5962 -- * Setting file sizes
6063 setFdSize ,
6164
@@ -255,6 +258,14 @@ specialDeviceID :: FileStatus -> DeviceID
255258-- | Size of the file in bytes. If this file is a symbolic link the size is
256259-- the length of the pathname it contains.
257260fileSize :: FileStatus -> FileOffset
261+ -- | Number of blocks allocated for this file, in units of
262+ -- 512-bytes. Returns @Nothing@ if @st_blocks@ is not supported on this
263+ -- platform.
264+ fileBlocks :: FileStatus -> Maybe CBlkCnt
265+ -- | Gives the preferred block size for efficient filesystem I/O in
266+ -- bytes. Returns @Nothing@ if @st_blocksize@ is not supported on this
267+ -- platform.
268+ fileBlockSize :: FileStatus -> Maybe CBlkSize
258269-- | Time of last access.
259270accessTime :: FileStatus -> EpochTime
260271-- | Time of last access in sub-second resolution. Depends on the timestamp resolution of the
@@ -294,6 +305,19 @@ modificationTime (FileStatus stat) =
294305statusChangeTime (FileStatus stat) =
295306 unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_ctime)
296307
308+ #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
309+ fileBlocks (FileStatus stat) =
310+ Just $ unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_blocks)
311+ #else
312+ fileBlocks _ = Nothing
313+ #endif
314+ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
315+ fileBlockSize (FileStatus stat) =
316+ Just $ unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_blksize)
317+ #else
318+ fileBlockSize _ = Nothing
319+ #endif
320+
297321accessTimeHiRes (FileStatus stat) =
298322 unsafePerformIO $ withForeignPtr stat $ \ stat_ptr -> do
299323 sec <- (# peek struct stat, st_atime) stat_ptr :: IO EpochTime
0 commit comments