qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Raw CD-ROM and hard disk for win32
@ 2006-08-07  5:06 Kazu
  2006-08-07 18:31 ` Fabrice Bellard
  0 siblings, 1 reply; 3+ messages in thread
From: Kazu @ 2006-08-07  5:06 UTC (permalink / raw)
  To: qemu-devel

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

Hi,

An attached patch fixes raw CD-ROM and hard disk handling for win32.
Qcow is not fixed.

Regards,
Kazu

[-- Attachment #2: qemu-20060807-cdrom.patch --]
[-- Type: application/octet-stream, Size: 1646 bytes --]

Index: block-raw.c
===================================================================
RCS file: /sources/qemu/qemu/block-raw.c,v
retrieving revision 1.6
diff -u -r1.6 block-raw.c
--- block-raw.c	7 Aug 2006 02:38:06 -0000	1.6
+++ block-raw.c	7 Aug 2006 04:07:36 -0000
@@ -455,12 +455,6 @@
     {
         size = lseek(fd, 0, SEEK_END);
     }
-#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;
-#endif
     return size;
 }
 
@@ -767,8 +761,11 @@
     LARGE_INTEGER l;
 
     l.LowPart = GetFileSize(s->hfile, &l.HighPart);
-    if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
-	return -EIO;
+    if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR) {
+    /* 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). */
+        return LONG_LONG_MAX;
+    }
     return l.QuadPart;
 }
 
Index: block.c
===================================================================
RCS file: /sources/qemu/qemu/block.c,v
retrieving revision 1.32
diff -u -r1.32 block.c
--- block.c	7 Aug 2006 02:38:06 -0000	1.32
+++ block.c	7 Aug 2006 04:07:37 -0000
@@ -191,6 +191,10 @@
         /* specific win32 case for driver letters */
         return &bdrv_raw;
     }
+    if (len == 5) {
+        /* win32 drive. CD-ROM etc. */
+        return &bdrv_raw;
+    }
 #endif   
     memcpy(protocol, filename, len);
     protocol[len] = '\0';

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

* Re: [Qemu-devel] Raw CD-ROM and hard disk for win32
  2006-08-07  5:06 [Qemu-devel] Raw CD-ROM and hard disk for win32 Kazu
@ 2006-08-07 18:31 ` Fabrice Bellard
  2006-08-09  6:36   ` Kazu
  0 siblings, 1 reply; 3+ messages in thread
From: Fabrice Bellard @ 2006-08-07 18:31 UTC (permalink / raw)
  To: qemu-devel

Hi,

I find it strange that there is no win32 API to know the size of a 
CD-ROM. Maybe a CD-ROM specific IOCTL exists ?

About the windows device patch detection, I would like a more precise 
test than "len == 5". Testing if the filename begins with "\\.\" would 
be better. Supporting also the syntax "/dev/cdrom" would be good too.

Regards,

Fabrice.

Kazu wrote:
> Hi,
> 
> An attached patch fixes raw CD-ROM and hard disk handling for win32.
> Qcow is not fixed.
> 
> Regards,
> Kazu
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Qemu-devel mailing list
> Qemu-devel@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/qemu-devel

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

* Re: [Qemu-devel] Raw CD-ROM and hard disk for win32
  2006-08-07 18:31 ` Fabrice Bellard
