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) {
