Skip to content

Commit 7478430

Browse files
Add a csum() method to ShortFileName.
Long File Names carry this checksum of their matching Short File Name.
1 parent 1b9fa5c commit 7478430

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/filesystem/filename.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ impl ShortFileName {
175175
contents: self.contents,
176176
}
177177
}
178+
179+
/// Get the LFN checksum for this short filename
180+
pub fn csum(&self) -> u8 {
181+
let mut result = 0u8;
182+
for b in self.contents.iter() {
183+
result = result.rotate_right(1).wrapping_add(*b);
184+
}
185+
result
186+
}
178187
}
179188

180189
impl core::fmt::Display for ShortFileName {
@@ -302,6 +311,16 @@ mod test {
302311
assert!(ShortFileName::create_from_str("123456789").is_err());
303312
assert!(ShortFileName::create_from_str("12345678.ABCD").is_err());
304313
}
314+
315+
#[test]
316+
fn checksum() {
317+
assert_eq!(
318+
0xB3,
319+
ShortFileName::create_from_str("UNARCH~1.DAT")
320+
.unwrap()
321+
.csum()
322+
);
323+
}
305324
}
306325

307326
// ****************************************************************************

0 commit comments

Comments
 (0)