From 8df03bb6f9a8617eee1cadafc86f771717c240c4 Mon Sep 17 00:00:00 2001 From: Ron Williams Date: Tue, 10 Jun 2025 12:44:27 -0700 Subject: [PATCH] Match DirentKind to include/bits/dirent.h --- src/dirent.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/dirent.rs b/src/dirent.rs index 285418dd06..67416b62bd 100644 --- a/src/dirent.rs +++ b/src/dirent.rs @@ -38,37 +38,41 @@ impl DerefMut for DirentHeader { unsafe { slice::from_raw_parts_mut(self as *mut Self as *mut u8, size_of::()) } } } + +// Note: Must match relibc/include/bits/dirent.h #[derive(Clone, Copy, Debug, Default)] #[repr(u8)] pub enum DirentKind { #[default] Unspecified = 0, - Regular = 1, - Directory = 2, - Symlink = 3, - BlockDev = 4, - CharDev = 5, - Socket = 6, + CharDev = 2, + Directory = 4, + BlockDev = 6, + Regular = 8, + Symlink = 10, + Socket = 12, } + impl DirentKind { // TODO: derive(FromPrimitive) pub fn try_from_raw(raw: u8) -> Option { Some(match raw { 0 => Self::Unspecified, - 1 => Self::Regular, - 2 => Self::Directory, - 3 => Self::Symlink, - 4 => Self::BlockDev, - 5 => Self::CharDev, - 6 => Self::Socket, + 2 => Self::CharDev, + 4 => Self::Directory, + 6 => Self::BlockDev, + 8 => Self::Regular, + 10 => Self::Symlink, + 12 => Self::Socket, _ => return None, }) } } + pub struct DirentIter<'a>(&'a [u8]); impl<'a> DirentIter<'a> {