Revision 7a6f3913 block/bochs.c

b/block/bochs.c
80 80
};
81 81

  
82 82
typedef struct BDRVBochsState {
83
    int fd;
84

  
85 83
    uint32_t *catalog_bitmap;
86 84
    int catalog_size;
87 85

  
......
109 107
    return 0;
110 108
}
111 109

  
112
static int bochs_open(BlockDriverState *bs, const char *filename, int flags)
110
static int bochs_open(BlockDriverState *bs, int flags)
113 111
{
114 112
    BDRVBochsState *s = bs->opaque;
115
    int fd, i;
113
    int i;
116 114
    struct bochs_header bochs;
117 115
    struct bochs_header_v1 header_v1;
118 116

  
119
    fd = open(filename, O_RDONLY | O_BINARY);
120
    if (fd < 0) {
121
        return -1;
122
    }
123

  
124 117
    bs->read_only = 1; // no write support yet
125 118

  
126
    s->fd = fd;
127

  
128
    if (pread(fd, &bochs, sizeof(bochs), 0) != sizeof(bochs)) {
119
    if (bdrv_pread(bs->file, 0, &bochs, sizeof(bochs)) != sizeof(bochs)) {
129 120
        goto fail;
130 121
    }
131 122

  
......
146 137

  
147 138
    s->catalog_size = le32_to_cpu(bochs.extra.redolog.catalog);
148 139
    s->catalog_bitmap = qemu_malloc(s->catalog_size * 4);
149
    if (pread(s->fd, s->catalog_bitmap, s->catalog_size * 4,
150
              le32_to_cpu(bochs.header)) != s->catalog_size * 4)
140
    if (bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap,
141
                   s->catalog_size * 4) != s->catalog_size * 4)
151 142
	goto fail;
152 143
    for (i = 0; i < s->catalog_size; i++)
153 144
	le32_to_cpus(&s->catalog_bitmap[i]);
......
161 152

  
162 153
    return 0;
163 154
 fail:
164
    close(fd);
165 155
    return -1;
166 156
}
167 157

  
......
184 174
	(s->extent_blocks + s->bitmap_blocks));
185 175

  
186 176
    /* read in bitmap for current extent */
187
    if (pread(s->fd, &bitmap_entry, 1, bitmap_offset + (extent_offset / 8))
188
            != 1) {
177
    if (bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8),
178
                   &bitmap_entry, 1) != 1) {
189 179
        return -1;
190 180
    }
191 181

  
......
199 189
static int bochs_read(BlockDriverState *bs, int64_t sector_num,
200 190
                    uint8_t *buf, int nb_sectors)
201 191
{
202
    BDRVBochsState *s = bs->opaque;
203 192
    int ret;
204 193

  
205 194
    while (nb_sectors > 0) {
206 195
        int64_t block_offset = seek_to_sector(bs, sector_num);
207 196
        if (block_offset >= 0) {
208
            ret = pread(s->fd, buf, 512, block_offset);
197
            ret = bdrv_pread(bs->file, block_offset, buf, 512);
209 198
            if (ret != 512) {
210 199
                return -1;
211 200
            }
......
222 211
{
223 212
    BDRVBochsState *s = bs->opaque;
224 213
    qemu_free(s->catalog_bitmap);
225
    close(s->fd);
226 214
}
227 215

  
228 216
static BlockDriver bdrv_bochs = {
229 217
    .format_name	= "bochs",
230 218
    .instance_size	= sizeof(BDRVBochsState),
231 219
    .bdrv_probe		= bochs_probe,
232
    .bdrv_file_open	= bochs_open,
220
    .bdrv_open		= bochs_open,
233 221
    .bdrv_read		= bochs_read,
234 222
    .bdrv_close		= bochs_close,
235 223
};

Also available in: Unified diff