]> Git Repo - qemu.git/blobdiff - block-dmg.c
Name the magic constants, wrap long lines
[qemu.git] / block-dmg.c
index 5df72354369a22e43f956919b21a2783fa2c5bcf..62117c97ae4fc57f96ef19b4e0f5b1a55bdfd1b4 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * QEMU Block driver for DMG images
- * 
+ *
  * Copyright (c) 2004 Johannes E. Schindelin
- * 
+ *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
  * in the Software without restriction, including without limitation the rights
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "vl.h"
+#include "qemu-common.h"
 #include "block_int.h"
 #include "bswap.h"
 #include <zlib.h>
 
 typedef struct BDRVDMGState {
     int fd;
-    
+
     /* each chunk contains a certain number of sectors,
      * offsets[i] is the offset in the .dmg file,
      * lengths[i] is the length of the compressed chunk,
@@ -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;
 
@@ -73,27 +73,27 @@ static off_t read_uint32(int fd)
        return be32_to_cpu(buffer);
 }
 
-static int dmg_open(BlockDriverState *bs, const char *filename)
+static int dmg_open(BlockDriverState *bs, const char *filename, int flags)
 {
     BDRVDMGState *s = bs->opaque;
     off_t info_begin,info_end,last_in_offset,last_out_offset;
     uint32_t count;
     uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;
 
-    s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
+    s->fd = open(filename, O_RDONLY | O_BINARY);
     if (s->fd < 0)
-        return -1;
+        return -errno;
     bs->read_only = 1;
     s->n_chunks = 0;
     s->offsets = s->lengths = s->sectors = s->sectorcounts = 0;
-    
+
     /* read offset of info blocks */
     if(lseek(s->fd,-0x1d8,SEEK_END)<0) {
 dmg_close:
        close(s->fd);
        /* open raw instead */
        bs->drv=&bdrv_raw;
-       return bs->drv->bdrv_open(bs,filename);
+       return bs->drv->bdrv_open(bs, filename, flags);
     }
     info_begin=read_off(s->fd);
     if(info_begin==0)
@@ -159,15 +159,15 @@ 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;
 
     s->current_chunk = s->n_chunks;
-    
+
     return 0;
 }
 
@@ -227,7 +227,7 @@ static inline int dmg_read_chunk(BDRVDMGState *s,int sector_num)
 
            if (ret != s->lengths[chunk])
                return -1;
-       
+
            s->zstream.next_in = s->compressed_chunk;
            s->zstream.avail_in = s->lengths[chunk];
            s->zstream.next_out = s->uncompressed_chunk;
@@ -253,7 +253,7 @@ static inline int dmg_read_chunk(BDRVDMGState *s,int sector_num)
     return 0;
 }
 
-static int dmg_read(BlockDriverState *bs, int64_t sector_num, 
+static int dmg_read(BlockDriverState *bs, int64_t sector_num,
                     uint8_t *buf, int nb_sectors)
 {
     BDRVDMGState *s = bs->opaque;
This page took 0.026558 seconds and 4 git commands to generate.