diff --git a/src/fat/volume.rs b/src/fat/volume.rs index 321e160..aa6bc4d 100644 --- a/src/fat/volume.rs +++ b/src/fat/volume.rs @@ -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; }; diff --git a/src/volume_mgr.rs b/src/volume_mgr.rs index d8311a6..e31dd1d 100644 --- a/src/volume_mgr.rs +++ b/src/volume_mgr.rs @@ -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> { 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 { @@ -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(())