Revision 5fafdf24 block-cloop.c
b/block-cloop.c | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* QEMU Block driver for CLOOP images |
3 |
*
|
|
3 |
* |
|
4 | 4 |
* Copyright (c) 2004 Johannes E. Schindelin |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | 7 |
* of this software and associated documentation files (the "Software"), to deal |
8 | 8 |
* in the Software without restriction, including without limitation the rights |
... | ... | |
96 | 96 |
if(inflateInit(&s->zstream) != Z_OK) |
97 | 97 |
goto cloop_close; |
98 | 98 |
s->current_block=s->n_blocks; |
99 |
|
|
99 |
|
|
100 | 100 |
s->sectors_per_block = s->block_size/512; |
101 | 101 |
bs->total_sectors = s->n_blocks*s->sectors_per_block; |
102 | 102 |
return 0; |
... | ... | |
107 | 107 |
if(s->current_block != block_num) { |
108 | 108 |
int ret; |
109 | 109 |
uint32_t bytes = s->offsets[block_num+1]-s->offsets[block_num]; |
110 |
|
|
110 |
|
|
111 | 111 |
lseek(s->fd, s->offsets[block_num], SEEK_SET); |
112 | 112 |
ret = read(s->fd, s->compressed_block, bytes); |
113 |
if (ret != bytes)
|
|
113 |
if (ret != bytes) |
|
114 | 114 |
return -1; |
115 |
|
|
115 |
|
|
116 | 116 |
s->zstream.next_in = s->compressed_block; |
117 | 117 |
s->zstream.avail_in = bytes; |
118 | 118 |
s->zstream.next_out = s->uncompressed_block; |
... | ... | |
123 | 123 |
ret = inflate(&s->zstream, Z_FINISH); |
124 | 124 |
if(ret != Z_STREAM_END || s->zstream.total_out != s->block_size) |
125 | 125 |
return -1; |
126 |
|
|
126 |
|
|
127 | 127 |
s->current_block = block_num; |
128 | 128 |
} |
129 | 129 |
return 0; |
130 | 130 |
} |
131 | 131 |
|
132 |
static int cloop_read(BlockDriverState *bs, int64_t sector_num,
|
|
132 |
static int cloop_read(BlockDriverState *bs, int64_t sector_num, |
|
133 | 133 |
uint8_t *buf, int nb_sectors) |
134 | 134 |
{ |
135 | 135 |
BDRVCloopState *s = bs->opaque; |
Also available in: Unified diff