@@ -5,7 +5,19 @@ use std::process::Command;
55
66use anyhow:: { bail, Context , Result } ;
77use openat_ext:: OpenatDirExt ;
8- use rustix:: fd:: BorrowedFd ;
8+ use rustix:: fd:: { AsFd , BorrowedFd } ;
9+
10+ /// [`openat::Dir`] only implements [`AsRawFd`]; this bridges to [`rustix::fd::AsFd`] so we can call
11+ /// [`rustix::fs::fstatvfs`] with `.as_fd()`, consistent with other rustix call sites in this crate
12+ /// (for example `cap_std::fs::Dir` in `efi.rs`).
13+ struct OpenatDirAsFd < ' a > ( & ' a openat:: Dir ) ;
14+
15+ impl AsFd for OpenatDirAsFd < ' _ > {
16+ fn as_fd ( & self ) -> BorrowedFd < ' _ > {
17+ // SAFETY: `openat::Dir` owns the fd; the borrow is tied to `&openat::Dir`.
18+ unsafe { BorrowedFd :: borrow_raw ( self . 0 . as_raw_fd ( ) ) }
19+ }
20+ }
921
1022/// Parse an environment variable as UTF-8
1123#[ allow( dead_code) ]
@@ -56,8 +68,7 @@ pub(crate) fn filenames(dir: &openat::Dir) -> Result<HashSet<String>> {
5668/// Return the available space in bytes on the filesystem containing the given directory.
5769/// Uses f_bavail * f_frsize from fstatvfs to avoid partial updates when the partition is full.
5870pub ( crate ) fn available_space_bytes ( dir : & openat:: Dir ) -> Result < u64 > {
59- let fd = unsafe { BorrowedFd :: borrow_raw ( dir. as_raw_fd ( ) ) } ;
60- let st = rustix:: fs:: fstatvfs ( fd) ?;
71+ let st = rustix:: fs:: fstatvfs ( OpenatDirAsFd ( dir) . as_fd ( ) ) ?;
6172 Ok ( ( st. f_bavail as u64 ) * ( st. f_frsize as u64 ) )
6273}
6374
0 commit comments