Skip to contentSkip to conversation

Raw CD-ROM and hard disk for win32

Qemu-devel Kazu 2 participants 3 messages Aug 7, 2006 – Aug 9, 2006

lore
Share & tools
lore

Kazu

author
#0 lore raw

Hi,

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

Regards,
Kazu

Index: block-raw.c
===================================================================
RCS file: /sources/qemu/qemu/block-raw.c,v
retrieving revision 1.6

block-raw.c +5 -8
diff -u -r1.6 block-raw.c
@@ -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

block.c +4 -0
diff -u -r1.32 block.c
@@ -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';
#1 lore raw

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.

Quoted 15 lines · Kazu

Hi,

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

Regards,
Kazu

------------------------------------------------------------------------

_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel

author
#2 lore raw
Quoted 5 lines · Fabrice Bellard

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.

Quoted 4 lines

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

Index: block-raw.c
===================================================================
RCS file: /sources/qemu/qemu/block-raw.c,v
retrieving revision 1.6

block-raw.c +41 -2
diff -u -r1.6 block-raw.c
@@ -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

block.c +50 -5

92 lines not on this page · raw message