14.2 Descriptor-Relative Access

Many functions that accept file names have …at variants which accept a file descriptor and a file name argument instead of just a file name argument. For example, fstatat is the descriptor-based variant of the fstat function. Most such functions also accept an additional flags argument which changes the behavior of the file name lookup based on the passed AT_… flags.

There are several reasons to use descriptor-relative access:

The file descriptor used by these …at functions has the following uses:

The flags argument in …at functions can be a combination of the following flags, defined in fcntl.h. Not all such functions support all flags, and some (such as openat) do not accept a flags argument at all.

In the flag descriptions below, the effective final path component refers to the final component (basename) of the full path constructed from the descriptor and file name arguments, using file name lookup, as described above.

AT_EMPTY_PATH

This flag is used with an empty file name "" and a descriptor which does not necessarily refer to a directory. It is most useful with O_PATH descriptors, as described above. This flag is a GNU extension.

AT_NO_AUTOMOUNT

If the effective final path component refers to a potential file system mount point controlled by an auto-mounting service, the operation does not trigger auto-mounting and refers to the unmounted mount point instead. See Mount, Unmount, Remount. If a file system has already been mounted at the effective final path component, the operation applies to the file or directory in the mounted file system, not the underlying file system that was mounted over. This flag is a GNU extension.

AT_SYMLINK_FOLLOW

If the effective final path component is a symbolic link, the operation follows the symbolic link and operates on its target. (For most functions, this is the default behavior.)

AT_SYMLINK_NOFOLLOW

If the effective final path component is a symbolic link, the operation operates on the symbolic link, without following it. The difference in behavior enabled by this flag is similar to the difference between the lstat and stat functions, or the behavior activated by the O_NOFOLLOW argument to the open function. Even with the AT_SYMLINK_NOFOLLOW flag present, symbolic links in a non-final component of the file name are still followed.

Note: There is no relationship between these flags and the type argument to the getauxval function (with AT_… constants defined in elf.h). See Auxiliary Vector.