HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

Moduleunix-2.8.8.0Haskell2010

System.Posix.Files.ByteString

Functions defined by the POSIX standards for manipulating and querying the file system. Names of underlying POSIX functions are indicated whenever possible. A more complete documentation of the POSIX functions together with a more detailed description of different error conditions are usually available in the system's manual pages or from http://www.unix.org/version3/online.html (free registration required).

When a function that calls an underlying POSIX function fails, the errno code is converted to an IOError using errnoToIOError. For a list of which errno codes may be generated, consult the POSIX documentation for the underlying function.

Contents
  1. File modes
  2. Setting file modes
  3. Checking file existence and permissions
  4. File status
  5. Obtaining file status
  6. Querying file status
  7. Extended file status
  8. Obtaining extended file status
  9. Flags
  10. Mask
  11. Querying extended file status
  12. Creation
  13. Hard links
  14. Symbolic links
  15. Renaming files
  16. Changing file ownership
  17. Changing file timestamps
  18. Setting file sizes
  19. Find system-specific limits for a file
Synopsis
  • Packageunix-2.8.8.0
  • Exports139
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceByteString.hsc

File modes

Setting file modes

setFileMode path mode changes permission of the file given by path to mode. This operation may fail with throwErrnoPathIfMinus1_ if path doesn't exist or if the effective user ID of the current process is not that of the file's owner.

Note: calls chmod.

setFileCreationMask mode sets the file mode creation mask to mode. Modes set by this operation are subtracted from files and directories upon creation. The previous file creation mask is returned.

Note: calls umask.

Checking file existence and permissions

valuefileAccess :: RawFilePath -> Bool -> Bool -> Bool -> IO Bool

fileAccess name read write exec checks if the file (or other file system object) name can be accessed for reading, writing and/or executing. To check a permission set the corresponding argument to True.

Note: calls access.

File status

newtypenewtype FileStatus

POSIX defines operations to get information, such as owner, permissions, size and access times, about a file. This information is represented by the FileStatus type.

Note: see chmod.

Limitations: Support for high resolution timestamps is filesystem dependent:

  • HFS+ volumes on OS X only support whole-second times.

Obtaining file status

Querying file status

Extended file status

newtypenewtype CAttributes
#

Constructors

Instances7Eq, Num, Ord, Read, Show, Bits, …
valuehaveStatx :: Bool

Whether statx is available on this platform and getExtendedFileStatus and related functions will work.

Obtaining extended file status

valuegetExtendedFileStatus
  1. :: Maybe Fd

    Optional directory file descriptor (dirfd)

  2. -> RawFilePath

    pathname to open

  3. -> StatxFlags

    flags

  4. -> StatxMask

    mask

  5. -> IO ExtendedFileStatus

Gets extended file status information.

The target file to open is identified in one of the following ways:

  • If pathname begins with a slash, then it is an absolute pathname that identifies the target file. In this case, dirfd is ignored

  • If pathname is a string that begins with a character other than a slash and dirfd is a file descriptor that refers to a directory, then pathname is a relative pathname that is interpreted relative to the directory referred to by dirfd. (See openat(2) for an explanation of why this is useful.)

  • If pathname is an empty string and the EmptyPath flag is specified in flags (see below), then the target file is the one referred to by the file descriptor dirfd.

Note: calls statx.

Flags

newtypenewtype StatxFlags

Statx flags.

See the pattern synonyms for possible flags. These are combined via (<>). Flags can be tested via (.&.).

The following flags influence pathname-based lookup:

The following flags can be used to control what sort of synchronization the kernel will do when querying a file on a remote filesystem:

Constructors

Instances11Enum, Eq, Integral, Num, Ord, Read, …
patternpattern EmptyPath :: StatxFlags

If pathname to getExtendedFileStatus is an empty string, operate on the file referred to by the 'Maybe Fd' argument.

In this case, it can refer to any type of file, not just a directory.

patternpattern NoAutoMount :: StatxFlags

