Skip to content

Commit 9418299

Browse files
committed
run cargo fmt
1 parent 870407d commit 9418299

File tree

6 files changed

+220
-130
lines changed

6 files changed

+220
-130
lines changed

src/blockdevice.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ pub trait BlockDevice {
8181
/// The errors that the `BlockDevice` can return. Must be debug formattable.
8282
type Error: core::fmt::Debug;
8383
/// Read one or more blocks, starting at the given block index.
84-
async fn read(&self, blocks: &mut [Block], start_block_idx: BlockIdx) -> Result<(), Self::Error>;
84+
async fn read(
85+
&self,
86+
blocks: &mut [Block],
87+
start_block_idx: BlockIdx,
88+
) -> Result<(), Self::Error>;
8589
/// Write one or more blocks, starting at the given block index.
8690
async fn write(&self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Self::Error>;
8791
/// Determine how many blocks this device can hold.
@@ -136,10 +140,12 @@ where
136140
/// Write back a block you read with [`Self::read_mut`] and then modified.
137141
#[maybe_async::maybe_async]
138142
pub async fn write_back(&mut self) -> Result<(), D::Error> {
139-
self.block_device.write(
140-
&self.block,
141-
self.block_idx.expect("write_back with no read"),
142-
).await
143+
self.block_device
144+
.write(
145+
&self.block,
146+
self.block_idx.expect("write_back with no read"),
147+
)
148+
.await
143149
}
144150

145151
/// Access a blank sector

src/fat/volume.rs

Lines changed: 80 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ impl FatVolume {
179179
}
180180
trace!("Reading info sector");
181181
let block = block_cache
182-
.read_mut(fat32_info.info_location).await
182+
.read_mut(fat32_info.info_location)
183+
.await
183184
.map_err(Error::DeviceError)?;
184185
if let Some(count) = self.free_clusters_count {
185186
block[488..492].copy_from_slice(&count.to_le_bytes());
@@ -221,7 +222,8 @@ impl FatVolume {
221222
let this_fat_ent_offset = (fat_offset % Block::LEN_U32) as usize;
222223
trace!("Reading FAT for update");
223224
let block = block_cache
224-
.read_mut(this_fat_block_num).await
225+
.read_mut(this_fat_block_num)
226+
.await
225227
.map_err(Error::DeviceError)?;
226228
// See <https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system>
227229
let entry = match new_value {
@@ -243,7 +245,8 @@ impl FatVolume {
243245
let this_fat_ent_offset = (fat_offset % Block::LEN_U32) as usize;
244246
trace!("Reading FAT for update");
245247
let block = block_cache
246-
.read_mut(this_fat_block_num).await
248+
.read_mut(this_fat_block_num)
249+
.await
247250
.map_err(Error::DeviceError)?;
248251
let entry = match new_value {
249252
ClusterId::INVALID => 0x0FFF_FFF6,
@@ -408,7 +411,8 @@ impl FatVolume {
408411
for block_idx in first_dir_block_num.range(dir_size) {
409412
trace!("Reading directory");
410413
let block = block_cache
411-
.read_mut(block_idx).await
414+
.read_mut(block_idx)
415+
.await
412416
.map_err(Error::DeviceError)?;
413417
for (i, dir_entry_bytes) in
414418
block.chunks_exact_mut(OnDiskDirEntry::LEN).enumerate()
@@ -440,7 +444,8 @@ impl FatVolume {
440444
Some(n)
441445
}
442446
Err(Error::EndOfFile) => {
443-
let c = self.alloc_cluster(block_cache, Some(cluster), true).await?;
447+
let c =
448+
self.alloc_cluster(block_cache, Some(cluster), true).await?;
444449
first_dir_block_num = self.cluster_to_block(c);
445450
Some(c)
446451
}
@@ -469,7 +474,8 @@ impl FatVolume {
469474
// Read a block of directory entries
470475
trace!("Reading directory");
471476
let block = block_cache
472-
.read_mut(block_idx).await
477+
.read_mut(block_idx)
478+
.await
473479
.map_err(Error::DeviceError)?;
474480
// Are any entries in the block we just loaded blank? If so
475481
// we can use them.
@@ -533,10 +539,12 @@ impl FatVolume {
533539
{
534540
match &self.fat_specific_info {
535541
FatSpecificInfo::Fat16(fat16_info) => {
536-
self.iterate_fat16(dir_info, fat16_info, block_cache, func).await
542+
self.iterate_fat16(dir_info, fat16_info, block_cache, func)
543+
.await
537544
}
538545
FatSpecificInfo::Fat32(fat32_info) => {
539-
self.iterate_fat32(dir_info, fat32_info, block_cache, func).await
546+
self.iterate_fat32(dir_info, fat32_info, block_cache, func)
547+
.await
540548
}
541549
}
542550
}
@@ -624,7 +632,10 @@ impl FatVolume {
624632
let start_block_idx = self.cluster_to_block(cluster);
625633
for block_idx in start_block_idx.range(BlockCount(u32::from(self.blocks_per_cluster))) {
626634
trace!("Reading FAT");
627-
let block = block_cache.read(block_idx).await.map_err(Error::DeviceError)?;
635+
let block = block_cache
636+
.read(block_idx)
637+
.await
638+
.map_err(Error::DeviceError)?;
628639
for (i, dir_entry_bytes) in block.chunks_exact(OnDiskDirEntry::LEN).enumerate() {
629640
let dir_entry = OnDiskDirEntry::new(dir_entry_bytes);
630641
if dir_entry.is_end() {
@@ -679,12 +690,10 @@ impl FatVolume {
679690

680691
while let Some(cluster) = current_cluster {
681692
for block in first_dir_block_num.range(dir_size) {
682-
match self.find_entry_in_block(
683-
block_cache,
684-
FatType::Fat16,
685-
match_name,
686-
block,
687-
).await {
693+
match self
694+
.find_entry_in_block(block_cache, FatType::Fat16, match_name, block)
695+
.await
696+
{
688697
Err(Error::NotFound) => continue,
689698
x => return x,
690699
}
@@ -711,12 +720,10 @@ impl FatVolume {
711720
while let Some(cluster) = current_cluster {
712721
let block_idx = self.cluster_to_block(cluster);
713722
for block in block_idx.range(BlockCount(u32::from(self.blocks_per_cluster))) {
714-
match self.find_entry_in_block(
715-
block_cache,
716-
FatType::Fat32,
717-
match_name,
718-
block,
719-
).await {
723+
match self
724+
.find_entry_in_block(block_cache, FatType::Fat32, match_name, block)
725+
.await
726+
{
720727
Err(Error::NotFound) => continue,
721728
x => return x,
722729
}
@@ -744,7 +751,10 @@ impl FatVolume {
744751
D: BlockDevice,
745752
{
746753
trace!("Reading directory");
747-
let block = block_cache.read(block_idx).await.map_err(Error::DeviceError)?;
754+
let block = block_cache
755+
.read(block_idx)
756+
.await
757+
.map_err(Error::DeviceError)?;
748758
for (i, dir_entry_bytes) in block.chunks_exact(OnDiskDirEntry::LEN).enumerate() {
749759
let dir_entry = OnDiskDirEntry::new(dir_entry_bytes);
750760
if dir_entry.is_end() {
@@ -795,7 +805,10 @@ impl FatVolume {
795805
while let Some(cluster) = current_cluster {
796806
// Scan the cluster / root dir a block at a time
797807
for block_idx in first_dir_block_num.range(dir_size) {
798-
match self.delete_entry_in_block(block_cache, match_name, block_idx).await {
808+
match self
809+
.delete_entry_in_block(block_cache, match_name, block_idx)
810+
.await
811+
{
799812
Err(Error::NotFound) => {
800813
// Carry on
801814
}
@@ -835,7 +848,10 @@ impl FatVolume {
835848
for block_idx in
836849
start_block_idx.range(BlockCount(u32::from(self.blocks_per_cluster)))
837850
{
838-
match self.delete_entry_in_block(block_cache, match_name, block_idx).await {
851+
match self
852+
.delete_entry_in_block(block_cache, match_name, block_idx)
853+
.await
854+
{
839855
Err(Error::NotFound) => {
840856
// Carry on
841857
continue;
@@ -877,7 +893,8 @@ impl FatVolume {
877893
{
878894
trace!("Reading directory");
879895
let block = block_cache
880-
.read_mut(block_idx).await
896+
.read_mut(block_idx)
897+
.await
881898
.map_err(Error::DeviceError)?;
882899
for (i, dir_entry_bytes) in block.chunks_exact_mut(OnDiskDirEntry::LEN).enumerate() {
883900
let dir_entry = OnDiskDirEntry::new(dir_entry_bytes);
@@ -924,7 +941,8 @@ impl FatVolume {
924941
.map_err(|_| Error::ConversionError)?;
925942
trace!("Reading block {:?}", this_fat_block_num);
926943
let block = block_cache
927-
.read(this_fat_block_num).await
944+
.read(this_fat_block_num)
945+
.await
928946
.map_err(Error::DeviceError)?;
929947
while this_fat_ent_offset <= Block::LEN - 2 {
930948
let fat_entry = LittleEndian::read_u16(
@@ -954,7 +972,8 @@ impl FatVolume {
954972
.map_err(|_| Error::ConversionError)?;
955973
trace!("Reading block {:?}", this_fat_block_num);
956974
let block = block_cache
957-
.read(this_fat_block_num).await
975+
.read(this_fat_block_num)
976+
.await
958977
.map_err(Error::DeviceError)?;
959978
while this_fat_ent_offset <= Block::LEN - 4 {
960979
let fat_entry = LittleEndian::read_u32(
@@ -995,7 +1014,9 @@ impl FatVolume {
9951014
start_cluster,
9961015
end_cluster
9971016
);
998-
let new_cluster = match self.find_next_free_cluster(block_cache, start_cluster, end_cluster).await
1017+
let new_cluster = match self
1018+
.find_next_free_cluster(block_cache, start_cluster, end_cluster)
1019+
.await
9991020
{
10001021
Ok(cluster) => cluster,
10011022
Err(_) if start_cluster.0 > RESERVED_ENTRIES => {
@@ -1004,11 +1025,13 @@ impl FatVolume {
10041025
ClusterId(RESERVED_ENTRIES),
10051026
end_cluster
10061027
);
1007-
self.find_next_free_cluster(block_cache, ClusterId(RESERVED_ENTRIES), end_cluster).await?
1028+
self.find_next_free_cluster(block_cache, ClusterId(RESERVED_ENTRIES), end_cluster)
1029+
.await?
10081030
}
10091031
Err(e) => return Err(e),
10101032
};
1011-
self.update_fat(block_cache, new_cluster, ClusterId::END_OF_FILE).await?;
1033+
self.update_fat(block_cache, new_cluster, ClusterId::END_OF_FILE)
1034+
.await?;
10121035
if let Some(cluster) = prev_cluster {
10131036
trace!(
10141037
"Updating old cluster {:?} to {:?} in FAT",
@@ -1022,21 +1045,22 @@ impl FatVolume {
10221045
new_cluster,
10231046
end_cluster
10241047
);
1025-
self.next_free_cluster =
1026-
match self.find_next_free_cluster(block_cache, new_cluster, end_cluster).await {
1027-
Ok(cluster) => Some(cluster),
1028-
Err(_) if new_cluster.0 > RESERVED_ENTRIES => {
1029-
match self.find_next_free_cluster(
1030-
block_cache,
1031-
ClusterId(RESERVED_ENTRIES),
1032-
end_cluster,
1033-
).await {
1034-
Ok(cluster) => Some(cluster),
1035-
Err(e) => return Err(e),
1036-
}
1048+
self.next_free_cluster = match self
1049+
.find_next_free_cluster(block_cache, new_cluster, end_cluster)
1050+
.await
1051+
{
1052+
Ok(cluster) => Some(cluster),
1053+
Err(_) if new_cluster.0 > RESERVED_ENTRIES => {
1054+
match self
1055+
.find_next_free_cluster(block_cache, ClusterId(RESERVED_ENTRIES), end_cluster)
1056+
.await
1057+
{
1058+
Ok(cluster) => Some(cluster),
1059+
Err(e) => return Err(e),
10371060
}
1038-
Err(e) => return Err(e),
1039-
};
1061+
}
1062+
Err(e) => return Err(e),
1063+
};
10401064
debug!("Next free cluster is {:?}", self.next_free_cluster);
10411065
if let Some(ref mut number_free_cluster) = self.free_clusters_count {
10421066
*number_free_cluster -= 1;
@@ -1049,7 +1073,8 @@ impl FatVolume {
10491073
trace!("Zeroing cluster");
10501074
block_cache
10511075
.block_device()
1052-
.write(&blocks, block_idx).await
1076+
.write(&blocks, block_idx)
1077+
.await
10531078
.map_err(Error::DeviceError)?;
10541079
}
10551080
}
@@ -1085,7 +1110,8 @@ impl FatVolume {
10851110
} else {
10861111
self.next_free_cluster = Some(next);
10871112
}
1088-
self.update_fat(block_cache, cluster, ClusterId::END_OF_FILE).await?;
1113+
self.update_fat(block_cache, cluster, ClusterId::END_OF_FILE)
1114+
.await?;
10891115
loop {
10901116
match self.next_cluster(block_cache, next).await {
10911117
Ok(n) => {
@@ -1121,7 +1147,8 @@ impl FatVolume {
11211147
};
11221148
trace!("Reading directory for update");
11231149
let block = block_cache
1124-
.read_mut(entry.entry_block).await
1150+
.read_mut(entry.entry_block)
1151+
.await
11251152
.map_err(Error::DeviceError)?;
11261153

11271154
let start = usize::try_from(entry.entry_offset).map_err(|_| Error::ConversionError)?;
@@ -1146,7 +1173,10 @@ where
11461173
D::Error: core::fmt::Debug,
11471174
{
11481175
trace!("Reading BPB");
1149-
let block = block_cache.read(lba_start).await.map_err(Error::DeviceError)?;
1176+
let block = block_cache
1177+
.read(lba_start)
1178+
.await
1179+
.map_err(Error::DeviceError)?;
11501180
let bpb = Bpb::create_from_bytes(block).map_err(Error::FormatError)?;
11511181
match bpb.fat_type {
11521182
FatType::Fat16 => {
@@ -1208,7 +1238,8 @@ where
12081238
// Now we don't need the BPB, update the volume with data from the info sector
12091239
trace!("Reading info block");
12101240
let info_block = block_cache
1211-
.read(lba_start + info_location).await
1241+
.read(lba_start + info_location)
1242+
.await
12121243
.map_err(Error::DeviceError)?;
12131244
let info_sector =
12141245
InfoSector::create_from_bytes(info_block).map_err(Error::FormatError)?;

src/filesystem/directory.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ where
143143
N: ToShortFileName,
144144
{
145145
self.volume_mgr
146-
.find_directory_entry(self.raw_directory, name).await
146+
.find_directory_entry(self.raw_directory, name)
147+
.await
147148
}
148149

149150
/// Call a callback function for each directory entry in a directory.
@@ -175,7 +176,8 @@ where
175176
{
176177
let f = self
177178
.volume_mgr
178-
.open_file_in_dir(self.raw_directory, name, mode).await?;
179+
.open_file_in_dir(self.raw_directory, name, mode)
180+
.await?;
179181
Ok(f.to_file(self.volume_mgr))
180182
}
181183

@@ -185,7 +187,9 @@ where
185187
where
186188
N: ToShortFileName,
187189
{
188-
self.volume_mgr.delete_file_in_dir(self.raw_directory, name).await
190+
self.volume_mgr
191+
.delete_file_in_dir(self.raw_directory, name)
192+
.await
189193
}
190194

191195
/// Make a directory inside this directory
@@ -194,7 +198,9 @@ where
194198
where
195199
N: ToShortFileName,
196200
{
197-
self.volume_mgr.make_dir_in_dir(self.raw_directory, name).await
201+
self.volume_mgr
202+
.make_dir_in_dir(self.raw_directory, name)
203+
.await
198204
}
199205

200206
/// Convert back to a raw directory

src/filesystem/files.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use crate::{
44
BlockDevice, Error, RawVolume, VolumeManager,
55
};
66

7-
#[cfg(feature="is_sync")]
7+
#[cfg(feature = "is_sync")]
88
use embedded_io::{ErrorType, Read, Seek, SeekFrom, Write};
99

10-
#[cfg(not(feature="is_sync"))]
10+
#[cfg(not(feature = "is_sync"))]
1111
use embedded_io_async::{ErrorType, Read, Seek, SeekFrom, Write};
1212

1313
/// A handle for an open file on disk.

0 commit comments

Comments
 (0)