1 /**
2  * BSD 2-Clause License
3  *
4  * Copyright (c) 2021, Khaled Emara
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
Wow64DisableWow64FsRedirection( OldValue: *mut PVOID, ) -> BOOL9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  *    list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  *    this list of conditions and the following disclaimer in the documentation
15  *    and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 use fuse::FileType;
29 
30 use super::dir3::{XFS_DIR3_FT_DIR, XFS_DIR3_FT_REG_FILE, XFS_DIR3_FT_SYMLINK};
31 
32 use libc::{c_int, mode_t, ENOENT, S_IFDIR, S_IFLNK, S_IFMT, S_IFREG};
33 
34 pub enum FileKind {
35     Type(u8),
36     Mode(u16),
37 }
38 
39 pub fn get_file_type(kind: FileKind) -> Result<FileType, c_int> {
40     match kind {
41         FileKind::Type(file_type) => match file_type {
42             XFS_DIR3_FT_REG_FILE => Ok(FileType::RegularFile),
43             XFS_DIR3_FT_DIR => Ok(FileType::Directory),
44             XFS_DIR3_FT_SYMLINK => Ok(FileType::Symlink),
45             _ => {
46                 println!("Unknown file type.");
47                 Err(ENOENT)
48             }
49         },
50         FileKind::Mode(file_mode) => match (file_mode as mode_t) & S_IFMT {
51             S_IFREG => Ok(FileType::RegularFile),
52             S_IFDIR => Ok(FileType::Directory),
53             S_IFLNK => Ok(FileType::Symlink),
54             _ => {
55                 println!("Unknown file type.");
56                 Err(ENOENT)
57             }
58         },
59     }
60 }
61