@@ -49,7 +49,8 @@ module System.Posix.Files.Common (
49
49
getFdStatus ,
50
50
-- ** Querying file status
51
51
deviceID , fileID , fileMode , linkCount , fileOwner , fileGroup ,
52
- specialDeviceID , fileSize , accessTime , modificationTime ,
52
+ specialDeviceID , fileSize , fileBlockSize ,
53
+ fileBlocks , accessTime , modificationTime ,
53
54
statusChangeTime ,
54
55
accessTimeHiRes , modificationTimeHiRes , statusChangeTimeHiRes ,
55
56
setFdTimesHiRes , touchFd ,
@@ -250,6 +251,10 @@ specialDeviceID :: FileStatus -> DeviceID
250
251
-- | Size of the file in bytes. If this file is a symbolic link the size is
251
252
-- the length of the pathname it contains.
252
253
fileSize :: 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
253
258
-- | Time of last access.
254
259
accessTime :: FileStatus -> EpochTime
255
260
-- | Time of last access in sub-second resolution.
@@ -286,6 +291,22 @@ modificationTime (FileStatus stat) =
286
291
statusChangeTime (FileStatus stat) =
287
292
unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_ctime)
288
293
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
+
289
310
accessTimeHiRes (FileStatus stat) =
290
311
unsafePerformIO $ withForeignPtr stat $ \ stat_ptr -> do
291
312
sec <- (# peek struct stat, st_atime) stat_ptr :: IO EpochTime
0 commit comments