Blame SOURCES/0043-v2v-windows-Do-not-fix-NTFS-heads-in-Windows-Vista-a.patch

7ed5e3
From 72f50e52515369ef8decda9493422d6235f5b365 Mon Sep 17 00:00:00 2001
7ed5e3
From: "Richard W.M. Jones" <rjones@redhat.com>
7ed5e3
Date: Wed, 18 Aug 2021 11:00:12 +0100
7ed5e3
Subject: [PATCH] v2v: windows: Do not fix NTFS heads in Windows Vista and
7ed5e3
 later
7ed5e3
7ed5e3
Setting/adjusting the number of drive heads in the NTFS header is only
7ed5e3
necessary for ancient versions of Windows.  Modern versions ignore
7ed5e3
this.  In addition this operation broke when we added BitLocker
7ed5e3
support.  Only do this for ancient Windows 2000/XP and skip it for
7ed5e3
everything else.
7ed5e3
7ed5e3
Reported-by: Ming Xie
7ed5e3
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1994984
7ed5e3
(cherry picked from commit 0a394c5c2f802098c9e481b4bacee7821e5dd0ae)
7ed5e3
---
7ed5e3
 v2v/convert_windows.ml | 44 ++++++++++++++++++++++--------------------
7ed5e3
 1 file changed, 23 insertions(+), 21 deletions(-)
7ed5e3
7ed5e3
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
7ed5e3
index 33fbd410..13de10cb 100644
7ed5e3
--- a/v2v/convert_windows.ml
7ed5e3
+++ b/v2v/convert_windows.ml
7ed5e3
@@ -730,30 +730,32 @@ if errorlevel 3010 exit /b 0
7ed5e3
        however, as this is specific to Windows 2003 it lists location
7ed5e3
        0x1A as unused.
7ed5e3
     *)
7ed5e3
-    let rootpart = inspect.i_root in
7ed5e3
+    if inspect.i_major_version < 6 (* is Windows 2000/XP *) then (
7ed5e3
+      let rootpart = inspect.i_root in
7ed5e3
 
7ed5e3
-    (* Ignore if the rootpart is something like /dev/sda.  RHBZ#1276540. *)
7ed5e3
-    if not (g#is_whole_device rootpart) then (
7ed5e3
-      (* Check that the root device contains NTFS magic. *)
7ed5e3
-      let magic = g#pread_device rootpart 8 3L in
7ed5e3
-      if magic = "NTFS    " then (
7ed5e3
-        (* Get the size of the whole disk containing the root partition. *)
7ed5e3
-        let rootdev = g#part_to_dev rootpart in (* eg. /dev/sda *)
7ed5e3
-        let size = g#blockdev_getsize64 rootdev in
7ed5e3
+      (* Ignore if the rootpart is something like /dev/sda.  RHBZ#1276540. *)
7ed5e3
+      if not (g#is_whole_device rootpart) then (
7ed5e3
+        (* Check that the root device contains NTFS magic. *)
7ed5e3
+        let magic = g#pread_device rootpart 8 3L in
7ed5e3
+        if magic = "NTFS    " then (
7ed5e3
+          (* Get the size of the whole disk containing the root partition. *)
7ed5e3
+          let rootdev = g#part_to_dev rootpart in (* eg. /dev/sda *)
7ed5e3
+          let size = g#blockdev_getsize64 rootdev in
7ed5e3
 
7ed5e3
-        let heads =             (* refer to the table above *)
7ed5e3
-          if size < 2114445312L then 0x40
7ed5e3
-          else if size < 4228374780L then 0x80
7ed5e3
-          else 0xff in
7ed5e3
+          let heads =             (* refer to the table above *)
7ed5e3
+            if size < 2114445312L then 0x40
7ed5e3
+            else if size < 4228374780L then 0x80
7ed5e3
+            else 0xff in
7ed5e3
 
7ed5e3
-        (* Update NTFS's idea of the number of heads.  This is an
7ed5e3
-         * unsigned 16 bit little-endian integer, offset 0x1a from the
7ed5e3
-         * beginning of the partition.
7ed5e3
-         *)
7ed5e3
-        let b = Bytes.create 2 in
7ed5e3
-        Bytes.unsafe_set b 0 (Char.chr heads);
7ed5e3
-        Bytes.unsafe_set b 1 '\000';
7ed5e3
-        ignore (g#pwrite_device rootpart (Bytes.to_string b) 0x1a_L)
7ed5e3
+          (* Update NTFS's idea of the number of heads.  This is an
7ed5e3
+           * unsigned 16 bit little-endian integer, offset 0x1a from the
7ed5e3
+           * beginning of the partition.
7ed5e3
+           *)
7ed5e3
+          let b = Bytes.create 2 in
7ed5e3
+          Bytes.unsafe_set b 0 (Char.chr heads);
7ed5e3
+          Bytes.unsafe_set b 1 '\000';
7ed5e3
+          ignore (g#pwrite_device rootpart (Bytes.to_string b) 0x1a_L)
7ed5e3
+        )
7ed5e3
       )
7ed5e3
     )
7ed5e3
 
7ed5e3
-- 
7ed5e3
2.18.4
7ed5e3