diff --git a/src/dir.rs b/src/dir.rs index c329e2d..3b1a93f 100644 --- a/src/dir.rs +++ b/src/dir.rs @@ -11,7 +11,7 @@ use chrono::{TimeZone, Local}; #[cfg(feature = "chrono")] use chrono; -use fs::{FileSystemRef, DiskSlice}; +use fs::{FileSystemRef, DiskSlice, FatType}; use file::File; #[derive(Clone)] @@ -107,14 +107,17 @@ pub(crate) struct DirFileEntryData { } impl DirFileEntryData { - pub(crate) fn first_cluster(&self) -> Option { - let n = ((self.first_cluster_hi as u32) << 16) | self.first_cluster_lo as u32; + pub(crate) fn first_cluster(&self, fat_type: FatType) -> Option { + let first_cluster_hi = if fat_type == FatType::Fat32 { self.first_cluster_hi } else { 0 }; + let n = ((first_cluster_hi as u32) << 16) | self.first_cluster_lo as u32; if n == 0 { None } else { Some(n) } } - pub(crate) fn set_first_cluster(&mut self, cluster: Option) { + pub(crate) fn set_first_cluster(&mut self, cluster: Option, fat_type: FatType) { let n = cluster.unwrap_or(0); - self.first_cluster_hi = (n >> 16) as u16; + if fat_type == FatType::Fat32 { + self.first_cluster_hi = (n >> 16) as u16; + } self.first_cluster_lo = (n & 0xFFFF) as u16; } @@ -715,7 +718,7 @@ impl <'a, 'b> Dir<'a, 'b> { attrs, ..Default::default() }; - raw_entry.set_first_cluster(first_cluster); + raw_entry.set_first_cluster(first_cluster, self.fs.fat_type); raw_entry.serialize(&mut stream)?; let end_pos = stream.seek(io::SeekFrom::Current(0))?; let abs_pos = stream.abs_pos().map(|p| p - DIR_ENTRY_SIZE); diff --git a/src/file.rs b/src/file.rs index 8326d13..e31642a 100644 --- a/src/file.rs +++ b/src/file.rs @@ -56,7 +56,7 @@ impl <'a, 'b> File<'a, 'b> { e.data.set_size(self.offset); if self.offset == 0 { - e.data.set_first_cluster(None); + e.data.set_first_cluster(None, self.fs.fat_type); } self.entry_dirty = true; }, @@ -124,7 +124,7 @@ impl <'a, 'b> File<'a, 'b> { self.first_cluster = Some(cluster); match self.entry { Some(ref mut e) => { - e.data.set_first_cluster(self.first_cluster); + e.data.set_first_cluster(self.first_cluster, self.fs.fat_type); }, None => {}, }