Skip to main content

dope_sys/io/file/
metadata.rs

1use std::num::NonZero;
2
3use crate::io::file::Kind;
4
5#[derive(Clone, Copy, Debug, Eq, PartialEq)]
6pub struct Identity {
7    pub device: libc::dev_t,
8    pub inode: libc::ino_t,
9}
10
11pub type Value = (Kind, super::Offset, Option<Identity>);
12
13#[derive(Clone, Copy, Debug, Eq, PartialEq)]
14pub enum Error {
15    Missing(NonZero<u32>),
16    Negative(i64),
17    Overflow(u64),
18}
19
20/// Native metadata for one opened or named file.
21#[derive(Clone, Copy, Debug)]
22pub struct Metadata {
23    kind: Kind,
24    size: i64,
25    identity: Identity,
26}
27
28impl Metadata {
29    pub(super) const fn new(raw: libc::stat) -> Self {
30        Self {
31            kind: Kind::from_mode(raw.st_mode),
32            size: raw.st_size,
33            identity: Identity {
34                device: raw.st_dev,
35                inode: raw.st_ino,
36            },
37        }
38    }
39
40    pub const fn kind(self) -> Kind {
41        self.kind
42    }
43
44    /// Exact signed st_size reported by the native metadata operation.
45    pub const fn size(self) -> i64 {
46        self.size
47    }
48
49    pub const fn identity(self) -> Identity {
50        self.identity
51    }
52}