0a122b
From 746c0b5934008a7e6a31c5de8ee5e799f88da9d9 Mon Sep 17 00:00:00 2001
0a122b
From: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
Date: Tue, 25 Mar 2014 14:23:40 +0100
0a122b
Subject: [PATCH 33/49] dmg: coding style and indentation cleanup
0a122b
0a122b
RH-Author: Kevin Wolf <kwolf@redhat.com>
0a122b
Message-id: <1395753835-7591-34-git-send-email-kwolf@redhat.com>
0a122b
Patchwork-id: n/a
0a122b
O-Subject: [virt-devel] [EMBARGOED RHEL-7.0 qemu-kvm PATCH 33/48] dmg: coding style and indentation cleanup
0a122b
Bugzilla: 1066691
0a122b
RH-Acked-by: Jeff Cody <jcody@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
0a122b
From: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1066691
0a122b
Upstream status: Series embargoed
0a122b
0a122b
Clean up the mix of tabs and spaces, as well as the coding style
0a122b
violations in block/dmg.c. There are no semantic changes since this
0a122b
patch simply reformats the code.
0a122b
0a122b
This patch is necessary before we can make meaningful changes to this
0a122b
file, due to the inconsistent formatting and confusing indentation.
0a122b
0a122b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
---
0a122b
 block/dmg.c |  224 +++++++++++++++++++++++++++++++---------------------------
0a122b
 1 files changed, 120 insertions(+), 104 deletions(-)
0a122b
0a122b
diff --git a/block/dmg.c b/block/dmg.c
0a122b
index d5e9b1f..be2f26e 100644
0a122b
--- a/block/dmg.c
0a122b
+++ b/block/dmg.c
0a122b
@@ -96,9 +96,9 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
                     Error **errp)
0a122b
 {
0a122b
     BDRVDMGState *s = bs->opaque;
0a122b
-    uint64_t info_begin,info_end,last_in_offset,last_out_offset;
0a122b
+    uint64_t info_begin, info_end, last_in_offset, last_out_offset;
0a122b
     uint32_t count, tmp;
0a122b
-    uint32_t max_compressed_size=1,max_sectors_per_chunk=1,i;
0a122b
+    uint32_t max_compressed_size = 1, max_sectors_per_chunk = 1, i;
0a122b
     int64_t offset;
0a122b
     int ret;
0a122b
 
0a122b
@@ -160,37 +160,39 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
             goto fail;
0a122b
         }
0a122b
 
0a122b
-	if (type == 0x6d697368 && count >= 244) {
0a122b
-	    int new_size, chunk_count;
0a122b
+        if (type == 0x6d697368 && count >= 244) {
0a122b
+            int new_size, chunk_count;
0a122b
 
0a122b
             offset += 4;
0a122b
             offset += 200;
0a122b
 
0a122b
-	    chunk_count = (count-204)/40;
0a122b
-	    new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);
0a122b
-	    s->types = g_realloc(s->types, new_size/2);
0a122b
-	    s->offsets = g_realloc(s->offsets, new_size);
0a122b
-	    s->lengths = g_realloc(s->lengths, new_size);
0a122b
-	    s->sectors = g_realloc(s->sectors, new_size);
0a122b
-	    s->sectorcounts = g_realloc(s->sectorcounts, new_size);
0a122b
+            chunk_count = (count - 204) / 40;
0a122b
+            new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count);
0a122b
+            s->types = g_realloc(s->types, new_size / 2);
0a122b
+            s->offsets = g_realloc(s->offsets, new_size);
0a122b
+            s->lengths = g_realloc(s->lengths, new_size);
0a122b
+            s->sectors = g_realloc(s->sectors, new_size);
0a122b
+            s->sectorcounts = g_realloc(s->sectorcounts, new_size);
0a122b
 
