fs-id 0.2.0

Uniquely identify files within the system
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::{io, mem, os::fd::AsRawFd};
use crate::{GetID, FileID};

pub type FileIDImpl = (u64, u64);

impl<T: AsRawFd> GetID for T {
	fn get_id(&self) -> io::Result<FileID> {
		let fd = self.as_raw_fd();
		unsafe {
			let mut buf = mem::zeroed();
			if libc::fstat64(fd, &mut buf) == 0 {
				Ok(FileID((buf.st_dev, buf.st_ino)))
			} else {
				Err(io::Error::last_os_error())				
			}
		}
	}
}