Skip to content

Commit

Permalink
chore: enable clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Oakchris1955 committed Sep 14, 2024
1 parent 63b0f9b commit 842fce1
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 148 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true
}
},
"rust-analyzer.check.command": "clippy",
}
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub enum InternalFSError {
InvalidBPBSig,
/**
Invalid FAT32 FSInfo signature.
Perhaps the FSInfo structure or the FAT32 EBR's fat_info field is malformed?
Perhaps the FSInfo structure or the FAT32 Ebr's fat_info field is malformed?
*/
InvalidFSInfoSig,
/**
Expand Down
26 changes: 14 additions & 12 deletions src/fat/bpb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use serde::{Deserialize, Serialize};
use serde_big_array::BigArray;

#[derive(Debug)]
#[allow(clippy::large_enum_variant)]
pub(crate) enum BootRecord {
FAT(BootRecordFAT),
Fat(BootRecordFAT),
ExFAT(BootRecordExFAT),
}

Expand All @@ -17,7 +18,7 @@ impl BootRecord {
/// The FAT type of this file system
pub(crate) fn fat_type(&self) -> FATType {
match self {
BootRecord::FAT(boot_record_fat) => boot_record_fat.fat_type(),
BootRecord::Fat(boot_record_fat) => boot_record_fat.fat_type(),
BootRecord::ExFAT(_boot_record_exfat) => {
todo!("ExFAT not yet implemented");
FATType::ExFAT
Expand All @@ -28,7 +29,7 @@ impl BootRecord {
#[allow(non_snake_case)]
pub(crate) fn nth_FAT_table_sector(&self, n: u8) -> u32 {
match self {
BootRecord::FAT(boot_record_fat) => {
BootRecord::Fat(boot_record_fat) => {
boot_record_fat.first_fat_sector() as u32
+ n as u32 * boot_record_fat.fat_sector_size()
}
Expand All @@ -46,20 +47,20 @@ pub(crate) const FAT_SIGNATURE: u16 = 0x55AA;

#[derive(Debug, Clone, Copy)]
pub(crate) struct BootRecordFAT {
pub bpb: BPBFAT,
pub ebr: EBR,
pub bpb: BpbFat,
pub ebr: Ebr,
}

impl BootRecordFAT {
#[inline]
pub(crate) fn verify_signature(&self) -> bool {
match self.fat_type() {
FATType::FAT12 | FATType::FAT16 | FATType::FAT32 => match self.ebr {
EBR::FAT12_16(ebr_fat12_16) => {
Ebr::FAT12_16(ebr_fat12_16) => {
ebr_fat12_16.boot_signature == BOOT_SIGNATURE
&& ebr_fat12_16.signature == FAT_SIGNATURE
}
EBR::FAT32(ebr_fat32, _) => {
Ebr::FAT32(ebr_fat32, _) => {
ebr_fat32.boot_signature == BOOT_SIGNATURE
&& ebr_fat32.signature == FAT_SIGNATURE
}
Expand All @@ -82,8 +83,8 @@ impl BootRecordFAT {
/// FAT size in sectors
pub(crate) fn fat_sector_size(&self) -> u32 {
match self.ebr {
EBR::FAT12_16(_ebr_fat12_16) => self.bpb.table_size_16.into(),
EBR::FAT32(ebr_fat32, _) => ebr_fat32.table_size_32,
Ebr::FAT12_16(_ebr_fat12_16) => self.bpb.table_size_16.into(),
Ebr::FAT32(ebr_fat32, _) => ebr_fat32.table_size_32,
}
}

Expand Down Expand Up @@ -171,7 +172,7 @@ pub(crate) struct BootRecordExFAT {

pub(crate) const BPBFAT_SIZE: usize = 36;
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub(crate) struct BPBFAT {
pub(crate) struct BpbFat {
pub _jmpboot: [u8; 3],
pub _oem_identifier: [u8; 8],
pub bytes_per_sector: u16,
Expand All @@ -191,12 +192,13 @@ pub(crate) struct BPBFAT {

pub(crate) const EBR_SIZE: usize = MIN_SECTOR_SIZE - BPBFAT_SIZE;
#[derive(Clone, Copy)]
pub(crate) enum EBR {
#[allow(clippy::large_enum_variant)]
pub(crate) enum Ebr {
FAT12_16(EBRFAT12_16),
FAT32(EBRFAT32, FSInfoFAT32),
}

impl fmt::Debug for EBR {
impl fmt::Debug for Ebr {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: find a good way of printing this
write!(f, "FAT12-16/32 Extended boot record...")
Expand Down
20 changes: 9 additions & 11 deletions src/fat/direntry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ impl TryFrom<TimeAttribute> for Time {
.with_hour_24(value.hour())
.and_then(|parsed| parsed.with_minute(value.minutes()))
.and_then(|parsed| parsed.with_second(value.seconds() * 2))
.map(|parsed| parsed.try_into().ok())
.flatten()
.and_then(|parsed| parsed.try_into().ok())
.ok_or(())
}
}
Expand All @@ -117,8 +116,7 @@ impl TryFrom<DateAttribute> for Date {
.with_year(i32::from(value.year()) + EPOCH.year())
.and_then(|parsed| parsed.with_month(value.month().try_into().ok()?))
.and_then(|parsed| parsed.with_day(num::NonZeroU8::new(value.day())?))
.map(|parsed| parsed.try_into().ok())
.flatten()
.and_then(|parsed| parsed.try_into().ok())
.ok_or(())
}
}
Expand Down Expand Up @@ -177,7 +175,7 @@ pub(crate) const NONROOT_MIN_DIRENTRIES: usize = 2;

#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub(crate) struct FATDirEntry {
pub(crate) sfn: SFN,
pub(crate) sfn: Sfn,
pub(crate) attributes: RawAttributes,
pub(crate) _reserved: [u8; 1],
pub(crate) created: EntryCreationTime,
Expand All @@ -189,12 +187,12 @@ pub(crate) struct FATDirEntry {
}

#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
pub(crate) struct SFN {
pub(crate) struct Sfn {
name: [u8; 8],
ext: [u8; 3],
}

impl SFN {
impl Sfn {
fn get_byte_slice(&self) -> [u8; 11] {
let mut slice = [0; 11];

Expand All @@ -213,13 +211,13 @@ impl SFN {
.wrapping_add(c)
}

log::debug!("SFN checksum: {:X}", sum);
log::debug!("Sfn checksum: {:X}", sum);

sum
}
}

impl fmt::Display for SFN {
impl fmt::Display for Sfn {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// we begin by writing the name (even if it is padded with spaces, they will be trimmed, so we don't care)
write!(f, "{}", String::from_utf8_lossy(&self.name).trim())?;
Expand All @@ -245,8 +243,8 @@ pub(crate) struct LFNEntry {
pub(crate) _long_entry_type: u8,
/// If this doesn't match with the computed cksum, then the set of LFNs is considered corrupt
///
/// A [`LFNEntry`] will be marked as corrupt even if it isn't, if the SFN is modifed by a legacy system,
/// since the new SFN's signature and the one on this field won't (probably) match
/// A [`LFNEntry`] will be marked as corrupt even if it isn't, if the Sfn is modifed by a legacy system,
/// since the new Sfn's signature and the one on this field won't (probably) match
pub(crate) checksum: u8,
pub(crate) mid_chars: [u8; 12],
pub(crate) _zeroed: [u8; 2],
Expand Down
8 changes: 4 additions & 4 deletions src/fat/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
#[inline]
/// Non-[`panic`]king version of [`next_cluster()`](ROFile::next_cluster)
fn get_next_cluster(&mut self) -> Result<Option<u32>, <Self as IOBase>::Error> {
Ok(self.fs.get_next_cluster(self.props.current_cluster)?)
self.fs.get_next_cluster(self.props.current_cluster)
}

/// Returns that last cluster in the file's cluster chain
Expand All @@ -74,7 +74,7 @@ where
loop {
match self.fs.read_nth_FAT_entry(current_cluster)? {
FATEntry::Allocated(next_cluster) => current_cluster = next_cluster,
FATEntry::EOF => break,
FATEntry::Eof => break,
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -328,7 +328,7 @@ where
// we set the new last cluster in the chain to be EOF
self.ro_file
.fs
.write_nth_FAT_entry(self.ro_file.props.current_cluster, FATEntry::EOF)?;
.write_nth_FAT_entry(self.ro_file.props.current_cluster, FATEntry::Eof)?;

// then, we set each cluster after the current one to EOF
while let Some(next_cluster) = next_cluster_option {
Expand Down Expand Up @@ -507,7 +507,7 @@ where
)?;
// we also set the next free cluster to be EOF
self.fs
.write_nth_FAT_entry(next_free_cluster, FATEntry::EOF)?;
.write_nth_FAT_entry(next_free_cluster, FATEntry::Eof)?;
log::trace!(
"cluster {} now points to {}",
last_cluster_in_chain,
Expand Down
Loading

0 comments on commit 842fce1

Please sign in to comment.