O_PATH
O_PATH is a Linux open flag that returns a filesystem-object reference without opening the object for ordinary data access.
The descriptor supports fstat(), duplication and, for a directory, relative openat() calls. It cannot supply file data or synchronize storage: read(), write(), mmap() and fsync() fail with EBADF, including fsync() on a directory reference. Acquiring it requires path-prefix search permission, not permissions on the final object; subsequent operations may perform their own checks. [1]
With O_NOFOLLOW, the descriptor can hold the final symlink itself for operations such as readlinkat() with an empty pathname. It does not hold that link's referent. [2]
A held reference remains associated with its object through pathname replacement. That lifetime guarantee is separate from namespace locking or preserving a version of file contents: another authorized writer can still modify the held file. [3]
Relations
Advantages
- Provides a reference for metadata inspection or directory-relative lookup without requesting ordinary data access.
Limitations
- Linux-specific; an O_PATH descriptor is not a readable backup stream or a content snapshot.
- A directory reference alone does not confine later lookup beneath that directory.
Citations
- Linux man-pages: open(2), O_PATH operations and permission checks
- Linux man-pages: symlink(7), descriptors referring to links
- Linux v6.12: Pathname lookup, dentry references and locking
Sources & caveats
- API source review. Reference lifetime, data-access permission and content consistency are separate properties; no crash-recovery guarantee is inferred.