@ 2006-08-09  6:36   ` Kazu
  0 siblings, 0 replies; 3+ messages in thread
From: Kazu @ 2006-08-09  6:36 UTC (permalink / raw)
  To: qemu-devel

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

Sent: Tuesday, August 08, 2006 3:31 AM Fabrice Bellard wrote:

> Hi,
>
> I find it strange that there is no win32 API to know the size of a
> CD-ROM. Maybe a CD-ROM specific IOCTL exists ?
>

Yes, it does. An attached patch gets a size of raw CD-ROM and raw hard disk.

> About the windows device patch detection, I would like a more precise
> test than "len == 5". Testing if the filename begins with "\\.\" would
> be better. Supporting also the syntax "/dev/cdrom" would be good too.
>

It is necessary to set drive letter to use CD-ROM. When -cdrom /dev/cdrom is
set, the first CD-ROM drive is used in the patch.


Regards,
Kazu

[-- Attachment #2: qemu-20060809-cdrom.patch --]
[-- Type: application/octet-stream, Size: 5218 bytes --]

Index: block-raw.c
===================================================================
RCS file: /sources/qemu/qemu/block-raw.c,v
retrieving revision 1.6
diff -u -r1.6 block-raw.c
--- block-raw.c	7 Aug 2006 02:38:06 -0000	1.6
+++ block-raw.c	9 Aug 2006 04:50:55 -0000
@@ -761,14 +761,53 @@
     return 0;
 }
 
+static int64_t get_size(BlockDriverState *bs, HANDLE hfile, const char *filename)
+{
+    int64_t size;
+    BOOL status;
+    ULARGE_INTEGER available, total, total_free; 
+    char *drive_letter;
+    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))) {
+        status = DeviceIoControl(hfile, 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;
+        }
+    }
+    return -1;
+}
+
 static int64_t  raw_getlength(BlockDriverState *bs)
 {
     BDRVRawState *s = bs->opaque;
     LARGE_INTEGER l;
+    int64_t size;
 
     l.LowPart = GetFileSize(s->hfile, &l.HighPart);
-    if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
-	return -EIO;
+    if (l.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR) {
+        size = get_size(bs, s->hfile, bs->filename);
+        if (size == -1)
+            return -EIO;
+        else
+            return size;
+    }
     return l.QuadPart;
 }
 
Index: block.c
===================================================================
RCS file: /sources/qemu/qemu/block.c,v
retrieving revision 1.33
diff -u -r1.33 block.c
--- block.c	7 Aug 2006 19:10:16 -0000	1.33
+++ block.c	9 Aug 2006 04:50:57 -0000
@@ -198,6 +198,11 @@
         /* specific win32 case for driver letters */
         return &bdrv_raw;
     }
+    if (len == 5 &&
+        (strstart(filename, "//./", NULL) || strstart(filename, "\\\\.\\", NULL))) {
+        /* win32 drive. CD-ROM etc. */
+        return &bdrv_raw;
+    }
 #endif   
     memcpy(protocol, filename, len);
     protocol[len] = '\0';
@@ -225,7 +230,11 @@
         return drv;
     if (strstart(filename, "/dev/", NULL))
         return &bdrv_raw;
-    
+#ifdef _WIN32
+    if (strstart(filename, "//./", NULL) || strstart(filename, "\\\\.\\", NULL))
+        return &bdrv_raw;
+#endif
+
     ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
     if (ret < 0)
         return NULL;
@@ -265,6 +274,28 @@
     return 0;
 }
 
+#ifdef _WIN32
+static int find_cdrom(BlockDriverState *bs, char *cdrom_name)
+{
+    char drives[256], *pdrv = drives;
+    UINT type;
+
+    ZeroMemory(drives, 256);
+    GetLogicalDriveStrings(sizeof(drives), drives);
+    while(pdrv[0] != '\0') {
+        type = GetDriveType(pdrv);
+        switch(type) {
+        case DRIVE_CDROM:
+            sprintf(cdrom_name, "\\\\.\\%c:", pdrv[0]);
+            return 0;
+            break;
+        }
+        pdrv += lstrlen(pdrv) + 1;
+    }
+    return -1;
+}
+#endif
+            
 int bdrv_open(BlockDriverState *bs, const char *filename, int flags)
 {
     return bdrv_open2(bs, filename, flags, NULL);
@@ -309,14 +340,28 @@
         bs->is_temporary = 1;
     }
 
+#ifdef _WIN32
+    /* convert /dev/cdrom to raw CD-ROM name */
+    if (strstart(filename, "/dev/cdrom", NULL)) {
+        int ret;
+        char cdrom_name[256];
+        ret = find_cdrom(bs, cdrom_name);
+        if (ret == -1)
+            return -1;
+        pstrcpy(bs->filename, sizeof(bs->filename), cdrom_name);
+    } else {
+        pstrcpy(bs->filename, sizeof(bs->filename), filename);
+    }
+#else
     pstrcpy(bs->filename, sizeof(bs->filename), filename);
+#endif
     if (flags & BDRV_O_FILE) {
-        drv = find_protocol(filename);
+        drv = find_protocol(bs->filename);
         if (!drv)
             return -ENOENT;
     } else {
         if (!drv) {
-            drv = find_image_format(filename);
+            drv = find_image_format(bs->filename);
             if (!drv)
                 return -1;
         }
@@ -331,9 +376,9 @@
         open_flags = BDRV_O_RDWR;
     else
         open_flags = flags & ~(BDRV_O_FILE | BDRV_O_SNAPSHOT);
-    ret = drv->bdrv_open(bs, filename, open_flags);
+    ret = drv->bdrv_open(bs, bs->filename, open_flags);
     if (ret == -EACCES && !(flags & BDRV_O_FILE)) {
-        ret = drv->bdrv_open(bs, filename, BDRV_O_RDONLY);
+        ret = drv->bdrv_open(bs, bs->filename, BDRV_O_RDONLY);
         bs->read_only = 1;
     }
     if (ret < 0) {

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

end of thread, other threads:[~2006-08-09  6:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-07  5:06 [Qemu-devel] Raw CD-ROM and hard disk for win32 Kazu
2006-08-07 18:31 ` Fabrice Bellard
2006-08-09  6:36   ` 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).