forked from M-Labs/rust-fatfs
Rename directory entry flags and add some internal docs
This commit is contained in:
parent
f9ca0f95ce
commit
cd7e77e1b4
10
src/dir.rs
10
src/dir.rs
@ -280,7 +280,7 @@ impl <'a, T: ReadWriteSeek + 'a> Dir<'a, T> {
|
||||
for _ in 0..num {
|
||||
let mut data = DirEntryData::deserialize(&mut stream)?;
|
||||
trace!("removing dir entry {:?}", data);
|
||||
data.set_free();
|
||||
data.set_deleted();
|
||||
stream.seek(SeekFrom::Current(-(DIR_ENTRY_SIZE as i64)))?;
|
||||
data.serialize(&mut stream)?;
|
||||
}
|
||||
@ -335,7 +335,7 @@ impl <'a, T: ReadWriteSeek + 'a> Dir<'a, T> {
|
||||
for _ in 0..num {
|
||||
let mut data = DirEntryData::deserialize(&mut stream)?;
|
||||
trace!("removing LFN entry {:?}", data);
|
||||
data.set_free();
|
||||
data.set_deleted();
|
||||
stream.seek(SeekFrom::Current(-(DIR_ENTRY_SIZE as i64)))?;
|
||||
data.serialize(&mut stream)?;
|
||||
}
|
||||
@ -359,7 +359,7 @@ impl <'a, T: ReadWriteSeek + 'a> Dir<'a, T> {
|
||||
}
|
||||
stream.seek(io::SeekFrom::Start(first_free as u64 * DIR_ENTRY_SIZE))?;
|
||||
return Ok(stream);
|
||||
} else if raw_entry.is_free() {
|
||||
} else if raw_entry.is_deleted() {
|
||||
// free entry - calculate number of free entries in a row
|
||||
if num_free == 0 {
|
||||
first_free = i;
|
||||
@ -470,7 +470,7 @@ impl <'a, T: ReadWriteSeek> DirIter<'a, T> {
|
||||
return Ok(None);
|
||||
}
|
||||
// Check if this is deleted or volume ID entry
|
||||
if data.is_free() || data.is_volume() {
|
||||
if data.is_deleted() || data.is_volume() {
|
||||
#[cfg(feature = "alloc")]
|
||||
lfn_buf.clear();
|
||||
begin_offset = offset;
|
||||
@ -495,7 +495,7 @@ impl <'a, T: ReadWriteSeek> DirIter<'a, T> {
|
||||
},
|
||||
DirEntryData::Lfn(data) => {
|
||||
// Check if this is deleted entry
|
||||
if data.is_free() {
|
||||
if data.is_deleted() {
|
||||
#[cfg(feature = "alloc")]
|
||||
lfn_buf.clear();
|
||||
begin_offset = offset;
|
||||
|
@ -34,11 +34,18 @@ bitflags! {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const LFN_PART_LEN: usize = 13;
|
||||
// Size of single directory entry in bytes
|
||||
pub(crate) const DIR_ENTRY_SIZE: u64 = 32;
|
||||
pub(crate) const DIR_ENTRY_FREE_FLAG: u8 = 0xE5;
|
||||
|
||||
// Directory entry flags available in first byte of the short name
|
||||
pub(crate) const DIR_ENTRY_DELETED_FLAG: u8 = 0xE5;
|
||||
pub(crate) const DIR_ENTRY_REALLY_E5_FLAG: u8 = 0x05;
|
||||
|
||||
// Length in characters of a LFN fragment packed in one directory entry
|
||||
pub(crate) const LFN_PART_LEN: usize = 13;
|
||||
|
||||
// Bit used in order field to mark last LFN entry
|
||||
pub(crate) const LFN_ENTRY_LAST_FLAG: u8 = 0x40;
|
||||
pub(crate) const LFN_ENTRY_REALLY_E5_FLAG: u8 = 0x05;
|
||||
|
||||
/// Decoded file short name
|
||||
#[derive(Clone, Debug, Default)]
|
||||
@ -66,7 +73,7 @@ impl ShortName {
|
||||
name_len
|
||||
};
|
||||
// FAT encodes character 0xE5 as 0x05 because 0xE5 marks deleted files
|
||||
if name[0] == LFN_ENTRY_REALLY_E5_FLAG {
|
||||
if name[0] == DIR_ENTRY_REALLY_E5_FLAG {
|
||||
name[0] = 0xE5;
|
||||
}
|
||||
// Short names in FAT filesystem are encoded in OEM code-page
|
||||
@ -272,12 +279,12 @@ impl DirFileEntryData {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn is_free(&self) -> bool {
|
||||
self.name[0] == DIR_ENTRY_FREE_FLAG
|
||||
pub(crate) fn is_deleted(&self) -> bool {
|
||||
self.name[0] == DIR_ENTRY_DELETED_FLAG
|
||||
}
|
||||
|
||||
pub(crate) fn set_free(&mut self) {
|
||||
self.name[0] = DIR_ENTRY_FREE_FLAG;
|
||||
pub(crate) fn set_deleted(&mut self) {
|
||||
self.name[0] = DIR_ENTRY_DELETED_FLAG;
|
||||
}
|
||||
|
||||
pub(crate) fn is_end(&self) -> bool {
|
||||
@ -352,12 +359,12 @@ impl DirLfnEntryData {
|
||||
self.checksum
|
||||
}
|
||||
|
||||
pub(crate) fn is_free(&self) -> bool {
|
||||
self.order == DIR_ENTRY_FREE_FLAG
|
||||
pub(crate) fn is_deleted(&self) -> bool {
|
||||
self.order == DIR_ENTRY_DELETED_FLAG
|
||||
}
|
||||
|
||||
pub(crate) fn set_free(&mut self) {
|
||||
self.order = DIR_ENTRY_FREE_FLAG;
|
||||
pub(crate) fn set_deleted(&mut self) {
|
||||
self.order = DIR_ENTRY_DELETED_FLAG;
|
||||
}
|
||||
|
||||
pub(crate) fn is_end(&self) -> bool {
|
||||
@ -428,17 +435,17 @@ impl DirEntryData {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_free(&self) -> bool {
|
||||
pub(crate) fn is_deleted(&self) -> bool {
|
||||
match self {
|
||||
&DirEntryData::File(ref file) => file.is_free(),
|
||||
&DirEntryData::Lfn(ref lfn) => lfn.is_free(),
|
||||
&DirEntryData::File(ref file) => file.is_deleted(),
|
||||
&DirEntryData::Lfn(ref lfn) => lfn.is_deleted(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_free(&mut self) {
|
||||
pub(crate) fn set_deleted(&mut self) {
|
||||
match self {
|
||||
&mut DirEntryData::File(ref mut file) => file.set_free(),
|
||||
&mut DirEntryData::Lfn(ref mut lfn) => lfn.set_free(),
|
||||
&mut DirEntryData::File(ref mut file) => file.set_deleted(),
|
||||
&mut DirEntryData::Lfn(ref mut lfn) => lfn.set_deleted(),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user