Real hard disk drive for Win2k/XP host
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.
Quoted 1 line
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.
Quoted 1 line
qemu.exe -L .\bios -hda \\.\PhysicalDrive0
It will break your host OS.
Regards,
Kazu
block.c +39 -2
@@ -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;
vl.c +0 -2
@@ -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
vl.h +2 -0
@@ -47,6 +47,8 @@#endif #ifdef _WIN32 +#include <windows.h> +#include <winioctl.h> #define lseek _lseeki64#define ENOTSUP 4096/* XXX: find 64 bit version */
Quoted 10 lines · Kazu
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.
Quoted 1 line
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.
Quoted 2 lines
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).
Quoted 3 lines · Jim C. Brown
I don't see any code for this in your patch. AFAIK qemu supports this already.
I didn't know that. Thanks.
Regards,
Kazu