Combines the two file modes into one that contains modes that appear in either.
Moduleunix-2.8.7.0Haskell2010
System.Posix.Files
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.
- 6 types
- 112 values
- Packageunix-2.8.7.0
- Exports139
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceFiles.hsc
File modes
27 declarationsCombines two file modes into one that only contains modes that appear in both.
No permissions.
Owner has read permission.
Owner has write permission.
Owner has execute permission.
Owner has read, write and execute permission.
Group has read permission.
Group has write permission.
Group has execute permission.
Group has read, write and execute permission.
Others have read permission.
Others have write permission.
Others have execute permission.
Others have read, write and execute permission.
Set user ID on execution.
Set group ID on execution.
Owner, group and others have read and write permission.
Owner, group and others have read, write and execute permission.
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.
setFdMode fd mode acts like setFileMode but uses a file descriptor
fd instead of a FilePath.
Note: calls fchmod.
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
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.
Checks for the existence of the file.
Note: calls access.
File status
1 declarationPOSIX 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.
Constructors
FileStatus (ForeignPtr CStat)The constructor is considered internal and may change.
Obtaining file status
getFileStatus path calls gets the FileStatus information (user ID,
size, access times, etc.) for the file path.
Note: calls stat.
getFdStatus fd acts as getFileStatus but uses a file descriptor fd.
Note: calls fstat.
Acts as getFileStatus except when the FilePath refers to a symbolic
link. In that case the FileStatus information of the symbolic link itself
is returned instead of that of the file it points to.
Note: calls lstat.
Querying file status
ID of the device on which this file resides.
inode number
File mode (such as permissions).
Number of hard links to this file.
ID of owner.
ID of group.
Describes the device that this file represents.
Size of the file in bytes. If this file is a symbolic link the size is the length of the pathname it contains.
Time of last access.
Time of last modification.
Time of last status change (i.e. owner, group, link count, mode, etc.).
Time of last access in sub-second resolution. Depends on the timestamp resolution of the underlying filesystem.
Time of last modification in sub-second resolution. Depends on the timestamp resolution of the underlying filesystem.
Time of last status change (i.e. owner, group, link count, mode, etc.) in sub-second resolution. Depends on the timestamp resolution of the underlying filesystem.
Checks if this file is a block device.
Checks if this file is a character device.
Checks if this file is a named pipe device.
Checks if this file is a regular file device.
Checks if this file is a directory device.
Checks if this file is a symbolic link device.
Checks if this file is a socket device.
Gives the preferred block size for efficient filesystem I/O in
bytes. Returns Nothing if st_blocksize is not supported on this
platform.
Number of blocks allocated for this file, in units of
512-bytes. Returns Nothing if st_blocks is not supported on this
platform.
Extended file status
3 declarationsConstructors
ExtendedFileStatus (ForeignPtr CStatx)The constructor is considered internal and may change.
Constructors
Instances7Eq, Num, Ord, Read, Show, Bits, …
Eq CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.CommonNum CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.CommonOrd CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.CommonRead CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.CommonShow CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.CommonBits CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.CommonStorable CAttributesDefined in unix-2.8.7.0 · System.Posix.Files.Common
Whether statx is available on this platform and getExtendedFileStatus and
related functions will work.
Obtaining extended file status
getExtendedFileStatus :: Maybe FdOptional directory file descriptor (
dirfd)-> FilePathpathnameto open-> StatxFlagsflags
-> StatxMaskmask
-> IO ExtendedFileStatus
Gets extended file status information.
The target file to open is identified in one of the following ways:
If
pathnamebegins with a slash, then it is an absolute pathname that identifies the target file. In this case,dirfdis ignoredIf
pathnameis a string that begins with a character other than a slash anddirfdis 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. (Seeopenat(2)for an explanation of why this is useful.)If
pathnameis 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 descriptordirfd.
Note: calls statx.
Flags
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, …
Enum StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonEq StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonIntegral StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonNum StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonOrd StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonRead StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonReal StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonShow StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonSemigroup StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonORs the flags.
Monoid StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonBits StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.Common
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.
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.
If pathname is a symbolic link, do not dereference it: instead return information about the link itself, like lstat(2).
Do whatever stat(2) does. This is the default and is very much filesystem-specific.
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.
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
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 (.&.).
Instances11Enum, Eq, Integral, Num, Ord, Read, …
Enum StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonEq StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonIntegral StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonNum StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonOrd StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonRead StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonReal StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonShow StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonSemigroup StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonORs the masks.
Monoid StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonBits StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.Common
Want stx_mode & S_IFMT.
Want stx_mode & ~S_IFMT.
Want stx_nlink.
Want stx_uid.
Want stx_gid.
Want stx_atime.
Want stx_mtime.
Want stx_ctime.
Want stx_ino.
Want stx_size.
Want stx_blocks.
Want all of the above.
Want stx_btime.
Want stx_mnt_id.
Want all currently available fields.
Querying extended file status
The "preferred" block size for efficient filesystem I/O. (Writing to a file in smaller chunks may cause an inefficient read-modify-rewrite.)
The number of hard links on a file.
Te user ID of the owner of the file.
The ID of the group owner of the file.
The file type and mode. See inode(7) for details.
The inode number of the file.
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 number of blocks allocated to the file on the medium, in 512-byte units. (This may be smaller than stx_size/512 when the file has holes.)
The file's last access timestamp.
The file's creation timestamp.
The file's last status change timestamp.
The file's last modification timestamp.
ID of the device on which this file resides.
Describes the device that this file represents.
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 is compressed by the filesystem and may take extra resources to access. This is an extended attribute.
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 can only be opened in append mode for writing. Random access writing is not permitted. See chattr(1).
This is an extended attribute.
File is not a candidate for backup when a backup program such as dump(8) is run. See chattr(1).
This is an extended attribute.
A key is required for the file to be encrypted by the filesystem. 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.
The file is in the DAX (cpu direct access) state. This is an extended attribute. Since Linux 5.8.
Checks if this file is a block device.
Checks if this file is a character device.
Checks if this file is a named pipe device.
Checks if this file is a regular file device.
Checks if this file is a directory device.
Checks if this file is a symbolic link device.
Checks if this file is a socket device.
Creation
2 declarationscreateNamedPipe 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.
createDevice path mode dev creates either a regular or a special file
depending on the value of mode (and dev). mode will normally be either
blockSpecialMode or characterSpecialMode. 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 file.
Note: calls mknod.
Hard links
2 declarationscreateLink old new creates a new path, new, linked to an existing file,
old.
Note: calls link.
removeLink path removes the link named path.
Note: calls unlink.
Symbolic links
2 declarationscreateSymbolicLink name1 name2 creates a symbolic link named name2
which points to the file name1.
Symbolic links are interpreted at run-time as if the contents of the link had been substituted into the path being followed to find a file or directory.
Note: calls symlink.
Reads the FilePath pointed to by the symbolic link and returns it.
Note: calls readlink.
Renaming files
1 declarationrename old new renames a file or directory from old to new.
Note: calls rename.
Changing file ownership
3 declarationssetOwnerAndGroup 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.
Acts as setOwnerAndGroup but uses a file descriptor instead of a
FilePath.
Note: calls fchown.
Acts as setOwnerAndGroup but does not follow symlinks (and thus changes permissions on the link itself).
Note: calls lchown.
Changing file timestamps
7 declarationssetFileTimes path atime mtime sets the access and modification times
associated with file path to atime and mtime, respectively.
Note: calls utime.
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.
touchFile path sets the access and modification times associated with
file path to the current time.
Note: calls utime.
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.
Like touchFile 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 lutimes.
Setting file sizes
2 declarationsTruncates 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.
Acts as setFileSize but uses a file descriptor instead of a FilePath.
Note: calls ftruncate.
Find system-specific limits for a file
3 declarationsgetPathVar 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.