0a122b
             for (i = s->n_chunks; i < s->n_chunks + chunk_count; i++) {
0a122b
                 ret = read_uint32(bs, offset, &s->types[i]);
0a122b
                 if (ret < 0) {
0a122b
                     goto fail;
0a122b
                 }
0a122b
-		offset += 4;
0a122b
-		if(s->types[i]!=0x80000005 && s->types[i]!=1 && s->types[i]!=2) {
0a122b
-		    if(s->types[i]==0xffffffff) {
0a122b
-			last_in_offset = s->offsets[i-1]+s->lengths[i-1];
0a122b
-			last_out_offset = s->sectors[i-1]+s->sectorcounts[i-1];
0a122b
-		    }
0a122b
-		    chunk_count--;
0a122b
-		    i--;
0a122b
-		    offset += 36;
0a122b
-		    continue;
0a122b
-		}
0a122b
-		offset += 4;
0a122b
+                offset += 4;
0a122b
+                if (s->types[i] != 0x80000005 && s->types[i] != 1 &&
0a122b
+                    s->types[i] != 2) {
0a122b
+                    if (s->types[i] == 0xffffffff) {
0a122b
+                        last_in_offset = s->offsets[i - 1] + s->lengths[i - 1];
0a122b
+                        last_out_offset = s->sectors[i - 1] +
0a122b
+                                          s->sectorcounts[i - 1];
0a122b
+                    }
0a122b
+                    chunk_count--;
0a122b
+                    i--;
0a122b
+                    offset += 36;
0a122b
+                    continue;
0a122b
+                }
0a122b
+                offset += 4;
0a122b
 
0a122b
                 ret = read_uint64(bs, offset, &s->sectors[i]);
0a122b
                 if (ret < 0) {
0a122b
@@ -218,19 +220,21 @@ static int dmg_open(BlockDriverState *bs, QDict *options, int flags,
0a122b
                 }
0a122b
                 offset += 8;
0a122b
 
0a122b
-		if(s->lengths[i]>max_compressed_size)
0a122b
-		    max_compressed_size = s->lengths[i];
0a122b
-		if(s->sectorcounts[i]>max_sectors_per_chunk)
0a122b
-		    max_sectors_per_chunk = s->sectorcounts[i];
0a122b
-	    }
0a122b
-	    s->n_chunks+=chunk_count;
0a122b
-	}
0a122b
+                if (s->lengths[i] > max_compressed_size) {
0a122b
+                    max_compressed_size = s->lengths[i];
0a122b
+                }
0a122b
+                if (s->sectorcounts[i] > max_sectors_per_chunk) {
0a122b
+                    max_sectors_per_chunk = s->sectorcounts[i];
0a122b
+                }
0a122b
+            }
0a122b
+            s->n_chunks += chunk_count;
0a122b
+        }
0a122b
     }
0a122b
 
0a122b
     /* initialize zlib engine */
0a122b
-    s->compressed_chunk = g_malloc(max_compressed_size+1);
0a122b
-    s->uncompressed_chunk = g_malloc(512*max_sectors_per_chunk);
0a122b
-    if(inflateInit(&s->zstream) != Z_OK) {
0a122b
+    s->compressed_chunk = g_malloc(max_compressed_size + 1);
0a122b
+    s->uncompressed_chunk = g_malloc(512 * max_sectors_per_chunk);
0a122b
+    if (inflateInit(&s->zstream) != Z_OK) {
0a122b
         ret = -EINVAL;
0a122b
         goto fail;
0a122b
     }
0a122b
@@ -252,27 +256,29 @@ fail:
0a122b
 }
0a122b
 
0a122b
 static inline int is_sector_in_chunk(BDRVDMGState* s,
0a122b
-		uint32_t chunk_num,int sector_num)
0a122b
+                uint32_t chunk_num, int sector_num)
0a122b
 {
0a122b
-    if(chunk_num>=s->n_chunks || s->sectors[chunk_num]>sector_num ||
0a122b
-	    s->sectors[chunk_num]+s->sectorcounts[chunk_num]<=sector_num)
0a122b
-	return 0;
0a122b
-    else
0a122b
-	return -1;
0a122b
+    if (chunk_num >= s->n_chunks || s->sectors[chunk_num] > sector_num ||
0a122b
+            s->sectors[chunk_num] + s->sectorcounts[chunk_num] <= sector_num) {
0a122b
+        return 0;
0a122b
+    } else {
0a122b
+        return -1;
0a122b
+    }
0a122b
 }
0a122b
 
