diff --git a/System/Posix/Files.hsc b/System/Posix/Files.hsc index 104df18f..949abf7c 100644 --- a/System/Posix/Files.hsc +++ b/System/Posix/Files.hsc @@ -59,6 +59,9 @@ module System.Posix.Files ( isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile, isDirectory, isSymbolicLink, isSocket, + fileBlockSize, + fileBlocks, + -- * Creation createNamedPipe, createDevice, diff --git a/System/Posix/Files/ByteString.hsc b/System/Posix/Files/ByteString.hsc index 88298a2b..d808e86e 100644 --- a/System/Posix/Files/ByteString.hsc +++ b/System/Posix/Files/ByteString.hsc @@ -59,6 +59,9 @@ module System.Posix.Files.ByteString ( isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile, isDirectory, isSymbolicLink, isSocket, + fileBlockSize, + fileBlocks, + -- * Creation createNamedPipe, createDevice, diff --git a/System/Posix/Files/Common.hsc b/System/Posix/Files/Common.hsc index 59b94f1a..32e1997d 100644 --- a/System/Posix/Files/Common.hsc +++ b/System/Posix/Files/Common.hsc @@ -56,6 +56,9 @@ module System.Posix.Files.Common ( isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile, isDirectory, isSymbolicLink, isSocket, + fileBlockSize, + fileBlocks, + -- * Setting file sizes setFdSize, @@ -255,6 +258,14 @@ specialDeviceID :: FileStatus -> DeviceID -- | Size of the file in bytes. If this file is a symbolic link the size is -- the length of the pathname it contains. fileSize :: FileStatus -> FileOffset +-- | Number of blocks allocated for this file, in units of +-- 512-bytes. Returns @Nothing@ if @st_blocks@ is not supported on this +-- platform. +fileBlocks :: FileStatus -> Maybe CBlkCnt +-- | Gives the preferred block size for efficient filesystem I/O in +-- bytes. Returns @Nothing@ if @st_blocksize@ is not supported on this +-- platform. +fileBlockSize :: FileStatus -> Maybe CBlkSize -- | Time of last access. accessTime :: FileStatus -> EpochTime -- | Time of last access in sub-second resolution. Depends on the timestamp resolution of the @@ -294,6 +305,19 @@ modificationTime (FileStatus stat) = statusChangeTime (FileStatus stat) = unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_ctime) +#ifdef HAVE_STRUCT_STAT_ST_BLOCKS +fileBlocks (FileStatus stat) = + Just $ unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_blocks) +#else +fileBlocks _ = Nothing +#endif +#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE +fileBlockSize (FileStatus stat) = + Just $ unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_blksize) +#else +fileBlockSize _ = Nothing +#endif + accessTimeHiRes (FileStatus stat) = unsafePerformIO $ withForeignPtr stat $ \stat_ptr -> do sec <- (#peek struct stat, st_atime) stat_ptr :: IO EpochTime diff --git a/configure.ac b/configure.ac index c23c9e1c..c65df49e 100644 --- a/configure.ac +++ b/configure.ac @@ -66,6 +66,9 @@ AC_CHECK_MEMBERS([struct stat.st_uatime]) AC_CHECK_MEMBERS([struct stat.st_umtime]) AC_CHECK_MEMBERS([struct stat.st_uctime]) +AC_CHECK_MEMBERS([struct stat.st_blocks]) +AC_CHECK_MEMBERS([struct stat.st_blksize]) + 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 ]]) # Functions for changing file timestamps