1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
use super::dir::Directory;
use super::file::RegularFile;
use super::fixed::FixedFile;
use super::symlink::SymLink;
use async_trait::async_trait;
use bytes::Bytes;
use enum_dispatch::enum_dispatch;
use fxhash::FxHashMap;
use serde::*;

use crate::error::*;

#[enum_dispatch(FileApi)]
pub enum FileSpec {
    //Custom,
    //NamedPipe,
    //CharDevice,
    //BlockDevice,
    Directory,
    RegularFile,
    SymLink,
    //Socket,
    FixedFile,
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum FileKind {
    Directory,
    RegularFile,
    FixedFile,
    SymLink,
}

#[async_trait]
#[enum_dispatch]
pub trait FileApi {
    fn ino(&self) -> u64;

    fn name(&self) -> String;

    fn kind(&self) -> FileKind;

    fn uid(&self) -> u32 {
        0
    }

    fn gid(&self) -> u32 {
        0
    }

    fn size(&self) -> u64 {
        0
    }

    fn mode(&self) -> u32 {
        0
    }

    fn accessed(&self) -> u64 {
        0
    }

    fn created(&self) -> u64 {
        0
    }

    fn updated(&self) -> u64 {
        0
    }

    async fn fallocate(&self, _size: u64) -> Result<()> {
        Ok(())
    }

    async fn read(&self, _offset: u64, _size: u64) -> Result<Bytes> {
        Ok(Bytes::from(Vec::new()))
    }

    async fn write(&self, _offset: u64, _data: &[u8]) -> Result<u64> {
        Ok(0)
    }

    fn link(&self) -> Option<String> {
        None
    }

    async fn commit(&self) -> Result<()> {
        Ok(())
    }

    async fn set_xattr(&mut self, _name: &str, _value: &str) -> Result<()> {
        Err(FileSystemErrorKind::NotImplemented.into())
    }

    async fn remove_xattr(&mut self, _name: &str) -> Result<bool> {
        Ok(false)
    }

    async fn get_xattr(&self, _name: &str) -> Result<Option<String>> {
        Ok(None)
    }

    async fn list_xattr(&self) -> Result<FxHashMap<String, String>> {
        Ok(FxHashMap::default())
    }
}