v2v: windows: Don't do NTFS heads fix if i_root is not a partition (RHBZ#1276540).

The error was:

libguestfs: trace: pread_device = "NTFS    "
libguestfs: trace: part_to_dev "/dev/sda"
guestfsd: main_loop: new request, len 0x34
guestfsd: error: device name is not a partition
guestfsd: main_loop: proc 272 (part_to_dev) took 0.00 seconds
libguestfs: trace: part_to_dev = NULL (error)
virt-v2v: error: libguestfs error: part_to_dev: device name is not a
partition
This commit is contained in:
Richard W.M. Jones
2015-10-30 08:50:10 +00:00
parent 25fee09a44
commit 20ae8bd9ec

View File

@@ -716,26 +716,29 @@ echo uninstalling Xen PV driver
*)
let rootpart = inspect.i_root in
(* Check that the root device contains NTFS magic. *)
let magic = g#pread_device rootpart 8 3L in
if magic = "NTFS " then (
(* Get the size of the whole disk containing the root partition. *)
let rootdev = g#part_to_dev rootpart in (* eg. /dev/sda *)
let size = g#blockdev_getsize64 rootdev in
(* Ignore if the rootpart is something like /dev/sda. RHBZ#1276540. *)
if not (g#is_whole_device rootpart) then (
(* Check that the root device contains NTFS magic. *)
let magic = g#pread_device rootpart 8 3L in
if magic = "NTFS " then (
(* Get the size of the whole disk containing the root partition. *)
let rootdev = g#part_to_dev rootpart in (* eg. /dev/sda *)
let size = g#blockdev_getsize64 rootdev in
let heads = (* refer to the table above *)
if size < 2114445312L then 0x40
else if size < 4228374780L then 0x80
else 0xff in
let heads = (* refer to the table above *)
if size < 2114445312L then 0x40
else if size < 4228374780L then 0x80
else 0xff in
(* Update NTFS's idea of the number of heads. This is an
* unsigned 16 bit little-endian integer, offset 0x1a from the
* beginning of the partition.
*)
let bytes = String.create 2 in
bytes.[0] <- Char.chr heads;
bytes.[1] <- '\000';
ignore (g#pwrite_device rootpart bytes 0x1a_L)
(* Update NTFS's idea of the number of heads. This is an
* unsigned 16 bit little-endian integer, offset 0x1a from the
* beginning of the partition.
*)
let bytes = String.create 2 in
bytes.[0] <- Char.chr heads;
bytes.[1] <- '\000';
ignore (g#pwrite_device rootpart bytes 0x1a_L)
)
)
in