Skip to content

Commit f2f5c65

Browse files
committed
Add accessors for st_blocks and st_blksize
1 parent ee3e99a commit f2f5c65

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

System/Posix/Files.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ module System.Posix.Files (
5757
getFileStatus, getFdStatus, getSymbolicLinkStatus,
5858
-- ** Querying file status
5959
deviceID, fileID, fileMode, linkCount, fileOwner, fileGroup,
60-
specialDeviceID, fileSize, accessTime, modificationTime,
60+
specialDeviceID, fileSize, fileBlockSize,
61+
fileBlocks, accessTime, modificationTime,
6162
statusChangeTime,
6263
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
6364
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,

System/Posix/Files/ByteString.hsc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ module System.Posix.Files.ByteString (
5757
getFileStatus, getFdStatus, getSymbolicLinkStatus,
5858
-- ** Querying file status
5959
deviceID, fileID, fileMode, linkCount, fileOwner, fileGroup,
60-
specialDeviceID, fileSize, accessTime, modificationTime,
60+
specialDeviceID, fileSize, fileBlockSize,
61+
fileBlocks, accessTime, modificationTime,
6162
statusChangeTime,
6263
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
6364
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,

System/Posix/Files/Common.hsc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
252253
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
253258
-- | Time of last access.
254259
accessTime :: FileStatus -> EpochTime
255260
-- | Time of last access in sub-second resolution.
@@ -286,6 +291,22 @@ modificationTime (FileStatus stat) =
286291
statusChangeTime (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+
289310
accessTimeHiRes (FileStatus stat) =
290311
unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
291312
sec <- (#peek struct stat, st_atime) stat_ptr :: IO EpochTime

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ AC_CHECK_MEMBERS([struct stat.st_uatime])
6666
AC_CHECK_MEMBERS([struct stat.st_umtime])
6767
AC_CHECK_MEMBERS([struct stat.st_uctime])
6868

69+
AC_CHECK_MEMBERS([struct stat.st_blocks])
70+
AC_CHECK_MEMBERS([struct stat.st_blksize])
71+
6972
AC_CHECK_MEMBER([struct passwd.pw_gecos], [], [AC_DEFINE([HAVE_NO_PASSWD_PW_GECOS],[],[Ignore the pw_gecos member of passwd where it does not exist])], [[#include <pwd.h>]])
7073

7174
# Functions for changing file timestamps

0 commit comments

Comments
 (0)