Don't automount the terminal ("basename") component of pathname if it is a directory that is an automount point. This allows the caller to gather attributes of an automount point (rather than the location it would mount). This flag can be used in tools that scan directories to prevent mass-automounting of a directory of automount points. This flag has no effect if the mount point has already been mounted over.

patternpattern SymlinkNoFollow :: StatxFlags

If pathname is a symbolic link, do not dereference it: instead return information about the link itself, like lstat(2).

patternpattern ForceSync :: StatxFlags

Force the attributes to be synchronized with the server. This may require that a network filesystem perform a data writeback to get the timestamps correct.

patternpattern DontSync :: StatxFlags

Don't synchronize anything, but rather just take whatever the system has cached if possible. This may mean that the information returned is approximate, but, on a network filesystem, it may not involve a round trip to the server - even if no lease is held.

Mask

newtypenewtype StatxMask

Mask argument to statx. It's used to tell the kernel which fields the caller is interested in.

See the pattern synonyms for possible masks. These are combined via (<>). Masks can be tested via (.&.).

Constructors

Instances11Enum, Eq, Integral, Num, Ord, Read, …

Querying extended file status

The size of the file (if it is a regular file or a symbolic link) in bytes. The size of a symbolic link is the length of the pathname it contains, without a terminating null byte.

The mount ID of the mount containing the file. This is the same number reported by name_to_handle_at(2) and corresponds to the number in the first field in one of the records in procself/mountinfo.

The file cannot be modified: it cannot be deleted or renamed, no hard links can be created to this file and no data can be written to it. See chattr(1). This is an extended attribute.

The file has fs-verity enabled. It cannot be written to, and all reads from it will be verified against a cryptographic hash that covers the entire file (e.g., via a Merkle tree). This is an extended attribute. Since Linux 5.5.

Creation

createNamedPipe fifo mode creates a new named pipe, fifo, with permissions based on mode. May fail with throwErrnoPathIfMinus1_ if a file named name already exists or if the effective user ID of the current process doesn't have permission to create the pipe.

Note: calls mkfifo.

Hard links

Symbolic links

Renaming files

Changing file ownership

setOwnerAndGroup path uid gid changes the owner and group of path to uid and gid, respectively.

If uid or gid is specified as -1, then that ID is not changed.

Note: calls chown.

Changing file timestamps

Like setFileTimes but timestamps can have sub-second resolution.

Note: calls utimensat or utimes. Support for high resolution timestamps is filesystem dependent with the following limitations:

  • HFS+ volumes on OS X truncate the sub-second part of the timestamp.

Like setFileTimesHiRes but uses a file descriptor instead of a path. This operation is not supported on all platforms. On these platforms, this function will raise an exception.

Note: calls futimens or futimes. Support for high resolution timestamps is filesystem dependent with the following limitations:

  • HFS+ volumes on OS X truncate the sub-second part of the timestamp.

Like setFileTimesHiRes but does not follow symbolic links. This operation is not supported on all platforms. On these platforms, this function will raise an exception.

Note: calls utimensat or lutimes. Support for high resolution timestamps is filesystem dependent with the following limitations:

  • HFS+ volumes on OS X truncate the sub-second part of the timestamp.

valuetouchFile :: RawFilePath -> IO ()

touchFile path sets the access and modification times associated with file path to the current time.

Note: calls utime.

valuetouchFd :: Fd -> IO ()

Like touchFile but uses a file descriptor instead of a path. This operation is not supported on all platforms. On these platforms, this function will raise an exception.

Note: calls futimes.

Setting file sizes

Truncates the file down to the specified length. If the file was larger than the given length before this operation was performed the extra is lost.

Note: calls truncate.

Find system-specific limits for a file

getPathVar var path obtains the dynamic value of the requested configurable file limit or option associated with file or directory path. For defined file limits, getPathVar returns the associated value. For defined file options, the result of getPathVar is undefined, but not failure.

Note: calls pathconf.

getFdPathVar var fd obtains the dynamic value of the requested configurable file limit or option associated with the file or directory attached to the open channel fd. For defined file limits, getFdPathVar returns the associated value. For defined file options, the result of getFdPathVar is undefined, but not failure.

Note: calls fpathconf.