Skip to main content

get_fd_identity

Function get_fd_identity 

Source
pub fn get_fd_identity(fd: BorrowedFd<'_>) -> Result<(u64, u64)>
Expand description

Get the device and inode for a file descriptor

This provides a direct way to identify a file from its open file descriptor, which is essential for accurately identifying stdout when it is redirected to a file.

§Implementation Note

This uses std::fs::File::from_raw_fd wrapped in ManuallyDrop to leverage the standard library’s Metadata implementation. This ensures that the dev and ino values returned here exactly match those returned by std::fs::metadata (which is used by the directory walker), avoiding potential mismatches due to platform-specific stat struct layouts or type casting differences.

§Arguments

  • fd - A borrowed file descriptor to inspect. BorrowedFd guarantees the descriptor is valid and open for the duration of the borrow, making this function safe to call without requiring unsafe at the call site.

§Returns

A tuple containing (device_id, inode_number) on success.

§Errors

Returns an io::Error if the underlying fstat syscall fails.