file_system/fundamentals/
statistics.rs

1use users::{GroupIdentifier, UserIdentifier};
2
3use crate::{Attributes, Kind, Size, Time};
4
5use super::{Inode, Permissions};
6
7/// Statistics of a file.
8///
9/// This type contains information about a file, such as its size, inode, etc.
10///
11/// # Fields
12///
13/// * `File_system`: The file system the file is on.
14/// * `Inode`: The inode of the file.
15/// * `Links`: The number of hard links to the file.
16/// * `Size`: The size of the file.
17/// * `Last_access`: The last time the file was accessed.
18/// * `Last_modification`: The last time the file was modified.
19/// * `Last_status_change`: The last time the file's status was changed.
20/// * `Type`: The type of the file.
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct Statistics {
23    pub group: GroupIdentifier,
24    pub user: UserIdentifier,
25    pub inode: Inode,
26    pub creation: Time,
27    pub access: Time,
28    pub modification: Time,
29    pub status: Time,
30    pub links: Size,
31    pub permissions: Permissions,
32    pub kind: Kind,
33    pub size: Size,
34}
35
36impl Statistics {
37    #[allow(clippy::too_many_arguments)]
38    pub fn new(
39        inode: Inode,
40        links: Size,
41        size: Size,
42        creation: Time,
43        access: Time,
44        modification: Time,
45        status: Time,
46        type_value: Kind,
47        permissions: Permissions,
48        user: UserIdentifier,
49        group: GroupIdentifier,
50    ) -> Self {
51        Statistics {
52            inode,
53            links,
54            size,
55            creation,
56            access,
57            modification,
58            status,
59            kind: type_value,
60            permissions,
61            user,
62            group,
63        }
64    }
65
66    pub fn from_attributes(attributes: &Attributes) -> Option<Self> {
67        Some(Statistics::new(
68            *attributes.get_inode()?,
69            *attributes.get_links()?,
70            *attributes.get_size()?,
71            *attributes.get_creation()?,
72            *attributes.get_access()?,
73            *attributes.get_modification()?,
74            *attributes.get_status()?,
75            *attributes.get_kind()?,
76            *attributes.get_permissions()?,
77            *attributes.get_user()?,
78            *attributes.get_group()?,
79        ))
80    }
81}