tape: BlockedReader - always consume EOF

This commit is contained in:
Dietmar Maurer 2021-02-03 13:15:18 +01:00
parent 04cec92e8d
commit 7d2c156eb1

View File

@ -49,16 +49,21 @@ impl <R: Read> BlockedReader<R> {
let (_size, found_end_marker) = Self::check_buffer(&buffer, 0)?; let (_size, found_end_marker) = Self::check_buffer(&buffer, 0)?;
let mut incomplete = false; let mut incomplete = false;
let mut got_eod = false;
if found_end_marker { if found_end_marker {
incomplete = buffer.flags.contains(BlockHeaderFlags::INCOMPLETE); incomplete = buffer.flags.contains(BlockHeaderFlags::INCOMPLETE);
Self::consume_eof_marker(&mut reader)?;
got_eod = true;
} }
Ok(Some(Self { Ok(Some(Self {
reader, reader,
buffer, buffer,
found_end_marker, found_end_marker,
incomplete, incomplete,
got_eod,
seq_nr: 1, seq_nr: 1,
got_eod: false,
read_error: false, read_error: false,
read_pos: 0, read_pos: 0,
})) }))
@ -101,6 +106,14 @@ impl <R: Read> BlockedReader<R> {
tape_device_read_block(reader, data) tape_device_read_block(reader, data)
} }
fn consume_eof_marker(reader: &mut R) -> Result<(), std::io::Error> {
let mut tmp_buf = [0u8; 512]; // use a small buffer for testing EOF
if tape_device_read_block(reader, &mut tmp_buf)? {
proxmox::io_bail!("detected tape block after stream end marker");
}
Ok(())
}
fn read_block(&mut self) -> Result<usize, std::io::Error> { fn read_block(&mut self) -> Result<usize, std::io::Error> {
if !Self::read_block_frame(&mut self.buffer, &mut self.reader)? { if !Self::read_block_frame(&mut self.buffer, &mut self.reader)? {
@ -118,12 +131,8 @@ impl <R: Read> BlockedReader<R> {
if found_end_marker { // consume EOF mark if found_end_marker { // consume EOF mark
self.found_end_marker = true; self.found_end_marker = true;
self.incomplete = self.buffer.flags.contains(BlockHeaderFlags::INCOMPLETE); self.incomplete = self.buffer.flags.contains(BlockHeaderFlags::INCOMPLETE);
let mut tmp_buf = [0u8; 512]; // use a small buffer for testing EOF Self::consume_eof_marker(&mut self.reader)?;
if tape_device_read_block(&mut self.reader, &mut tmp_buf)? { self.got_eod = true;
proxmox::io_bail!("detected tape block after stream end marker");
} else {
self.got_eod = true;
}
} }
self.read_pos = 0; self.read_pos = 0;