From bdcda26d77059b083481844db8113162a08334ab Mon Sep 17 00:00:00 2001 From: Moritz Gmeiner Date: Thu, 31 Jul 2025 01:13:32 +0200 Subject: [PATCH] cluster 0 as 'empty' marker --- fat-bits/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fat-bits/src/lib.rs b/fat-bits/src/lib.rs index 5db4130..bd50960 100644 --- a/fat-bits/src/lib.rs +++ b/fat-bits/src/lib.rs @@ -185,12 +185,28 @@ impl FatFs { } pub fn cluster_as_subslice_mut(&mut self, cluster: u32) -> SubSliceMut<'_> { + if cluster == 0 { + // for cluster 0 simply return empty subslice + // this makes things a bit easier, since cluster 0 is used as a marker that a file/dir + // is empty + + SubSliceMut::new(self, 0, 0); + } + let offset = self.data_cluster_to_offset(cluster); SubSliceMut::new(self, offset, self.bytes_per_cluster) } pub fn cluster_as_subslice(&self, cluster: u32) -> SubSlice<'_> { + if cluster == 0 { + // for cluster 0 simply return empty subslice + // this makes things a bit easier, since cluster 0 is used as a marker that a file/dir + // is empty + + SubSlice::new(self, 0, 0); + } + let offset = self.data_cluster_to_offset(cluster); SubSlice::new(self, offset, self.bytes_per_cluster)