Skip to content

Commit 2403c59

Browse files
committed
Add accessors for st_blocks and st_blksize
1 parent 7b20b4c commit 2403c59

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

System/Posix/Files.hsc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ 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,
61+
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
62+
fileBlockSize,
63+
#endif
64+
fileBlocks, accessTime, modificationTime,
6165
statusChangeTime,
6266
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
6367
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,

System/Posix/Files/ByteString.hsc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ 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,
61+
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
62+
fileBlockSize,
63+
#endif
64+
fileBlocks, accessTime, modificationTime,
6165
statusChangeTime,
6266
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
6367
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,

System/Posix/Files/Common.hsc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ 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,
53+
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
54+
fileBlockSize,
55+
#endif
56+
fileBlocks, accessTime, modificationTime,
5357
statusChangeTime,
5458
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
5559
setFdTimesHiRes, touchFd,
@@ -250,6 +254,8 @@ specialDeviceID :: FileStatus -> DeviceID
250254
-- | Size of the file in bytes. If this file is a symbolic link the size is
251255
-- the length of the pathname it contains.
252256
fileSize :: FileStatus -> FileOffset
257+
-- | Number of block blocks allocated for this file, in units of 512-byte.
258+
fileBlocks :: FileStatus -> CBlkCnt
253259
-- | Time of last access.
254260
accessTime :: FileStatus -> EpochTime
255261
-- | Time of last access in sub-second resolution.
@@ -279,13 +285,22 @@ specialDeviceID (FileStatus stat) =
279285
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_rdev)
280286
fileSize (FileStatus stat) =
281287
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_size)
288+
fileBlocks (FileStatus stat) =
289+
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_blocks)
282290
accessTime (FileStatus stat) =
283291
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_atime)
284292
modificationTime (FileStatus stat) =
285293
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_mtime)
286294
statusChangeTime (FileStatus stat) =
287295
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_ctime)
288296

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+
289304
accessTimeHiRes (FileStatus stat) =
290305
unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do
291306
sec <- (#peek struct stat, st_atime) stat_ptr :: IO EpochTime

configure.ac

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ AC_CHECK_MEMBERS([struct stat.st_uatime])
6464
AC_CHECK_MEMBERS([struct stat.st_umtime])
6565
AC_CHECK_MEMBERS([struct stat.st_uctime])
6666

67+
AC_CHECK_MEMBERS([struct stat.st_blksize])
68+
6769
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>]])
6870

6971
# Functions for changing file timestamps

0 commit comments

Comments
 (0)