Fix formatting

Immprovements by hand + rustfmt
This commit is contained in:
Rafał Harabień 2018-10-10 21:26:31 +02:00
parent 83b5971045
commit 1724a54536
6 changed files with 50 additions and 22 deletions

View File

@ -473,7 +473,9 @@ pub struct DirIter<'a, T: ReadWriteSeek + 'a> {
impl<'a, T: ReadWriteSeek> DirIter<'a, T> {
fn new(stream: DirRawStream<'a, T>, fs: &'a FileSystem<T>, skip_volume: bool) -> Self {
DirIter {
stream, fs, skip_volume,
stream,
fs,
skip_volume,
err: false,
}
}

View File

@ -158,8 +158,7 @@ impl DirFileEntryData {
}
pub(crate) fn first_cluster(&self, fat_type: FatType) -> Option<u32> {
let first_cluster_hi =
if fat_type == FatType::Fat32 { self.first_cluster_hi } else { 0 };
let first_cluster_hi = if fat_type == FatType::Fat32 { self.first_cluster_hi } else { 0 };
let n = ((first_cluster_hi as u32) << 16) | self.first_cluster_lo as u32;
if n == 0 {
None

View File

@ -305,11 +305,13 @@ impl<'a, T: ReadWriteSeek> Seek for File<'a, T> {
SeekFrom::Current(x) => self.offset as i64 + x,
SeekFrom::Start(x) => x as i64,
SeekFrom::End(x) => {
self.entry
let size = self
.entry
.iter()
.next()
.map_or(None, |e| e.inner().size())
.expect("cannot seek from end if size is unknown") as i64 + x
.expect("cannot seek from end if size is unknown") as i64;
size + x
},
};
if new_pos < 0 {

View File

@ -176,11 +176,13 @@ impl BiosParameterBlock {
Ok(bpb)
}
fn validate(&self) -> io::Result<()> {
// sanity checks
if self.bytes_per_sector.count_ones() != 1 {
return Err(Error::new(ErrorKind::Other, "invalid bytes_per_sector value in BPB (not power of two)"));
return Err(Error::new(
ErrorKind::Other,
"invalid bytes_per_sector value in BPB (not power of two)",
));
} else if self.bytes_per_sector < 512 {
return Err(Error::new(ErrorKind::Other, "invalid bytes_per_sector value in BPB (value < 512)"));
} else if self.bytes_per_sector > 4096 {
@ -188,11 +190,17 @@ impl BiosParameterBlock {
}
if self.sectors_per_cluster.count_ones() != 1 {
return Err(Error::new(ErrorKind::Other, "invalid sectors_per_cluster value in BPB (not power of two)"));
return Err(Error::new(
ErrorKind::Other,
"invalid sectors_per_cluster value in BPB (not power of two)",
));
} else if self.sectors_per_cluster < 1 {
return Err(Error::new(ErrorKind::Other, "invalid sectors_per_cluster value in BPB (value < 1)"));
} else if self.sectors_per_cluster > 128 {
return Err(Error::new(ErrorKind::Other, "invalid sectors_per_cluster value in BPB (value > 128)"));
return Err(Error::new(
ErrorKind::Other,
"invalid sectors_per_cluster value in BPB (value > 128)",
));
}
// bytes per sector is u16, sectors per cluster is u8, so guaranteed no overflow in multiplication
@ -211,16 +219,20 @@ impl BiosParameterBlock {
return Err(Error::new(ErrorKind::Other, "invalid reserved_sectors value in BPB"));
} else if !self.is_fat32() && self.reserved_sectors != 1 {
// Microsoft document indicates fat12 and fat16 code exists that presume this value is 1
warn!("fs compatibility: reserved_sectors value '{}' in BPB is not '1', and thus is incompatible with some implementations",
self.reserved_sectors);
warn!(
"fs compatibility: reserved_sectors value '{}' in BPB is not '1', and thus is incompatible with some implementations",
self.reserved_sectors
);
}
if self.fats == 0 {
return Err(Error::new(ErrorKind::Other, "invalid fats value in BPB"));
} else if self.fats > 2 {
// Microsoft document indicates that few implementations support any values other than 1 or 2
warn!("fs compatibility: numbers of FATs '{}' in BPB is greater than '2', and thus is incompatible with some implementations",
self.fats);
warn!(
"fs compatibility: numbers of FATs '{}' in BPB is greater than '2', and thus is incompatible with some implementations",
self.fats
);
}
if self.fs_version != 0 {
@ -387,13 +399,19 @@ impl FsInfoSector {
let max_valid_cluster_number = total_clusters + RESERVED_FAT_ENTRIES;
if let Some(n) = self.free_cluster_count {
if n > total_clusters {
warn!("invalid free_cluster_count ({}) in fs_info exceeds total cluster count ({})", n, total_clusters);
warn!(
"invalid free_cluster_count ({}) in fs_info exceeds total cluster count ({})",
n, total_clusters
);
self.free_cluster_count = None;
}
}
if let Some(n) = self.next_free_cluster {
if n > max_valid_cluster_number {
warn!("invalid free_cluster_count ({}) in fs_info exceeds maximum cluster number ({})", n, max_valid_cluster_number);
warn!(
"invalid free_cluster_count ({}) in fs_info exceeds maximum cluster number ({})",
n, max_valid_cluster_number
);
self.next_free_cluster = None;
}
}

View File

@ -1,6 +1,6 @@
use io;
use byteorder::LittleEndian;
use byteorder_ext::{ReadBytesExt, WriteBytesExt};
use io;
use fs::{FatType, FsStatusFlags, ReadSeek, ReadWriteSeek};
@ -280,7 +280,10 @@ impl FatTrait for Fat32 {
Ok(match val {
0 if cluster >= 0x0FFFFFF7 && cluster <= 0x0FFFFFFF => {
let tmp = if cluster == 0x0FFFFFF7 { "BAD_CLUSTER" } else { "end-of-chain" };
warn!("cluster number {} is a special value in FAT to indicate {}; it should never be seen as free", cluster, tmp);
warn!(
"cluster number {} is a special value in FAT to indicate {}; it should never be seen as free",
cluster, tmp
);
FatValue::Bad // avoid accidental use or allocation into a FAT chain
},
0 => FatValue::Free,
@ -304,7 +307,10 @@ impl FatTrait for Fat32 {
// or even have them all store value '4' as their next cluster.
// Some believe only FatValue::Bad should be allowed for this edge case.
let tmp = if cluster == 0x0FFFFFF7 { "BAD_CLUSTER" } else { "end-of-chain" };
panic!("cluster number {} is a special value in FAT to indicate {}; it should never be set as free", cluster, tmp);
panic!(
"cluster number {} is a special value in FAT to indicate {}; it should never be set as free",
cluster, tmp
);
};
let raw_val = match value {
FatValue::Free => 0,

View File

@ -39,10 +39,11 @@ fn open_filesystem_rw(tmp_path: &str) -> FileSystem {
}
fn call_with_fs(f: &Fn(FileSystem) -> (), filename: &str, test_seq: u32) {
call_with_tmp_img(&|tmp_path| {
let callback = |tmp_path: &str| {
let fs = open_filesystem_rw(tmp_path);
f(fs);
}, filename, test_seq);
};
call_with_tmp_img(&callback, filename, test_seq);
}
fn test_write_short_file(fs: FileSystem) {