Compare commits
5 commits
99bb1e25c2
...
b96805c1c4
| Author | SHA1 | Date | |
|---|---|---|---|
| b96805c1c4 | |||
| 56871201dd | |||
| 1bfd7d3ba5 | |||
| 1785c0e7dd | |||
| 905d8a61cc |
3 changed files with 55 additions and 8 deletions
|
|
@ -250,12 +250,8 @@ impl Bpb {
|
|||
|
||||
/// first data sector
|
||||
pub fn first_data_sector(&self) -> u32 {
|
||||
println!("reserved sectors: {}", self.reserved_sector_count());
|
||||
println!("fat sectors: {}", self.num_fats() as u32 * self.fat_size());
|
||||
println!("root dir sectors: {}", self.root_dir_sectors());
|
||||
|
||||
self.reserved_sector_count() as u32
|
||||
+ (self.num_fats() as u32 + self.fat_size())
|
||||
+ (self.num_fats() as u32 * self.fat_size())
|
||||
+ self.root_dir_sectors() as u32
|
||||
}
|
||||
|
||||
|
|
|
|||
38
src/dir.rs
38
src/dir.rs
|
|
@ -24,6 +24,27 @@ bitflags! {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for Attr {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut if_has_attr = |attr: Attr, c: char| {
|
||||
if self.contains(attr) {
|
||||
write!(f, "{}", c)
|
||||
} else {
|
||||
write!(f, "-")
|
||||
}
|
||||
};
|
||||
|
||||
if_has_attr(Attr::ReadOnly, 'R')?;
|
||||
if_has_attr(Attr::Hidden, 'H')?;
|
||||
if_has_attr(Attr::System, 'S')?;
|
||||
if_has_attr(Attr::VolumeId, 'V')?;
|
||||
if_has_attr(Attr::Directory, 'D')?;
|
||||
if_has_attr(Attr::Archive, 'A')?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RegularDirEntry {
|
||||
name: [u8; 11],
|
||||
|
|
@ -55,10 +76,11 @@ impl Display for RegularDirEntry {
|
|||
|
||||
write!(
|
||||
f,
|
||||
"DirEntry {{ {: <16} created: {} modified: {} }}",
|
||||
"DirEntry {{ {} {: <16} created: {} modified: {} }}",
|
||||
self.attr,
|
||||
name,
|
||||
self.create_time(),
|
||||
self.write_time()
|
||||
self.create_time().format("%a %b %d %H:%M:%S%.3f %Y"),
|
||||
self.write_time().format("%a %b %d %H:%M:%S%.3f %Y")
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
|
|
@ -135,6 +157,16 @@ impl RegularDirEntry {
|
|||
self.name[0] == 0x00
|
||||
}
|
||||
|
||||
pub fn is_file(&self) -> bool {
|
||||
!self
|
||||
.attr
|
||||
.intersects(Attr::Directory | Attr::System | Attr::VolumeId)
|
||||
}
|
||||
|
||||
pub fn is_dir(&self) -> bool {
|
||||
self.attr.contains(Attr::Directory) && !self.attr.intersects(Attr::System | Attr::VolumeId)
|
||||
}
|
||||
|
||||
pub fn name(&self) -> &[u8] {
|
||||
&self.name
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use std::fmt::Debug;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use crate::{FatFs, SliceLike};
|
||||
|
|
@ -9,6 +10,15 @@ pub struct SubSliceMut<'a, S: SliceLike> {
|
|||
len: usize,
|
||||
}
|
||||
|
||||
impl<S: SliceLike> Debug for SubSliceMut<'_, S> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("SubSliceMut")
|
||||
.field("offset", &self.offset)
|
||||
.field("len", &self.len)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: SliceLike> SubSliceMut<'_, S> {
|
||||
pub fn new(fat_fs: &mut FatFs<S>, offset: u64, len: usize) -> SubSliceMut<'_, S> {
|
||||
SubSliceMut {
|
||||
|
|
@ -70,6 +80,15 @@ pub struct SubSlice<'a, S: SliceLike> {
|
|||
len: usize,
|
||||
}
|
||||
|
||||
impl<S: SliceLike> Debug for SubSlice<'_, S> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("SubSliceMut")
|
||||
.field("offset", &self.offset)
|
||||
.field("len", &self.len)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: SliceLike> SubSlice<'_, S> {
|
||||
pub fn new(fat_fs: &mut FatFs<S>, offset: u64, len: usize) -> SubSlice<'_, S> {
|
||||
SubSlice {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue