@@ -49,7 +49,11 @@ 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 ,
53
+ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
54
+ fileBlockSize ,
55
+ #endif
56
+ fileBlocks , accessTime , modificationTime ,
53
57
statusChangeTime ,
54
58
accessTimeHiRes , modificationTimeHiRes , statusChangeTimeHiRes ,
55
59
setFdTimesHiRes , touchFd ,
@@ -250,6 +254,8 @@ specialDeviceID :: FileStatus -> DeviceID
250
254
-- | Size of the file in bytes. If this file is a symbolic link the size is
251
255
-- the length of the pathname it contains.
252
256
fileSize :: FileStatus -> FileOffset
257
+ -- | Number of block blocks allocated for this file, in units of 512-byte.
258
+ fileBlocks :: FileStatus -> CBlkCnt
253
259
-- | Time of last access.
254
260
accessTime :: FileStatus -> EpochTime
255
261
-- | Time of last access in sub-second resolution.
@@ -279,13 +285,22 @@ specialDeviceID (FileStatus stat) =
279
285
unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_rdev)
280
286
fileSize (FileStatus stat) =
281
287
unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_size)
288
+ fileBlocks (FileStatus stat) =
289
+ unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_blocks)
282
290
accessTime (FileStatus stat) =
283
291
unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_atime)
284
292
modificationTime (FileStatus stat) =
285
293
unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_mtime)
286
294
statusChangeTime (FileStatus stat) =
287
295
unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_ctime)
288
296
297
+ #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
298
+ -- | Gives the preferred block size for efficient filesystem I/O in bytes.
299
+ fileBlockSize :: FileStatus -> CBlkSize
300
+ fileBlockSize (FileStatus stat) =
301
+ unsafePerformIO $ withForeignPtr stat $ (# peek struct stat, st_blksize)
302
+ #endif
303
+
289
304
accessTimeHiRes (FileStatus stat) =
290
305
unsafePerformIO $ withForeignPtr stat $ \ stat_ptr -> do
291
306
sec <- (# peek struct stat, st_atime) stat_ptr :: IO EpochTime
0 commit comments