Skip to content

Commit 169cc24

Browse files
committed
Add BlockSize and BlocksCount fields for FileStatus
TODO: find a better place for the new types
1 parent 94d8824 commit 169cc24

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

System/Posix/Files.hsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ 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, blockSize, blocksCount, accessTime, modificationTime,
6161
statusChangeTime,
6262
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
6363
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,

System/Posix/Files/Common.hsc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module System.Posix.Files.Common (
5050
getFdStatus,
5151
-- ** Querying file status
5252
deviceID, fileID, fileMode, linkCount, fileOwner, fileGroup,
53-
specialDeviceID, fileSize, accessTime, modificationTime,
53+
specialDeviceID, fileSize, blockSize, blocksCount, accessTime, modificationTime,
5454
statusChangeTime,
5555
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
5656
setFdTimesHiRes, touchFd,
@@ -234,6 +234,11 @@ setFileCreationMask mask = c_umask mask
234234
-- -----------------------------------------------------------------------------
235235
-- stat() support
236236

237+
-- TODO: Those values should be defined in package base
238+
-- and correct type should be used. CSsize works, but without guarantee
239+
type BlockSize = CSsize
240+
type BlocksCount = CSsize
241+
237242
-- | POSIX defines operations to get information, such as owner, permissions,
238243
-- size and access times, about a file. This information is represented by the
239244
-- 'FileStatus' type.
@@ -258,6 +263,10 @@ specialDeviceID :: FileStatus -> DeviceID
258263
-- | Size of the file in bytes. If this file is a symbolic link the size is
259264
-- the length of the pathname it contains.
260265
fileSize :: FileStatus -> FileOffset
266+
-- | BlockSize for file
267+
blockSize :: FileStatus -> BlockSize
268+
-- | Number of blocks
269+
blocksCount :: FileStatus -> BlocksCount
261270
-- | Time of last access.
262271
accessTime :: FileStatus -> EpochTime
263272
-- | Time of last access in sub-second resolution.
@@ -287,6 +296,10 @@ specialDeviceID (FileStatus stat) =
287296
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_rdev)
288297
fileSize (FileStatus stat) =
289298
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_size)
299+
blockSize (FileStatus stat) =
300+
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_blksize)
301+
blocksCount (FileStatus stat) =
302+
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_blocks)
290303
accessTime (FileStatus stat) =
291304
unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_atime)
292305
modificationTime (FileStatus stat) =

0 commit comments

Comments
 (0)