qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Kazu" <kazoo@r3.dion.ne.jp>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Real hard disk drive for Win2k/XP host
Date: Wed, 14 Sep 2005 12:41:39 +0900	[thread overview]
Message-ID: <005a01c5b8de$373f1a20$0464a8c0@athlon> (raw)

[-- Attachment #1: Type: text/plain, Size: 1192 bytes --]

Hi,

This patch supports a real hard disk drive by \\.\PhysicalDriveN
(N=0,1,2,...) on Windows 2000/XP host. Windows 98/Me are not supported.
You can also use slash like //./PhysicalDriveN. You can see a number in
Administration Tools in Control Panel. This is not case-sensitive. It is
necessary to have an administrative priviledge.This can be used like this.

> qemu.exe -L .\bios -hda win2k.img -hdb \\.\PhysicalDrive0

This patch also adds a size information about CD-ROM.

It is safe to use it as a read-only. Making a file from guest OS to real
hard
disk  isn't recognized immediately. Rebooting a host OS recognized the file.
Making a directory from guest OS breaks a host's file system.

There is a case that changes of files in a host OS isn't recognized by a
guest OS. Shut down the guest OS, move the file to another directory and
boot the guest OS. Then the file is recognized.

Windows 98/Me doesn't recognize NTFS file system. When you use Windows XP on
NTFS, Windows 98/Me guest can't see host files.

If you don't have a multi-boot environment, don't boot from your system hard
disk.

>qemu.exe -L .\bios -hda \\.\PhysicalDrive0

It will break your host OS.

Regards,
Kazu



[-- Attachment #2: qemu-0.7.2-hd.patch --]
[-- Type: application/octet-stream, Size: 2672 bytes --]

diff -ur qemu-0.7.2.orig/block.c qemu-0.7.2/block.c
--- qemu-0.7.2.orig/block.c	Mon Sep  5 02:11:31 2005
+++ qemu-0.7.2/block.c	Sun Sep 11 17:16:15 2005
@@ -546,6 +546,44 @@
     return 1; /* maybe */
 }
 
+#ifdef _WIN32
+static int64_t get_size(BlockDriverState *bs, const char *filename, int fd)
+{
+    int64_t size;
+    BOOL status;
+    ULARGE_INTEGER available, total, total_free; 
+    char *drive_letter;
+    HANDLE hHd;
+    DISK_GEOMETRY dg;
+    DWORD count;
+
+    if (bdrv_get_type_hint(bs) == BDRV_TYPE_CDROM &&
+        (strstart(filename, "//", NULL) || strstart(filename, "\\\\", NULL))) {
+        drive_letter = (char *)filename + 4;
+        status = GetDiskFreeSpaceEx(drive_letter, &available, &total, &total_free);
+        if (status != FALSE){
+            return total.QuadPart;
+        } else {
+            return -1;
+        }
+    } else if (bdrv_get_type_hint(bs) == BDRV_TYPE_HD &&
+               (strstart(filename, "//", NULL) || strstart(filename, "\\\\", NULL))) {
+        hHd = (HANDLE)_get_osfhandle(fd);
+        status = DeviceIoControl(hHd, IOCTL_DISK_GET_DRIVE_GEOMETRY,
+                                 NULL, 0, &dg, sizeof(dg), &count, NULL);
+        if (status != FALSE) {
+            size = dg.Cylinders.QuadPart * dg.TracksPerCylinder
+                * dg.SectorsPerTrack * dg.BytesPerSector;
+            return size;
+        } else {
+            return -1;
+        }
+    }
+    size = lseek(fd, 0, SEEK_END);
+    return size;
+}
+#endif
+
 static int raw_open(BlockDriverState *bs, const char *filename)
 {
     BDRVRawState *s = bs->opaque;
@@ -576,8 +614,7 @@
 #ifdef _WIN32
     /* On Windows hosts it can happen that we're unable to get file size
        for CD-ROM raw device (it's inherent limitation of the CDFS driver). */
-    if (size == -1)
-        size = LONG_LONG_MAX;
+    size = get_size(bs, filename, fd);
 #endif
     bs->total_sectors = size / 512;
     s->fd = fd;
diff -ur qemu-0.7.2.orig/vl.c qemu-0.7.2/vl.c
--- qemu-0.7.2.orig/vl.c	Mon Sep  5 02:11:31 2005
+++ qemu-0.7.2/vl.c	Sun Sep 11 17:16:15 2005
@@ -61,8 +61,6 @@
 #ifdef _WIN32
 #include <malloc.h>
 #include <sys/timeb.h>
-#include <windows.h>
-#define getopt_long_only getopt_long
 #define memalign(align, size) malloc(size)
 #endif
 
diff -ur qemu-0.7.2.orig/vl.h qemu-0.7.2/vl.h
--- qemu-0.7.2.orig/vl.h	Mon Sep  5 02:11:31 2005
+++ qemu-0.7.2/vl.h	Sun Sep 11 17:16:15 2005
@@ -47,6 +47,8 @@
 #endif
 
 #ifdef _WIN32
+#include <windows.h>
+#include <winioctl.h>
 #define lseek _lseeki64
 #define ENOTSUP 4096
 /* XXX: find 64 bit version */

             reply	other threads:[~2005-09-14  4:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-14  3:41 Kazu [this message]
2005-09-14 15:39 ` [Qemu-devel] Real hard disk drive for Win2k/XP host Jim C. Brown
2005-09-14 23:07   ` Kazu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='005a01c5b8de$373f1a20$0464a8c0@athlon' \
    --to=kazoo@r3.dion.ne.jp \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).