pub struct Card<B: Block> { /* private fields */ }Expand description
A memory card with the standard PS1 filesystem on top of a Block device.
Implementations§
Source§impl<B: Block> Card<B>
impl<B: Block> Card<B>
Sourcepub fn is_formatted(&mut self) -> Result<bool>
pub fn is_formatted(&mut self) -> Result<bool>
True if the card carries the MC directory header.
Sourcepub fn validate_filesystem(&mut self) -> Result<()>
pub fn validate_filesystem(&mut self) -> Result<()>
Validate the directory before a safety-critical write.
This checks the MC header, every directory-sector checksum, every
allocation state and link, rejects loops/cross-links and orphan
continuation blocks, and requires each first entry’s file size to
equal its allocated chain in 8 KiB units as required by the Sony BIOS.
It performs no writes.
Sourcepub fn format(&mut self) -> Result<()>
pub fn format(&mut self) -> Result<()>
Lay down a fresh, empty directory (byte-identical to a BIOS format’s system area). Data blocks are left as-is; the directory marks them free.
Sourcepub fn free_blocks(&mut self) -> Result<usize>
pub fn free_blocks(&mut self) -> Result<usize>
Number of free 8 KiB blocks.
Sourcepub fn list(&mut self, out: &mut [Entry]) -> Result<usize>
pub fn list(&mut self, out: &mut [Entry]) -> Result<usize>
List all files. Returns the number written to out (capped at its len).
Sourcepub fn delete(&mut self, name: &str) -> Result<()>
pub fn delete(&mut self, name: &str) -> Result<()>
Delete name, freeing its blocks. Ok(()) even if it did not exist.
Sourcepub fn write(&mut self, name: &str, title: &str, data: &[u8]) -> Result<()>
pub fn write(&mut self, name: &str, title: &str, data: &[u8]) -> Result<()>
Write a save (uncompressed), replacing any existing file of the same
name. The old save stays on the card until the new one is complete, so a
failed or interrupted write leaves it readable; the price is that the
card needs room for both copies at once, and a write that does not fit
returns Error::NoSpace without touching the card. name is the BIOS file name (product code + label, <= 20 ASCII);
title is the human-readable label shown by the card manager (<= 32
ASCII).
Sourcepub fn write_with_icon(
&mut self,
name: &str,
title: &str,
data: &[u8],
icon: &SaveIcon,
) -> Result<()>
pub fn write_with_icon( &mut self, name: &str, title: &str, data: &[u8], icon: &SaveIcon, ) -> Result<()>
Write an uncompressed save with a caller-supplied native 16×16 icon.
Sourcepub fn write_compressed(
&mut self,
name: &str,
title: &str,
data: &[u8],
scratch: &mut [u8],
) -> Result<()>
pub fn write_compressed( &mut self, name: &str, title: &str, data: &[u8], scratch: &mut [u8], ) -> Result<()>
Write a save, compressing the payload with LZSS when it helps. scratch
receives the compressor output and must be at least data.len() bytes;
if compression does not shrink the data, it is stored as-is.
Sourcepub fn read(&mut self, name: &str, buf: &mut [u8]) -> Result<usize>
pub fn read(&mut self, name: &str, buf: &mut [u8]) -> Result<usize>
Read a save into buf. Returns the payload length. Transparently
decompresses if the save was written with Card::write_compressed
(requires the compress feature).
Source§impl<B: Block> Card<B>
impl<B: Block> Card<B>
Sourcepub fn new(dev: B) -> Self
pub fn new(dev: B) -> Self
Wrap a block device. Does no I/O; call Card::is_formatted /
Card::format as needed.
Sourcepub fn into_inner(self) -> B
pub fn into_inner(self) -> B
Recover the underlying block device.