#open #filesystem #fs #openat


A wrapper around openat, symlinkat, and similar system calls

17 releases

0.1.16 Aug 7, 2018
0.1.15 Jun 11, 2018
0.1.13 Dec 17, 2017
0.1.12 Nov 7, 2017
0.1.2 Dec 28, 2016

#27 in Filesystem

Download history 218/week @ 2018-12-20 77/week @ 2018-12-27 155/week @ 2019-01-03 180/week @ 2019-01-10 230/week @ 2019-01-17 97/week @ 2019-01-24 168/week @ 2019-01-31 221/week @ 2019-02-07 153/week @ 2019-02-14 209/week @ 2019-02-21 179/week @ 2019-02-28 913/week @ 2019-03-07 527/week @ 2019-03-14 360/week @ 2019-03-21 147/week @ 2019-03-28

421 downloads per month
Used in 3 crates


660 lines

Openat Crate

Status: Beta

Documentation | Github | Crate

The interface to openat, symlinkat, and other functions in *at family.


Licensed under either of


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


Handling Files Relative to File Descriptor

Main concept here is a Dir which holds O_PATH file descriptor, you can create it with:

  • Dir::open("/some/path") -- open this directory as a file descriptor
  • Dir::from_raw_fd(fd) -- uses a file descriptor provided elsewhere

Note after opening file descriptors refer to same directory regardless of where it's moved or mounted (with pivot_root or mount --move). It may also be unmounted or be out of chroot and you will still be able to access files relative to it.

Note2: The constructor Dir::cwd() is deprecated, and it's recommended to use Dir::open(".") instead.

Most other operations are done on Dir object and are executed relative to it:

  • Dir::list_dir()
  • Dir::sub_dir()
  • Dir::read_link()
  • Dir::open_file()
  • Dir::create_file()
  • Dir::update_file()
  • Dir::create_dir()
  • Dir::symlink()
  • Dir::local_rename()

Functions that expect path relative to the directory accept both the traditional path-like objects, such as Path, PathBuf and &str, and Entry type returned from list_dir(). The latter is faster as underlying system call wants CString and we keep that in entry.

Note that if path supplied to any method of dir is absolute the Dir file descriptor is ignored.

Also while all methods of dir accept any path if you want to prevent certain symlink attacks and race condition you should only use a single-component path. I.e. open one part of a chain at a time.