fs_id/
unix.rs

1use std::{io, mem, os::fd::AsRawFd};
2use crate::{GetID, FileID};
3
4pub type FileIDImpl = (u64, u64);
5
6impl<T: AsRawFd> GetID for T {
7	fn get_id(&self) -> io::Result<FileID> {
8		let fd = self.as_raw_fd();
9		unsafe {
10			let mut buf = mem::zeroed();
11			if libc::fstat64(fd, &mut buf) == 0 {
12				Ok(FileID((buf.st_dev, buf.st_ino)))
13			} else {
14				Err(io::Error::last_os_error())				
15			}
16		}
17	}
18}