]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
win32: physical drive support (initial patch by kazu)
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
Sun, 7 Jan 2007 22:43:30 +0000 (22:43 +0000)
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
Sun, 7 Jan 2007 22:43:30 +0000 (22:43 +0000)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2311 c046a42c-6fe2-441c-8c8c-71466251a162

block-raw.c
qemu-doc.texi

index 8cf198854ae193371354b41805d672f452d44e26..2b6f441bad85f907ee76c16a9738205129902865 100644 (file)
@@ -838,6 +838,7 @@ BlockDriver bdrv_host_device = {
 
 #define FTYPE_FILE 0
 #define FTYPE_CD     1
+#define FTYPE_HARDDISK 2
 
 typedef struct BDRVRawState {
     HANDLE hfile;
@@ -1098,6 +1099,9 @@ static int64_t raw_getlength(BlockDriverState *bs)
     BDRVRawState *s = bs->opaque;
     LARGE_INTEGER l;
     ULARGE_INTEGER available, total, total_free; 
+    DISK_GEOMETRY dg;
+    DWORD count;
+    BOOL status;
 
     switch(s->type) {
     case FTYPE_FILE:
@@ -1110,6 +1114,14 @@ static int64_t raw_getlength(BlockDriverState *bs)
             return -EIO;
         l.QuadPart = total.QuadPart;
         break;
+    case FTYPE_HARDDISK:
+        status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY,
+                                 NULL, 0, &dg, sizeof(dg), &count, NULL);
+        if (status != FALSE) {
+            l.QuadPart = dg.Cylinders.QuadPart * dg.TracksPerCylinder
+                * dg.SectorsPerTrack * dg.BytesPerSector;
+        }
+        break;
     default:
         return -EIO;
     }
@@ -1216,6 +1228,8 @@ static int find_device_type(BlockDriverState *bs, const char *filename)
 
     if (strstart(filename, "\\\\.\\", &p) ||
         strstart(filename, "//./", &p)) {
+        if (stristart(p, "PhysicalDrive", NULL))
+            return FTYPE_HARDDISK;
         snprintf(s->drive_path, sizeof(s->drive_path), "%c:\\", p[0]);
         type = GetDriveType(s->drive_path);
         if (type == DRIVE_CDROM)
@@ -1248,7 +1262,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
         }
     }
     s->type = find_device_type(bs, filename);
-
+    
     if ((flags & BDRV_O_ACCESS) == O_RDWR) {
         access_flags = GENERIC_READ | GENERIC_WRITE;
     } else {
index 655e1514901430b67d0fcd1d2e3e21f6f9e8e931..0423ef065455bbcb534e8b9dfb9babb01625ceb7 100644 (file)
@@ -1079,14 +1079,25 @@ line option or modify the device permissions accordingly).
 
 @subsubsection Windows
 
-On Windows you can use any host drives as QEMU drive. The prefered
-syntax is the driver letter (e.g. @file{d:}). The alternate syntax
-@file{\\.\d:} is supported. @file{/dev/cdrom} is supported as an alias
-to the first CDROM drive.
+@table @code
+@item CD
+The prefered syntax is the drive letter (e.g. @file{d:}). The
+alternate syntax @file{\\.\d:} is supported. @file{/dev/cdrom} is
+supported as an alias to the first CDROM drive.
 
 Currently there is no specific code to handle removable medias, so it
 is better to use the @code{change} or @code{eject} monitor commands to
 change or eject media.
+@item Hard disks
+Hard disks can be used with the syntax: @file{\\.\PhysicalDriveN}
+where @var{N} is the drive number (0 is the first hard disk).
+
+WARNING: unless you know what you do, it is better to only make
+READ-ONLY accesses to the hard disk otherwise you may corrupt your
+host data (use the @option{-snapshot} command line so that the
+modifications are written in a temporary file).
+@end table
+
 
 @subsubsection Mac OS X