standard_lib/fs/
file_type.rs1#[derive(Debug, Clone, PartialEq)]
2pub enum FileType {
3 BlockDevice,
4 CharDevice,
5 Directory,
6 Fifo,
7 Symlink,
8 Regular,
9 Socket,
10 Other,
11}
12
13use FileType::*;
14
15impl FileType {
16 #[inline(always)]
17 pub(crate) const fn from_stat_mode(st_mode: u32) -> FileType {
18 match st_mode & libc::S_IFMT {
19 libc::S_IFBLK => BlockDevice,
20 libc::S_IFCHR => CharDevice,
21 libc::S_IFDIR => Directory,
22 libc::S_IFIFO => Fifo,
23 libc::S_IFLNK => Symlink,
24 libc::S_IFREG => Regular,
25 libc::S_IFSOCK => Socket,
26 _ => Other,
27 }
28 }
29
30 pub(crate) fn from_dirent_type(d_type: u8) -> Option<FileType> {
31 Some(match d_type {
32 libc::DT_BLK => BlockDevice,
33 libc::DT_CHR => CharDevice,
34 libc::DT_DIR => Directory,
35 libc::DT_FIFO => Fifo,
36 libc::DT_LNK => Symlink,
37 libc::DT_REG => Regular,
38 libc::DT_SOCK => Socket,
39 libc::DT_UNKNOWN => None?,
40 _ => Other,
41 })
42 }
43}