diff --git a/src/api2/tape/restore.rs b/src/api2/tape/restore.rs index 96fb184d..f045465d 100644 --- a/src/api2/tape/restore.rs +++ b/src/api2/tape/restore.rs @@ -57,7 +57,6 @@ use crate::{ TapeRead, MediaId, MediaCatalog, - ChunkArchiveDecoder, MediaPool, Inventory, file_formats::{ @@ -67,6 +66,7 @@ use crate::{ PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0, PROXMOX_BACKUP_CHUNK_ARCHIVE_MAGIC_1_0, MediaContentHeader, + ChunkArchiveDecoder, }, drive::{ TapeDriver, diff --git a/src/bin/proxmox-tape.rs b/src/bin/proxmox-tape.rs index 8d0157fa..f30d902e 100644 --- a/src/bin/proxmox-tape.rs +++ b/src/bin/proxmox-tape.rs @@ -45,8 +45,8 @@ use proxmox_backup::{ complete_media_set_uuid, file_formats::{ PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0, - PROXMOX_BACKUP_CONTENT_NAME, MediaContentHeader, + proxmox_tape_magic_to_text, }, }, }; @@ -565,7 +565,7 @@ fn debug_scan(param: Value) -> Result<(), Error> { Ok(header) => { if header.magic != PROXMOX_BACKUP_CONTENT_HEADER_MAGIC_1_0 { println!("got MediaContentHeader with wrong magic: {:?}", header.magic); - } else if let Some(name) = PROXMOX_BACKUP_CONTENT_NAME.get(&header.content_magic) { + } else if let Some(name) = proxmox_tape_magic_to_text(&header.content_magic) { println!("got content header: {}", name); println!(" uuid: {}", header.content_uuid()); println!(" ctime: {}", strftime_local("%c", header.ctime)?); diff --git a/src/tape/drive/linux_tape.rs b/src/tape/drive/linux_tape.rs index 4b7684a5..ad8c5e98 100644 --- a/src/tape/drive/linux_tape.rs +++ b/src/tape/drive/linux_tape.rs @@ -40,15 +40,13 @@ use crate::{ }, file_formats::{ PROXMOX_TAPE_BLOCK_SIZE, + PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0, MediaSetLabel, MediaContentHeader, - PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0, - }, - helpers::{ BlockedReader, BlockedWriter, }, - } + }, }; fn run_sg_tape_cmd(subcmd: &str, args: &[&str], fd: RawFd) -> Result { diff --git a/src/tape/drive/virtual_tape.rs b/src/tape/drive/virtual_tape.rs index 7fbc1167..72f7f704 100644 --- a/src/tape/drive/virtual_tape.rs +++ b/src/tape/drive/virtual_tape.rs @@ -30,12 +30,12 @@ use crate::{ MediaSetLabel, MediaContentHeader, PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0, + BlockedReader, + BlockedWriter, }, helpers::{ EmulateTapeReader, EmulateTapeWriter, - BlockedReader, - BlockedWriter, }, }, }; diff --git a/src/tape/helpers/blocked_reader.rs b/src/tape/file_formats/blocked_reader.rs similarity index 100% rename from src/tape/helpers/blocked_reader.rs rename to src/tape/file_formats/blocked_reader.rs diff --git a/src/tape/helpers/blocked_writer.rs b/src/tape/file_formats/blocked_writer.rs similarity index 100% rename from src/tape/helpers/blocked_writer.rs rename to src/tape/file_formats/blocked_writer.rs diff --git a/src/tape/chunk_archive.rs b/src/tape/file_formats/chunk_archive.rs similarity index 100% rename from src/tape/chunk_archive.rs rename to src/tape/file_formats/chunk_archive.rs diff --git a/src/tape/file_formats.rs b/src/tape/file_formats/mod.rs similarity index 92% rename from src/tape/file_formats.rs rename to src/tape/file_formats/mod.rs index 006ccb8b..da71e1cb 100644 --- a/src/tape/file_formats.rs +++ b/src/tape/file_formats/mod.rs @@ -1,4 +1,17 @@ -//! File format definitions for data written to tapes +//! File format definitions and implementations for data written to +//! tapes + +mod blocked_reader; +pub use blocked_reader::*; + +mod blocked_writer; +pub use blocked_writer::*; + +mod chunk_archive; +pub use chunk_archive::*; + +mod snapshot_archive; +pub use snapshot_archive::*; use std::collections::HashMap; @@ -33,8 +46,8 @@ pub const PROXMOX_BACKUP_CHUNK_ARCHIVE_ENTRY_MAGIC_1_0: [u8; 8] = [72, 87, 109, pub const PROXMOX_BACKUP_SNAPSHOT_ARCHIVE_MAGIC_1_0: [u8; 8] = [9, 182, 2, 31, 125, 232, 114, 133]; lazy_static::lazy_static!{ - /// Map content Uuid to human readable names. - pub static ref PROXMOX_BACKUP_CONTENT_NAME: HashMap<&'static [u8;8], &'static str> = { + // Map content magic numbers to human readable names. + static ref PROXMOX_TAPE_CONTENT_NAME: HashMap<&'static [u8;8], &'static str> = { let mut map = HashMap::new(); map.insert(&PROXMOX_BACKUP_MEDIA_LABEL_MAGIC_1_0, "Proxmox Backup Tape Label v1.0"); map.insert(&PROXMOX_BACKUP_MEDIA_SET_LABEL_MAGIC_1_0, "Proxmox Backup MediaSet Label v1.0"); @@ -44,6 +57,11 @@ lazy_static::lazy_static!{ }; } +/// Map content magic numbers to human readable names. +pub fn proxmox_tape_magic_to_text(magic: &[u8; 8]) -> Option { + PROXMOX_TAPE_CONTENT_NAME.get(magic).map(|s| String::from(*s)) +} + /// Tape Block Header with data payload /// /// All tape files are written as sequence of blocks. diff --git a/src/tape/snapshot_archive.rs b/src/tape/file_formats/snapshot_archive.rs similarity index 100% rename from src/tape/snapshot_archive.rs rename to src/tape/file_formats/snapshot_archive.rs diff --git a/src/tape/helpers/mod.rs b/src/tape/helpers/mod.rs index df7464d8..4adc6e85 100644 --- a/src/tape/helpers/mod.rs +++ b/src/tape/helpers/mod.rs @@ -4,11 +4,5 @@ pub use emulate_tape_writer::*; mod emulate_tape_reader; pub use emulate_tape_reader::*; -mod blocked_reader; -pub use blocked_reader::*; - -mod blocked_writer; -pub use blocked_writer::*; - mod snapshot_reader; pub use snapshot_reader::*; diff --git a/src/tape/mod.rs b/src/tape/mod.rs index f9f69243..98af0bd7 100644 --- a/src/tape/mod.rs +++ b/src/tape/mod.rs @@ -40,12 +40,6 @@ pub use media_pool::*; mod media_catalog; pub use media_catalog::*; -mod chunk_archive; -pub use chunk_archive::*; - -mod snapshot_archive; -pub use snapshot_archive::*; - mod pool_writer; pub use pool_writer::*; diff --git a/src/tape/pool_writer.rs b/src/tape/pool_writer.rs index 75d64366..a15273f1 100644 --- a/src/tape/pool_writer.rs +++ b/src/tape/pool_writer.rs @@ -16,15 +16,17 @@ use crate::{ MAX_CHUNK_ARCHIVE_SIZE, COMMIT_BLOCK_SIZE, TapeWrite, - ChunkArchiveWriter, SnapshotReader, SnapshotChunkIterator, MediaPool, MediaId, MediaCatalog, MediaSetCatalog, - tape_write_snapshot_archive, - file_formats::MediaSetLabel, + file_formats::{ + MediaSetLabel, + ChunkArchiveWriter, + tape_write_snapshot_archive, + }, drive::{ TapeDriver, request_and_load_media,