File_system/Fundamentals/
Metadata.rs

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use Users::{Group_identifier_type, User_identifier_type};

use crate::{Permissions_type, Time_type, Type_type};

use super::Inode_type;

/// File attributes.
///
/// The attributes are metadata associated with the file that stores:
/// - The file type.
/// - The file creation time.
/// - The file modification time.
/// - The file access time.
/// - The file permissions.
/// - The file owner.
/// - The file group.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Metadata_type {
    /// The file inode.
    Inode: Option<Inode_type>,
    /// The file type.
    Type: Type_type,
    /// The file creation time.
    Creation_time: Time_type,
    /// The file modification time.
    Modification_time: Time_type,
    /// The file access time.
    Access_time: Time_type,
    /// The file permissions.
    Permissions: Permissions_type,
    /// The file owner.
    User: User_identifier_type,
    /// The file group.
    Group: Group_identifier_type,
}

impl Metadata_type {
    pub const Identifier: u8 = 0x01;

    pub fn Get_default(
        Type: Type_type,
        Current_time: Time_type,
        User: User_identifier_type,
        Group: Group_identifier_type,
    ) -> Option<Self> {
        let Permissions = Permissions_type::New_default(Type);

        Some(Metadata_type {
            Inode: None,
            Type,
            Creation_time: Current_time,
            Modification_time: Current_time,
            Access_time: Current_time,
            Permissions,
            User,
            Group,
        })
    }

    pub fn Get_inode(&self) -> Option<Inode_type> {
        self.Inode
    }

    pub fn Get_type(&self) -> Type_type {
        self.Type
    }

    pub fn Get_creation_time(&self) -> Time_type {
        self.Creation_time
    }

    pub fn Get_modification_time(&self) -> Time_type {
        self.Modification_time
    }

    pub fn Get_access_time(&self) -> Time_type {
        self.Access_time
    }

    pub fn Get_permissions(&self) -> Permissions_type {
        self.Permissions
    }

    pub fn Get_user(&self) -> User_identifier_type {
        self.User
    }

    pub fn Get_group(&self) -> Group_identifier_type {
        self.Group
    }

    pub fn Set_inode(&mut self, Inode: Inode_type) {
        self.Inode = Some(Inode);
    }

    pub fn Set_type(&mut self, Type: Type_type) {
        self.Type = Type;
    }

    pub fn Set_creation_time(&mut self, Time: Time_type) {
        self.Creation_time = Time;
    }

    pub fn Set_modification_time(&mut self, Time: Time_type) {
        self.Modification_time = Time;
    }

    pub fn Set_access_time(&mut self, Time: Time_type) {
        self.Access_time = Time;
    }

    pub fn Set_permissions(&mut self, Permissions: Permissions_type) {
        self.Permissions = Permissions;
    }

    pub fn Set_owner(&mut self, Owner: User_identifier_type) {
        self.User = Owner;
    }

    pub fn Set_group(&mut self, Group: Group_identifier_type) {
        self.Group = Group;
    }
}