tape: improve EOT error handling

This commit is contained in:
Dietmar Maurer
2021-04-12 11:25:40 +02:00
parent 164ad7b706
commit 318b310638
10 changed files with 152 additions and 116 deletions

View File

@ -4,7 +4,7 @@ use proxmox::tools::io::ReadExt;
use crate::tape::{
BlockRead,
BlockReadStatus,
BlockReadError,
file_formats::PROXMOX_TAPE_BLOCK_SIZE,
};
@ -24,22 +24,27 @@ impl <R: Read> EmulateTapeReader<R> {
}
impl <R: Read> BlockRead for EmulateTapeReader<R> {
fn read_block(&mut self, buffer: &mut [u8]) -> Result<BlockReadStatus, std::io::Error> {
fn read_block(&mut self, buffer: &mut [u8]) -> Result<usize, BlockReadError> {
if self.got_eof {
proxmox::io_bail!("detected read after EOF!");
return Err(BlockReadError::Error(proxmox::io_format_err!("detected read after EOF!")));
}
match self.reader.read_exact_or_eof(buffer)? {
false => {
self.got_eof = true;
Ok(BlockReadStatus::EndOfFile)
Err(BlockReadError::EndOfFile)
}
true => {
// test buffer len after EOF test (to allow EOF test with small buffers in BufferedReader)
if buffer.len() != PROXMOX_TAPE_BLOCK_SIZE {
proxmox::io_bail!("EmulateTapeReader: read_block with wrong block size ({} != {})",
buffer.len(), PROXMOX_TAPE_BLOCK_SIZE);
return Err(BlockReadError::Error(
proxmox::io_format_err!(
"EmulateTapeReader: read_block with wrong block size ({} != {})",
buffer.len(),
PROXMOX_TAPE_BLOCK_SIZE,
)
));
}
Ok(BlockReadStatus::Ok(buffer.len()))
Ok(buffer.len())
}
}
}