|
| OsString | nix::readLinkAt (Descriptor dirFd, const OsCanonPath &path) |
| void | nix::createFileSymlinkAt (Descriptor dirFd, const OsCanonPath &path, const OsString &target) |
| void | nix::createDirectorySymlinkAt (Descriptor dirFd, const OsCanonPath &path, const OsString &target) |
| void | nix::createUnknownSymlinkAt (Descriptor dirFd, const OsCanonPath &path, const OsString &target) |
| Result< AutoCloseFD, NativeError > | nix::openDirectoryAt (Descriptor dirFd, const OsCanonPath &path) |
| Result< AutoCloseFD, NativeError > | nix::reopenDirectory (Descriptor dirFd) |
| Result< AutoCloseFD, NativeError > | nix::createDirectoryAt (Descriptor dirFd, const OsCanonPath &path, mode_t mode=0777) |
| PosixStat | nix::fstat (Descriptor fd) |
| std::optional< PosixStat > | nix::maybeFstatat (Descriptor dirFd, const OsCanonPath &path) |
| PosixStat | nix::fstatat (Descriptor dirFd, const OsCanonPath &path) |
| Result< AutoCloseFD, NativeError > | nix::openFileEnsureBeneathNoSymlinks (Descriptor dirFd, const OsCanonPath &path, int flags, mode_t mode=0, std::function< void(AutoCloseFD dirFd, OsCanonPath relPath)> dirFdCallback=nullptr) |
| std::optional< Result< AutoCloseFD, NativeError > > | nix::linux::openat2 (Descriptor dirFd, const char *path, uint64_t flags, uint64_t mode, uint64_t resolve) |
| void | nix::unix::fchmodatTryNoFollow (Descriptor dirFd, const OsCanonPath &path, mode_t mode) |
File system operations relative to directory file descriptors.
This header provides cross-platform wrappers for POSIX *at functions (e.g., symlinkat, mkdirat, readlinkat) that operate relative to a directory file descriptor.
Prefer this to file-system.hh because file descriptor-based file system operations are necessary to avoid TOCTOU issues.
| Result< AutoCloseFD, NativeError > nix::openFileEnsureBeneathNoSymlinks |
( |
Descriptor | dirFd, |
|
|
const OsCanonPath & | path, |
|
|
int | flags, |
|
|
mode_t | mode = 0, |
|
|
std::function< void(AutoCloseFD dirFd, OsCanonPath relPath)> | dirFdCallback = nullptr ) |
Open a file relative to dirFd, ensuring the path stays beneath dirFd and that no path component is a symlink (with the exception that O_PATH (without O_DIRECTORY) on Unix permits a trailing symlink).
Callers must not pass O_NOFOLLOW on Unix (enforced by assert); this function owns symlink policy and handles the flag internally.
- Parameters
-
| dirFdCallback | Callback invoked that gets the ownership of an intermediate directory fd. |
- Precondition
- path.empty() is false
- Exceptions
-
| SymlinkNotAllowed | if an interior path component is a symlink, or if the final component is a symlink and O_PATH (without O_DIRECTORY) was not passed. With O_PATH (without O_DIRECTORY) on Unix, a trailing symlink is permitted and the caller receives a "path fd" to the symlink itself. |
- Note
- With O_CREAT | O_EXCL, a pre-existing symlink at the final component causes the OS to return EEXIST rather than ELOOP, so SymlinkNotAllowed is not thrown — the caller sees a failure with EEXIST.
- Returns
- The descriptor, or on non-symlink errors the native error code (e.g. ENOENT, ENOTDIR, EACCES on Unix).
The error will never be ELOOP because that case is translated to a SymlinkNotAllowed throw instead.
- Parameters
-
| path | Directory handle to open relative to |
| flags | path Relative path (with no .. or . components) |
| mode | O_* flags (must not include O_NOFOLLOW) |
| dirFdCallback | Mode for O_{CREAT,TMPFILE} |