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

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