Skip to content

Commit 21aaa88

Browse files
Check file match by dir entry not by starting cluster.
This is because some files have no starting cluster and thus look like the same file when they are not. Fixes #75
1 parent 457de81 commit 21aaa88

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/fat/volume.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl FatVolume {
320320
let entry = DirEntry::new(
321321
name,
322322
attributes,
323-
ClusterId(0),
323+
ClusterId::EMPTY,
324324
ctime,
325325
block,
326326
start as u32,

src/volume_mgr.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ where
370370
}
371371

372372
// Check it's not already open
373-
if self.file_is_open(volume, dir_entry.cluster) {
373+
if self.file_is_open(volume, &dir_entry) {
374374
return Err(Error::FileAlreadyOpen);
375375
}
376376

@@ -488,7 +488,7 @@ where
488488

489489
// Check if it's open already
490490
if let Some(dir_entry) = &dir_entry {
491-
if self.file_is_open(volume_info.volume_id, dir_entry.cluster) {
491+
if self.file_is_open(volume_info.volume_id, &dir_entry) {
492492
return Err(Error::FileAlreadyOpen);
493493
}
494494
}
@@ -562,7 +562,7 @@ where
562562
return Err(Error::DeleteDirAsFile);
563563
}
564564

565-
if self.file_is_open(dir_info.volume_id, dir_entry.cluster) {
565+
if self.file_is_open(dir_info.volume_id, &dir_entry) {
566566
return Err(Error::FileAlreadyOpen);
567567
}
568568

@@ -579,9 +579,12 @@ where
579579
/// Check if a file is open
580580
///
581581
/// Returns `true` if it's open, `false`, otherwise.
582-
fn file_is_open(&self, volume: Volume, starting_cluster: ClusterId) -> bool {
582+
fn file_is_open(&self, volume: Volume, dir_entry: &DirEntry) -> bool {
583583
for f in self.open_files.iter() {
584-
if f.volume_id == volume && f.entry.cluster == starting_cluster {
584+
if f.volume_id == volume
585+
&& f.entry.entry_block == dir_entry.entry_block
586+
&& f.entry.entry_offset == dir_entry.entry_offset
587+
{
585588
return true;
586589
}
587590
}

0 commit comments

Comments
 (0)