]>
git.proxmox.com Git - proxmox-backup.git/blob - pbs-tape/src/tape_write.rs
1 use endian_trait
::Endian
;
3 use crate::MediaContentHeader
;
5 /// Write trait for tape devices
7 /// The 'write_all' function returns if the drive reached the Logical
8 /// End Of Media (early warning).
10 /// It is mandatory to call 'finish' before closing the stream to mark it
11 /// as correctly written.
13 /// Please note that there is no flush method. Tapes flush there internal
14 /// buffer when they write an EOF marker.
16 /// writes all data, returns true on LEOM
17 fn write_all(&mut self, data
: &[u8]) -> Result
<bool
, std
::io
::Error
>;
19 /// Returns how many bytes (raw data on tape) have been written
20 fn bytes_written(&self) -> usize;
22 /// flush last block, write file end mark
24 /// The incomplete flag is used to mark multivolume stream.
25 fn finish(&mut self, incomplete
: bool
) -> Result
<bool
, std
::io
::Error
>;
27 /// Returns true if the writer already detected the logical end of media
28 fn logical_end_of_media(&self) -> bool
;
30 /// writes header and data, returns true on LEOM
33 header
: &MediaContentHeader
,
35 ) -> Result
<bool
, std
::io
::Error
> {
36 if header
.size
as usize != data
.len() {
37 proxmox_sys
::io_bail
!("write_header with wrong size - internal error");
39 let header
= header
.to_le();
41 let res
= self.write_all(unsafe { std
::slice
::from_raw_parts(
42 &header
as *const MediaContentHeader
as *const u8,
43 std
::mem
::size_of
::<MediaContentHeader
>(),
46 if data
.is_empty() { return Ok(res); }
52 /// Write streams of blocks
53 pub trait BlockWrite
{
54 /// Write a data block
56 /// Returns true if the drive reached the Logical End Of Media
58 fn write_block(&mut self, buffer
: &[u8]) -> Result
<bool
, std
::io
::Error
>;
61 fn write_filemark(&mut self) -> Result
<(), std
::io
::Error
>;