1use crate::ClusterId;
2use crate::PathBuf;
3use crate::api::raw_directory_entry::Attributes;
4use crate::api::timestamp::VfatTimestamp;
5use alloc::string::String;
6
7#[derive(Debug, Clone)]
9pub struct Metadata {
10 creation: VfatTimestamp,
11 last_update: VfatTimestamp,
12 pub(crate) name: String,
14 pub(crate) size: u32,
17 path: PathBuf,
19 pub(crate) cluster: ClusterId,
21 parent: PathBuf,
23 pub(crate) attributes: Attributes,
24}
25
26impl Metadata {
27 pub(crate) fn new<S: AsRef<str>>(
28 creation: VfatTimestamp,
29 last_update: VfatTimestamp,
30 name: S,
32 size: u32,
33 path: PathBuf,
34 cluster: ClusterId,
35 parent: PathBuf,
36 attributes: Attributes,
37 ) -> Self {
38 Self {
39 creation,
40 last_update,
41 name: String::from(name.as_ref()),
43 size,
44 path,
45 cluster,
46 parent,
47 attributes,
48 }
49 }
50}
51impl Metadata {
52 pub fn size(&self) -> usize {
54 self.size as usize
55 }
56
57 pub(crate) fn last_update(&self) -> Option<VfatTimestamp> {
65 Some(self.last_update)
66 }
67 pub(crate) fn creation(&self) -> Option<VfatTimestamp> {
69 Some(self.creation)
70 }
71
72 pub fn full_path(&self) -> &PathBuf {
74 &self.path
75 }
76 pub(crate) fn parent(&self) -> &PathBuf {
77 &self.parent
78 }
79 pub fn name(&self) -> &str {
81 &self.name
82 }
83 pub(crate) fn has_no_cluster_allocated(&self) -> bool {
84 self.cluster == ClusterId::new(0)
85 }
86}