separate alias_addr (10.0.2.2) from our_addr (Ed Swierk)
[qemu] / block-dmg.c
index af8b67b..a16ab92 100644 (file)
@@ -44,8 +44,8 @@ typedef struct BDRVDMGState {
     uint64_t* sectors;
     uint64_t* sectorcounts;
     uint32_t current_chunk;
-    char* compressed_chunk;
-    char* uncompressed_chunk;
+    uint8_t *compressed_chunk;
+    uint8_t *uncompressed_chunk;
     z_stream zstream;
 } BDRVDMGState;
 
@@ -91,7 +91,9 @@ static int dmg_open(BlockDriverState *bs, const char *filename)
     if(lseek(s->fd,-0x1d8,SEEK_END)<0) {
 dmg_close:
        close(s->fd);
-       return -1;
+       /* open raw instead */
+       bs->drv=&bdrv_raw;
+       return bs->drv->bdrv_open(bs,filename);
     }
     info_begin=read_off(s->fd);
     if(info_begin==0)
@@ -109,10 +111,12 @@ dmg_close:
     /* read offsets */
     last_in_offset = last_out_offset = 0;
     while(lseek(s->fd,0,SEEK_CUR)<info_end) {
+        uint32_t type;
+
        count = read_uint32(s->fd);
        if(count==0)
            goto dmg_close;
-       uint32_t type = read_uint32(s->fd);
+       type = read_uint32(s->fd);
        if(type!=0x6d697368 || count<244)
            lseek(s->fd,count-4,SEEK_CUR);
        else {
@@ -155,9 +159,9 @@ dmg_close:
     }
 
     /* initialize zlib engine */
-    if(!(s->compressed_chunk=(char*)malloc(max_compressed_size+1)))
+    if(!(s->compressed_chunk = malloc(max_compressed_size+1)))
        goto dmg_close;
-    if(!(s->uncompressed_chunk=(char*)malloc(512*max_sectors_per_chunk)))
+    if(!(s->uncompressed_chunk = malloc(512*max_sectors_per_chunk)))
        goto dmg_close;
     if(inflateInit(&s->zstream) != Z_OK)
        goto dmg_close;