qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Real hard disk drive for Win2k/XP host
@ 2005-09-14  3:41 Kazu
  2005-09-14 15:39 ` Jim C. Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Kazu @ 2005-09-14  3:41 UTC (permalink / raw)
  To: qemu-devel

[-- 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 */

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] Real hard disk drive for Win2k/XP host
  2005-09-14  3:41 [Qemu-devel] Real hard disk drive for Win2k/XP host Kazu
@ 2005-09-14 15:39 ` Jim C. Brown
  2005-09-14 23:07   ` Kazu
  0 siblings, 1 reply; 3+ messages in thread
From: Jim C. Brown @ 2005-09-14 15:39 UTC (permalink / raw)
  To: qemu-devel

On Wed, Sep 14, 2005 at 12:41:39PM +0900, Kazu wrote:
> 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
> 

I don't see any code for this in your patch. AFAIK qemu supports this already.

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

It breaks non-Windows hosts. get_size() should only be called when running
on Windows and when size == -1.

Also, it is always a bad idea to have a filesystem used by both the host and
the guest OS (unless they both can see it read-only).

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] Real hard disk drive for Win2k/XP host
  2005-09-14 15:39 ` Jim C. Brown
@ 2005-09-14 23:07   ` Kazu
  0 siblings, 0 replies; 3+ messages in thread
From: Kazu @ 2005-09-14 23:07 UTC (permalink / raw)
  To: qemu-devel

Thursday, September 15, 2005 12:39 AM Jim C. Brown wrote:


>
> I don't see any code for this in your patch. AFAIK qemu supports this 
> already.
>

I didn't know that. Thanks.

Regards,
Kazu

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-09-14 23:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-14  3:41 [Qemu-devel] Real hard disk drive for Win2k/XP host Kazu
2005-09-14 15:39 ` Jim C. Brown
2005-09-14 23:07   ` Kazu

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).