Skip to content

Commit

Permalink
Update the free cluster count when unmounting.
Browse files Browse the repository at this point in the history
Also decrement the free cluster count when allocating a cluster.
  • Loading branch information
thejpster committed Oct 29, 2024
1 parent 7ed6189 commit c2341ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/fat/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ impl FatVolume {
Err(e) => return Err(e),
};
debug!("Next free cluster is {:?}", self.next_free_cluster);
// Record that we've allocated a cluster
if let Some(ref mut number_free_cluster) = self.free_clusters_count {
*number_free_cluster -= 1;
};
Expand Down
7 changes: 7 additions & 0 deletions src/volume_mgr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ where
/// You can't close it if there are any files or directories open on it.
pub fn close_volume(&self, volume: RawVolume) -> Result<(), Error<D::Error>> {
let mut data = self.data.try_borrow_mut().map_err(|_| Error::LockError)?;
let data = data.deref_mut();

for f in data.open_files.iter() {
if f.raw_volume == volume {
Expand All @@ -349,6 +350,12 @@ where

let volume_idx = data.get_volume_by_id(volume)?;

match &mut data.open_volumes[volume_idx].volume_type {
VolumeType::Fat(fat) => {
fat.update_info_sector(&mut data.block_cache)?;
},
}

data.open_volumes.swap_remove(volume_idx);

Ok(())
Expand Down

0 comments on commit c2341ac

Please sign in to comment.