Commit 01781963983206feac8c6be5ded68c3ee244c4ad

Authored by bellard
1 parent 18607dcb

win32: physical drive support (initial patch by kazu)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2311 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 30 additions and 5 deletions
block-raw.c
@@ -838,6 +838,7 @@ BlockDriver bdrv_host_device = { @@ -838,6 +838,7 @@ BlockDriver bdrv_host_device = {
838 838
839 #define FTYPE_FILE 0 839 #define FTYPE_FILE 0
840 #define FTYPE_CD 1 840 #define FTYPE_CD 1
  841 +#define FTYPE_HARDDISK 2
841 842
842 typedef struct BDRVRawState { 843 typedef struct BDRVRawState {
843 HANDLE hfile; 844 HANDLE hfile;
@@ -1098,6 +1099,9 @@ static int64_t raw_getlength(BlockDriverState *bs) @@ -1098,6 +1099,9 @@ static int64_t raw_getlength(BlockDriverState *bs)
1098 BDRVRawState *s = bs->opaque; 1099 BDRVRawState *s = bs->opaque;
1099 LARGE_INTEGER l; 1100 LARGE_INTEGER l;
1100 ULARGE_INTEGER available, total, total_free; 1101 ULARGE_INTEGER available, total, total_free;
  1102 + DISK_GEOMETRY dg;
  1103 + DWORD count;
  1104 + BOOL status;
1101 1105
1102 switch(s->type) { 1106 switch(s->type) {
1103 case FTYPE_FILE: 1107 case FTYPE_FILE:
@@ -1110,6 +1114,14 @@ static int64_t raw_getlength(BlockDriverState *bs) @@ -1110,6 +1114,14 @@ static int64_t raw_getlength(BlockDriverState *bs)
1110 return -EIO; 1114 return -EIO;
1111 l.QuadPart = total.QuadPart; 1115 l.QuadPart = total.QuadPart;
1112 break; 1116 break;
  1117 + case FTYPE_HARDDISK:
  1118 + status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY,
  1119 + NULL, 0, &dg, sizeof(dg), &count, NULL);
  1120 + if (status != FALSE) {
  1121 + l.QuadPart = dg.Cylinders.QuadPart * dg.TracksPerCylinder
  1122 + * dg.SectorsPerTrack * dg.BytesPerSector;
  1123 + }
  1124 + break;
1113 default: 1125 default:
1114 return -EIO; 1126 return -EIO;
1115 } 1127 }
@@ -1216,6 +1228,8 @@ static int find_device_type(BlockDriverState *bs, const char *filename) @@ -1216,6 +1228,8 @@ static int find_device_type(BlockDriverState *bs, const char *filename)
1216 1228
1217 if (strstart(filename, "\\\\.\\", &p) || 1229 if (strstart(filename, "\\\\.\\", &p) ||
1218 strstart(filename, "//./", &p)) { 1230 strstart(filename, "//./", &p)) {
  1231 + if (stristart(p, "PhysicalDrive", NULL))
  1232 + return FTYPE_HARDDISK;
1219 snprintf(s->drive_path, sizeof(s->drive_path), "%c:\\", p[0]); 1233 snprintf(s->drive_path, sizeof(s->drive_path), "%c:\\", p[0]);
1220 type = GetDriveType(s->drive_path); 1234 type = GetDriveType(s->drive_path);
1221 if (type == DRIVE_CDROM) 1235 if (type == DRIVE_CDROM)
@@ -1248,7 +1262,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags) @@ -1248,7 +1262,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
1248 } 1262 }
1249 } 1263 }
1250 s->type = find_device_type(bs, filename); 1264 s->type = find_device_type(bs, filename);
1251 - 1265 +
1252 if ((flags & BDRV_O_ACCESS) == O_RDWR) { 1266 if ((flags & BDRV_O_ACCESS) == O_RDWR) {
1253 access_flags = GENERIC_READ | GENERIC_WRITE; 1267 access_flags = GENERIC_READ | GENERIC_WRITE;
1254 } else { 1268 } else {
qemu-doc.texi
@@ -1079,14 +1079,25 @@ line option or modify the device permissions accordingly). @@ -1079,14 +1079,25 @@ line option or modify the device permissions accordingly).
1079 1079
1080 @subsubsection Windows 1080 @subsubsection Windows
1081 1081
1082 -On Windows you can use any host drives as QEMU drive. The prefered  
1083 -syntax is the driver letter (e.g. @file{d:}). The alternate syntax  
1084 -@file{\\.\d:} is supported. @file{/dev/cdrom} is supported as an alias  
1085 -to the first CDROM drive. 1082 +@table @code
  1083 +@item CD
  1084 +The prefered syntax is the drive letter (e.g. @file{d:}). The
  1085 +alternate syntax @file{\\.\d:} is supported. @file{/dev/cdrom} is
  1086 +supported as an alias to the first CDROM drive.
1086 1087
1087 Currently there is no specific code to handle removable medias, so it 1088 Currently there is no specific code to handle removable medias, so it
1088 is better to use the @code{change} or @code{eject} monitor commands to 1089 is better to use the @code{change} or @code{eject} monitor commands to
1089 change or eject media. 1090 change or eject media.
  1091 +@item Hard disks
  1092 +Hard disks can be used with the syntax: @file{\\.\PhysicalDriveN}
  1093 +where @var{N} is the drive number (0 is the first hard disk).
  1094 +
  1095 +WARNING: unless you know what you do, it is better to only make
  1096 +READ-ONLY accesses to the hard disk otherwise you may corrupt your
  1097 +host data (use the @option{-snapshot} command line so that the
  1098 +modifications are written in a temporary file).
  1099 +@end table
  1100 +
1090 1101
1091 @subsubsection Mac OS X 1102 @subsubsection Mac OS X
1092 1103