From 408467a05fce550b9076aa042b5ed46046af99b2 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Mon, 23 Dec 2024 07:21:33 +0000 Subject: [PATCH] block: vhdx: do not update the VHDX header during parsing The original code was buggy. It always attempted to update the header, even when the file was opened as read-only. That led to an error. The specification states that the headers should be updated when the first user visible write happens. We can just drop the incorrect code. Signed-off-by: Wei Liu --- block/src/vhdx/vhdx_header.rs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/block/src/vhdx/vhdx_header.rs b/block/src/vhdx/vhdx_header.rs index ad86a2d6c..48967bd78 100644 --- a/block/src/vhdx/vhdx_header.rs +++ b/block/src/vhdx/vhdx_header.rs @@ -371,22 +371,10 @@ pub struct VhdxHeader { impl VhdxHeader { /// Creates a VhdxHeader from a reference to a file pub fn new(f: &mut File) -> Result { - let _file_type_identifier: FileTypeIdentifier = FileTypeIdentifier::new(f)?; - let header_1 = Header::new(f, HEADER_1_START); - let header_2 = Header::new(f, HEADER_2_START); - - let mut file_write_guid: u128 = 0; - let metadata = f.metadata().map_err(VhdxHeaderError::ReadMetadata)?; - if !metadata.permissions().readonly() { - file_write_guid = Uuid::new_v4().as_u128(); - } - - let (header_1, header_2) = - VhdxHeader::update_headers(f, header_1, header_2, file_write_guid)?; Ok(VhdxHeader { - _file_type_identifier, - header_1, - header_2, + _file_type_identifier: FileTypeIdentifier::new(f)?, + header_1: Header::new(f, HEADER_1_START)?, + header_2: Header::new(f, HEADER_2_START)?, region_table_1: RegionTableHeader::new(f, REGION_TABLE_1_START)?, _region_table_2: RegionTableHeader::new(f, REGION_TABLE_2_START)?, })