Welcome to mirror list, hosted at ThFree Co, Russian Federation.

x40.rs « attribute « src - github.com/windirstat/mft.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2526c8288e22a932bfd3bc901d72ca11cb751cbc (plain)
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
use crate::err::{Error, Result};
use crate::ReadSeek;
use serde::Serialize;
use winstructs::guid::Guid;

/// $Data Attribute
#[derive(Serialize, Clone, Debug)]
pub struct ObjectIdAttr {
    /// Unique Id assigned to file
    pub object_id: Guid,
    /// Volume where file was created
    pub birth_volume_id: Option<Guid>,
    /// Original Object Id of file
    pub birth_object_id: Option<Guid>,
    /// Domain in which object was created
    pub domain_id: Option<Guid>,
}

impl ObjectIdAttr {
    /// Data size should be either 16 or 64
    pub fn from_stream<S: ReadSeek>(stream: &mut S, data_size: usize) -> Result<ObjectIdAttr> {
        let object_id = Guid::from_reader(stream).map_err(Error::failed_to_read_guid)?;
        let (birth_volume_id, birth_object_id, domain_id) = if data_size == 64 {
            let g1 = Guid::from_reader(stream).map_err(Error::failed_to_read_guid)?;
            let g2 = Guid::from_reader(stream).map_err(Error::failed_to_read_guid)?;
            let g3 = Guid::from_reader(stream).map_err(Error::failed_to_read_guid)?;
            (Some(g1), Some(g2), Some(g3))
        } else {
            (None, None, None)
        };

        Ok(ObjectIdAttr {
            object_id,
            birth_volume_id,
            birth_object_id,
            domain_id,
        })
    }
}