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

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