Skip to content

Commit cf32701

Browse files
Some clean-ups.
Co-authored-by: Ryan Summers <[email protected]>
1 parent 21aaa88 commit cf32701

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/fat/volume.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl FatVolume {
126126
block_device
127127
.read(&mut blocks, this_fat_block_num, "read_fat")
128128
.map_err(Error::DeviceError)?;
129+
// See <https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system>
129130
let entry = match new_value {
130131
ClusterId::INVALID => 0xFFF6,
131132
ClusterId::BAD => 0xFFF7,

src/volume_mgr.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,21 +273,13 @@ where
273273
/// Close a directory. You cannot perform operations on an open directory
274274
/// and so must close it if you want to do something with it.
275275
pub fn close_dir(&mut self, directory: Directory) -> Result<(), Error<D::Error>> {
276-
let mut found_idx = None;
277276
for (idx, info) in self.open_dirs.iter().enumerate() {
278277
if directory == info.directory_id {
279-
found_idx = Some(idx);
280-
break;
281-
}
282-
}
283-
284-
match found_idx {
285-
None => Err(Error::BadHandle),
286-
Some(idx) => {
287278
self.open_dirs.swap_remove(idx);
288-
Ok(())
279+
return Ok(());
289280
}
290281
}
282+
Err(Error::BadHandle)
291283
}
292284

293285
/// Close a volume
@@ -357,6 +349,7 @@ where
357349
dir_entry: DirEntry,
358350
mode: Mode,
359351
) -> Result<File, Error<D::Error>> {
352+
// This check is load-bearing - we do an unchecked push later.
360353
if self.open_files.is_full() {
361354
return Err(Error::TooManyOpenFiles);
362355
}
@@ -449,6 +442,7 @@ where
449442
where
450443
N: ToShortFileName,
451444
{
445+
// This check is load-bearing - we do an unchecked push later.
452446
if self.open_files.is_full() {
453447
return Err(Error::TooManyOpenFiles);
454448
}
@@ -524,7 +518,7 @@ where
524518
dirty: false,
525519
};
526520

527-
// Remember this open file
521+
// Remember this open file - can't be full as we checked already
528522
unsafe {
529523
self.open_files.push_unchecked(file);
530524
}

0 commit comments

Comments
 (0)