0a122b
-static inline uint32_t search_chunk(BDRVDMGState* s,int sector_num)
0a122b
+static inline uint32_t search_chunk(BDRVDMGState *s, int sector_num)
0a122b
 {
0a122b
     /* binary search */
0a122b
-    uint32_t chunk1=0,chunk2=s->n_chunks,chunk3;
0a122b
-    while(chunk1!=chunk2) {
0a122b
-	chunk3 = (chunk1+chunk2)/2;
0a122b
-	if(s->sectors[chunk3]>sector_num)
0a122b
-	    chunk2 = chunk3;
0a122b
-	else if(s->sectors[chunk3]+s->sectorcounts[chunk3]>sector_num)
0a122b
-	    return chunk3;
0a122b
-	else
0a122b
-	    chunk1 = chunk3;
0a122b
+    uint32_t chunk1 = 0, chunk2 = s->n_chunks, chunk3;
0a122b
+    while (chunk1 != chunk2) {
0a122b
+        chunk3 = (chunk1 + chunk2) / 2;
0a122b
+        if (s->sectors[chunk3] > sector_num) {
0a122b
+            chunk2 = chunk3;
0a122b
+        } else if (s->sectors[chunk3] + s->sectorcounts[chunk3] > sector_num) {
0a122b
+            return chunk3;
0a122b
+        } else {
0a122b
+            chunk1 = chunk3;
0a122b
+        }
0a122b
     }
0a122b
     return s->n_chunks; /* error */
0a122b
 }
0a122b
@@ -281,54 +287,62 @@ static inline int dmg_read_chunk(BlockDriverState *bs, int sector_num)
0a122b
 {
0a122b
     BDRVDMGState *s = bs->opaque;
0a122b
 
0a122b
-    if(!is_sector_in_chunk(s,s->current_chunk,sector_num)) {
0a122b
-	int ret;
0a122b
-	uint32_t chunk = search_chunk(s,sector_num);
0a122b
+    if (!is_sector_in_chunk(s, s->current_chunk, sector_num)) {
0a122b
+        int ret;
0a122b
+        uint32_t chunk = search_chunk(s, sector_num);
0a122b
 
0a122b
-	if(chunk>=s->n_chunks)
0a122b
-	    return -1;
0a122b
+        if (chunk >= s->n_chunks) {
0a122b
+            return -1;
0a122b
+        }
0a122b
 
0a122b
-	s->current_chunk = s->n_chunks;
0a122b
-	switch(s->types[chunk]) {
0a122b
-	case 0x80000005: { /* zlib compressed */
0a122b
-	    int i;
0a122b
+        s->current_chunk = s->n_chunks;
0a122b
+        switch (s->types[chunk]) {
0a122b
+        case 0x80000005: { /* zlib compressed */
0a122b
+            int i;
0a122b
 
0a122b
-	    /* we need to buffer, because only the chunk as whole can be
0a122b
-	     * inflated. */
0a122b
-	    i=0;
0a122b
-	    do {
0a122b
+            /* we need to buffer, because only the chunk as whole can be
0a122b
+             * inflated. */
0a122b
+            i = 0;
0a122b
+            do {
0a122b
                 ret = bdrv_pread(bs->file, s->offsets[chunk] + i,
0a122b
-                                 s->compressed_chunk+i, s->lengths[chunk]-i);
0a122b
-		if(ret<0 && errno==EINTR)
0a122b
-		    ret=0;
0a122b
-		i+=ret;
0a122b
-	    } while(ret>=0 && ret+i<s->lengths[chunk]);
0a122b
-
0a122b
-	    if (ret != s->lengths[chunk])
0a122b
-		return -1;
0a122b
-
0a122b
-	    s->zstream.next_in = s->compressed_chunk;
0a122b
-	    s->zstream.avail_in = s->lengths[chunk];
0a122b
-	    s->zstream.next_out = s->uncompressed_chunk;
0a122b
-	    s->zstream.avail_out = 512*s->sectorcounts[chunk];
0a122b
-	    ret = inflateReset(&s->zstream);
0a122b
-	    if(ret != Z_OK)
0a122b
-		return -1;
0a122b
-	    ret = inflate(&s->zstream, Z_FINISH);
0a122b
-	    if(ret != Z_STREAM_END || s->zstream.total_out != 512*s->sectorcounts[chunk])
0a122b
-		return -1;
0a122b
-	    break; }
0a122b
-	case 1: /* copy */
0a122b
-	    ret = bdrv_pread(bs->file, s->offsets[chunk],
0a122b
+                                 s->compressed_chunk + i,
0a122b
+                                 s->lengths[chunk] - i);
0a122b
+                if (ret < 0 && errno == EINTR) {
0a122b
+                    ret = 0;
0a122b
+                }
0a122b
+                i += ret;
0a122b
+            } while (ret >= 0 && ret + i < s->lengths[chunk]);
0a122b
+
0a122b
+            if (ret != s->lengths[chunk]) {
0a122b
+                return -1;
0a122b
+            }
0a122b
+
0a122b
+            s->zstream.next_in = s->compressed_chunk;
0a122b
+            s->zstream.avail_in = s->lengths[chunk];
0a122b
+            s->zstream.next_out = s->uncompressed_chunk;
0a122b
+            s->zstream.avail_out = 512 * s->sectorcounts[chunk];
0a122b
+            ret = inflateReset(&s->zstream);
0a122b
+            if (ret != Z_OK) {
0a122b
+                return -1;
0a122b
+            }
0a122b
+            ret = inflate(&s->zstream, Z_FINISH);
0a122b
+            if (ret != Z_STREAM_END ||
0a122b
+                s->zstream.total_out != 512 * s->sectorcounts[chunk]) {
0a122b
+                return -1;
0a122b
+            }
0a122b
+            break; }
0a122b
+        case 1: /* copy */
0a122b
+            ret = bdrv_pread(bs->file, s->offsets[chunk],
0a122b
                              s->uncompressed_chunk, s->lengths[chunk]);
0a122b
-	    if (ret != s->lengths[chunk])
0a122b
-		return -1;
0a122b
-	    break;
0a122b
-	case 2: /* zero */
0a122b
-	    memset(s->uncompressed_chunk, 0, 512*s->sectorcounts[chunk]);
0a122b
-	    break;
0a122b
-	}
0a122b
-	s->current_chunk = chunk;
0a122b
+            if (ret != s->lengths[chunk]) {
0a122b
+                return -1;
0a122b
+            }
0a122b
+            break;
0a122b
+        case 2: /* zero */
0a122b
+            memset(s->uncompressed_chunk, 0, 512 * s->sectorcounts[chunk]);
0a122b
+            break;
0a122b
+        }
0a122b
+        s->current_chunk = chunk;
0a122b
     }
0a122b
     return 0;
0a122b
 }
0a122b
@@ -339,12 +353,14 @@ static int dmg_read(BlockDriverState *bs, int64_t sector_num,
0a122b
     BDRVDMGState *s = bs->opaque;
0a122b
     int i;
0a122b
 
0a122b
-    for(i=0;i
0a122b
-	uint32_t sector_offset_in_chunk;
0a122b
-	if(dmg_read_chunk(bs, sector_num+i) != 0)
0a122b
-	    return -1;
0a122b
-	sector_offset_in_chunk = sector_num+i-s->sectors[s->current_chunk];
0a122b
-	memcpy(buf+i*512,s->uncompressed_chunk+sector_offset_in_chunk*512,512);
0a122b
+    for (i = 0; i < nb_sectors; i++) {
0a122b
+        uint32_t sector_offset_in_chunk;
0a122b
+        if (dmg_read_chunk(bs, sector_num + i) != 0) {
0a122b
+            return -1;
0a122b
+        }
0a122b
+        sector_offset_in_chunk = sector_num + i - s->sectors[s->current_chunk];
0a122b
+        memcpy(buf + i * 512,
0a122b
+               s->uncompressed_chunk + sector_offset_in_chunk * 512, 512);
0a122b
     }
0a122b
     return 0;
0a122b
 }
0a122b
@@ -376,12 +392,12 @@ static void dmg_close(BlockDriverState *bs)
0a122b
 }
0a122b
 
0a122b
 static BlockDriver bdrv_dmg = {
0a122b
-    .format_name	= "dmg",
0a122b
-    .instance_size	= sizeof(BDRVDMGState),
0a122b
-    .bdrv_probe		= dmg_probe,
0a122b
-    .bdrv_open		= dmg_open,
0a122b
-    .bdrv_read          = dmg_co_read,
0a122b
-    .bdrv_close		= dmg_close,
0a122b
+    .format_name    = "dmg",
0a122b
+    .instance_size  = sizeof(BDRVDMGState),
0a122b
+    .bdrv_probe     = dmg_probe,
0a122b
+    .bdrv_open      = dmg_open,
0a122b
+    .bdrv_read      = dmg_co_read,
0a122b
+    .bdrv_close     = dmg_close,
0a122b
 };
0a122b
 
0a122b
 static void bdrv_dmg_init(void)
0a122b
-- 
0a122b
1.7.1
0a122b