From abef3ecc22303b720771acb115fd0cc49600cc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Th=C3=A4ter?= Date: Mon, 19 Apr 2021 08:32:45 +0200 Subject: [PATCH] Store inode in Entry, add accessor the d_ino field is mandatory in POSIX and clients (me) really need it when passing data around. Keeping it in the Entry saves an extra stat()/metadata query. --- src/lib.rs | 1 + src/list.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a1a2feb..4bd3e3a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,7 @@ pub struct Dir(RawFd); pub struct Entry { name: CString, file_type: Option, + ino: libc::ino_t, } #[cfg(test)] diff --git a/src/list.rs b/src/list.rs index 5b4d3cd..3577fb2 100644 --- a/src/list.rs +++ b/src/list.rs @@ -37,6 +37,10 @@ impl Entry { pub fn simple_type(&self) -> Option { self.file_type } + /// Returns the inode number of this entry + pub fn inode(&self) -> libc::ino_t { + self.ino + } } #[cfg(any(target_os="linux", target_os="fuchsia"))] @@ -136,6 +140,7 @@ impl Iterator for DirIter { libc::DT_LNK => Some(SimpleType::Symlink), _ => Some(SimpleType::Other), }, + ino: e.d_ino, })); } }