Rename directory entry flags and add some internal docs

This commit is contained in:
Rafał Harabień 2018-06-25 00:22:34 +02:00
parent f9ca0f95ce
commit cd7e77e1b4
2 changed files with 30 additions and 23 deletions

View File

@ -280,7 +280,7 @@ impl <'a, T: ReadWriteSeek + 'a> Dir<'a, T> {
for _ in 0..num { for _ in 0..num {
let mut data = DirEntryData::deserialize(&mut stream)?; let mut data = DirEntryData::deserialize(&mut stream)?;
trace!("removing dir entry {:?}", data); trace!("removing dir entry {:?}", data);
data.set_free(); data.set_deleted();
stream.seek(SeekFrom::Current(-(DIR_ENTRY_SIZE as i64)))?; stream.seek(SeekFrom::Current(-(DIR_ENTRY_SIZE as i64)))?;
data.serialize(&mut stream)?; data.serialize(&mut stream)?;
} }
@ -335,7 +335,7 @@ impl <'a, T: ReadWriteSeek + 'a> Dir<'a, T> {
for _ in 0..num { for _ in 0..num {
let mut data = DirEntryData::deserialize(&mut stream)?; let mut data = DirEntryData::deserialize(&mut stream)?;
trace!("removing LFN entry {:?}", data); trace!("removing LFN entry {:?}", data);
data.set_free(); data.set_deleted();
stream.seek(SeekFrom::Current(-(DIR_ENTRY_SIZE as i64)))?; stream.seek(SeekFrom::Current(-(DIR_ENTRY_SIZE as i64)))?;
data.serialize(&mut stream)?; 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))?; stream.seek(io::SeekFrom::Start(first_free as u64 * DIR_ENTRY_SIZE))?;
return Ok(stream); 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 // free entry - calculate number of free entries in a row
if num_free == 0 { if num_free == 0 {
first_free = i; first_free = i;
@ -470,7 +470,7 @@ impl <'a, T: ReadWriteSeek> DirIter<'a, T> {
return Ok(None); return Ok(None);
} }
// Check if this is deleted or volume ID entry // 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")] #[cfg(feature = "alloc")]
lfn_buf.clear(); lfn_buf.clear();
begin_offset = offset; begin_offset = offset;
@ -495,7 +495,7 @@ impl <'a, T: ReadWriteSeek> DirIter<'a, T> {
}, },
DirEntryData::Lfn(data) => { DirEntryData::Lfn(data) => {
// Check if this is deleted entry // Check if this is deleted entry
if data.is_free() { if data.is_deleted() {
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
lfn_buf.clear(); lfn_buf.clear();
begin_offset = offset; begin_offset = offset;

View File

@ -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_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_LAST_FLAG: u8 = 0x40;
pub(crate) const LFN_ENTRY_REALLY_E5_FLAG: u8 = 0x05;
/// Decoded file short name /// Decoded file short name
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
@ -66,7 +73,7 @@ impl ShortName {
name_len name_len
}; };
// FAT encodes character 0xE5 as 0x05 because 0xE5 marks deleted files // 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; name[0] = 0xE5;
} }
// Short names in FAT filesystem are encoded in OEM code-page // Short names in FAT filesystem are encoded in OEM code-page
@ -272,12 +279,12 @@ impl DirFileEntryData {
Ok(()) Ok(())
} }
pub(crate) fn is_free(&self) -> bool { pub(crate) fn is_deleted(&self) -> bool {
self.name[0] == DIR_ENTRY_FREE_FLAG self.name[0] == DIR_ENTRY_DELETED_FLAG
} }
pub(crate) fn set_free(&mut self) { pub(crate) fn set_deleted(&mut self) {
self.name[0] = DIR_ENTRY_FREE_FLAG; self.name[0] = DIR_ENTRY_DELETED_FLAG;
} }
pub(crate) fn is_end(&self) -> bool { pub(crate) fn is_end(&self) -> bool {
@ -352,12 +359,12 @@ impl DirLfnEntryData {
self.checksum self.checksum
} }
pub(crate) fn is_free(&self) -> bool { pub(crate) fn is_deleted(&self) -> bool {
self.order == DIR_ENTRY_FREE_FLAG self.order == DIR_ENTRY_DELETED_FLAG
} }
pub(crate) fn set_free(&mut self) { pub(crate) fn set_deleted(&mut self) {
self.order = DIR_ENTRY_FREE_FLAG; self.order = DIR_ENTRY_DELETED_FLAG;
} }
pub(crate) fn is_end(&self) -> bool { 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 { match self {
&DirEntryData::File(ref file) => file.is_free(), &DirEntryData::File(ref file) => file.is_deleted(),
&DirEntryData::Lfn(ref lfn) => lfn.is_free(), &DirEntryData::Lfn(ref lfn) => lfn.is_deleted(),
} }
} }
pub(crate) fn set_free(&mut self) { pub(crate) fn set_deleted(&mut self) {
match self { match self {
&mut DirEntryData::File(ref mut file) => file.set_free(), &mut DirEntryData::File(ref mut file) => file.set_deleted(),
&mut DirEntryData::Lfn(ref mut lfn) => lfn.set_free(), &mut DirEntryData::Lfn(ref mut lfn) => lfn.set_deleted(),
} }
} }