Skip to content

Commit 6ec1aa4

Browse files
committed
Move functions into impl blocks.
1 parent 7f4aa0c commit 6ec1aa4

File tree

1 file changed

+32
-40
lines changed

1 file changed

+32
-40
lines changed

src/fs.rs

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl<IO: Read + Write + Seek, TP, OCC> FileSystem<IO, TP, OCC> {
410410
if options.ignore_dirty_flag {
411411
warn!("BPB is dirty, clearing dirty flag.");
412412
bpb_status_flags.dirty = false;
413-
write_bpb_status_flags(&mut disk, fat_type, bpb_status_flags)?;
413+
Self::write_bpb_status_flags(&mut disk, fat_type, bpb_status_flags)?;
414414
bpb.set_status_flags(bpb_status_flags);
415415
} else {
416416
return Err(Error::DirtyFileSystem);
@@ -619,10 +619,40 @@ impl<IO: Read + Write + Seek, TP, OCC> FileSystem<IO, TP, OCC> {
619619
Ok(())
620620
}
621621

622+
fn write_bpb_status_flags(
623+
disk: &mut IO,
624+
fat_type: FatType,
625+
status_flags: FsStatusFlags,
626+
) -> Result<(), Error<IO::Error>> {
627+
let encoded = status_flags.encode();
628+
629+
// Note: only one field is written to avoid rewriting entire boot-sector which could be dangerous
630+
// Compute reserver_1 field offset and write new flags
631+
let offset = if fat_type == FatType::Fat32 { 0x041 } else { 0x025 };
632+
633+
disk.seek(io::SeekFrom::Start(offset))?;
634+
disk.write_u8(encoded)?;
635+
636+
Ok(())
637+
}
638+
622639
#[inline]
623640
pub(crate) fn set_dirty_flag(&self, dirty: bool) -> Result<(), Error<IO::Error>> {
624641
let mut disk = self.disk.borrow_mut();
625-
set_dirty_flag(&mut *disk, self.fat_type(), &self.current_status_flags, dirty)
642+
643+
let mut status_flags = self.current_status_flags.get();
644+
645+
if status_flags.dirty == dirty {
646+
// Dirty flag did not change.
647+
return Ok(());
648+
}
649+
650+
status_flags.dirty = dirty;
651+
652+
Self::write_bpb_status_flags(&mut *disk, self.fat_type(), status_flags)?;
653+
self.current_status_flags.set(status_flags);
654+
655+
Ok(())
626656
}
627657

628658
/// Returns a root directory object allowing for futher penetration of a filesystem structure.
@@ -752,44 +782,6 @@ impl<IO: ReadWriteSeek, TP, OCC> Clone for FsIoAdapter<'_, IO, TP, OCC> {
752782
}
753783
}
754784

755-
fn set_dirty_flag<IO: Seek + Write>(
756-
disk: &mut IO,
757-
fat_type: FatType,
758-
current_status_flags: &Cell<FsStatusFlags>,
759-
dirty: bool,
760-
) -> Result<(), Error<IO::Error>> {
761-
let mut status_flags = current_status_flags.get();
762-
763-
if status_flags.dirty == dirty {
764-
// Dirty flag did not change.
765-
return Ok(());
766-
}
767-
768-
status_flags.dirty = dirty;
769-
770-
write_bpb_status_flags(disk, fat_type, status_flags)?;
771-
current_status_flags.set(status_flags);
772-
773-
Ok(())
774-
}
775-
776-
fn write_bpb_status_flags<IO: Seek + Write>(
777-
disk: &mut IO,
778-
fat_type: FatType,
779-
status_flags: FsStatusFlags,
780-
) -> Result<(), Error<IO::Error>> {
781-
let encoded = status_flags.encode();
782-
783-
// Note: only one field is written to avoid rewriting entire boot-sector which could be dangerous
784-
// Compute reserver_1 field offset and write new flags
785-
let offset = if fat_type == FatType::Fat32 { 0x041 } else { 0x025 };
786-
787-
disk.seek(io::SeekFrom::Start(offset))?;
788-
disk.write_u8(encoded)?;
789-
790-
Ok(())
791-
}
792-
793785
fn fat_slice<B: BorrowMut<S>, E, S: ReadWriteSeek>(io: B, bpb: &BiosParameterBlock) -> DiskSlice<B, E, S> {
794786
let sectors_per_fat = bpb.sectors_per_fat();
795787
let mirroring_enabled = bpb.mirroring_enabled();

0 commit comments

Comments
 (0)