[pbs-devel] [PATCH v5 pxar 12/62] format: add payload stream start marker
Christian Ebner
c.ebner at proxmox.com
Tue May 7 17:51:54 CEST 2024
Mark the beginning of the payload stream with a magic number. Allows for
version and file type detection.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 4:
- no changes
examples/mk-format-hashes.rs | 5 +++++
src/accessor/mod.rs | 1 +
src/decoder/mod.rs | 28 +++++++++++++++++++---------
src/encoder/mod.rs | 18 +++++++++++-------
src/format/mod.rs | 2 ++
5 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/examples/mk-format-hashes.rs b/examples/mk-format-hashes.rs
index de73df0..35cff99 100644
--- a/examples/mk-format-hashes.rs
+++ b/examples/mk-format-hashes.rs
@@ -56,6 +56,11 @@ const CONSTANTS: &[(&str, &str, &str)] = &[
"PXAR_GOODBYE_TAIL_MARKER",
"__PROXMOX_FORMAT_PXAR_GOODBYE_TAIL_MARKER__",
),
+ (
+ "The start marker used in the separate payload stream",
+ "PXAR_PAYLOAD_START_MARKER",
+ "__PROXMOX_FORMAT_PXAR_PAYLOAD_START_MARKER__",
+ ),
(
"The end marker used in the separate payload stream",
"PXAR_PAYLOAD_TAIL_MARKER",
diff --git a/src/accessor/mod.rs b/src/accessor/mod.rs
index fadd3d2..9048c94 100644
--- a/src/accessor/mod.rs
+++ b/src/accessor/mod.rs
@@ -239,6 +239,7 @@ async fn get_decoder<T: ReadAt>(
path,
true,
payload_input.map(|(input, range)| SeqReadAtAdapter::new(input, range)),
+ 0,
)
.await
}
diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs
index 7c5cc12..3bca835 100644
--- a/src/decoder/mod.rs
+++ b/src/decoder/mod.rs
@@ -206,8 +206,21 @@ pub(crate) enum ItemResult {
}
impl<I: SeqRead> DecoderImpl<I> {
- pub async fn new(input: I, payload_input: Option<I>) -> io::Result<Self> {
- Self::new_full(input, "/".into(), false, payload_input).await
+ pub async fn new(input: I, mut payload_input: Option<I>) -> io::Result<Self> {
+ let payload_consumed = if let Some(payload_input) = payload_input.as_mut() {
+ let header: Header = seq_read_entry(payload_input).await?;
+ if header.htype != format::PXAR_PAYLOAD_START_MARKER {
+ io_bail!(
+ "unexpected header in payload input: expected {:#x?} , got {header:#x?}",
+ format::PXAR_PAYLOAD_START_MARKER,
+ );
+ }
+ header.full_size()
+ } else {
+ 0
+ };
+
+ Self::new_full(input, "/".into(), false, payload_input, payload_consumed).await
}
pub(crate) fn input(&self) -> &I {
@@ -219,8 +232,9 @@ impl<I: SeqRead> DecoderImpl<I> {
path: PathBuf,
eof_after_entry: bool,
payload_input: Option<I>,
+ payload_consumed: u64,
) -> io::Result<Self> {
- let this = DecoderImpl {
+ Ok(DecoderImpl {
input,
current_header: unsafe { mem::zeroed() },
entry: Entry {
@@ -232,13 +246,9 @@ impl<I: SeqRead> DecoderImpl<I> {
state: State::Begin,
with_goodbye_tables: false,
payload_input,
- payload_consumed: 0,
+ payload_consumed,
eof_after_entry,
- };
-
- // this.read_next_entry().await?;
-
- Ok(this)
+ })
}
/// Get the next file entry, recursing into directories.
diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs
index cf16449..ea82eef 100644
--- a/src/encoder/mod.rs
+++ b/src/encoder/mod.rs
@@ -345,15 +345,23 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
pub async fn new(
output: EncoderOutput<'a, T>,
metadata: &Metadata,
- payload_output: Option<T>,
+ mut payload_output: Option<T>,
) -> io::Result<EncoderImpl<'a, T>> {
if !metadata.is_dir() {
io_bail!("directory metadata must contain the directory mode flag");
}
+
+ let mut state = EncoderState::default();
+ if let Some(payload_output) = payload_output.as_mut() {
+ let header = format::Header::with_content_size(format::PXAR_PAYLOAD_START_MARKER, 0);
+ header.check_header_size()?;
+ seq_write_struct(payload_output, header, &mut state.payload_write_position).await?;
+ }
+
let mut this = Self {
output,
- payload_output: EncoderOutput::Owned(None),
- state: vec![EncoderState::default()],
+ payload_output: EncoderOutput::Owned(payload_output),
+ state: vec![state],
finished: false,
file_copy_buffer: Arc::new(Mutex::new(unsafe {
crate::util::vec_new_uninitialized(1024 * 1024)
@@ -364,10 +372,6 @@ impl<'a, T: SeqWrite + 'a> EncoderImpl<'a, T> {
let state = this.state_mut()?;
state.files_offset = state.position();
- if let Some(payload_output) = payload_output {
- this.payload_output = EncoderOutput::Owned(Some(payload_output));
- }
-
Ok(this)
}
diff --git a/src/format/mod.rs b/src/format/mod.rs
index e451b0f..6519bfc 100644
--- a/src/format/mod.rs
+++ b/src/format/mod.rs
@@ -106,6 +106,8 @@ pub const PXAR_PAYLOAD_REF: u64 = 0x419d3d6bc4ba977e;
pub const PXAR_GOODBYE: u64 = 0x2fec4fa642d5731d;
/// The end marker used in the GOODBYE object
pub const PXAR_GOODBYE_TAIL_MARKER: u64 = 0xef5eed5b753e1555;
+/// The start marker used in the separate payload stream
+pub const PXAR_PAYLOAD_START_MARKER: u64 = 0x834c68c2194a4ed2;
/// The end marker used in the separate payload stream
pub const PXAR_PAYLOAD_TAIL_MARKER: u64 = 0x6c72b78b984c81b5;
--
2.39.2
More information about the pbs-devel
mailing list