Revision 5efa9d5a

b/block-bochs.c
24 24
 */
25 25
#include "qemu-common.h"
26 26
#include "block_int.h"
27
#include "module.h"
27 28

  
28 29
/**************************************************************/
29 30

  
......
241 242
    close(s->fd);
242 243
}
243 244

  
244
BlockDriver bdrv_bochs = {
245
static BlockDriver bdrv_bochs = {
245 246
    .format_name	= "bochs",
246 247
    .instance_size	= sizeof(BDRVBochsState),
247 248
    .bdrv_probe		= bochs_probe,
......
249 250
    .bdrv_read		= bochs_read,
250 251
    .bdrv_close		= bochs_close,
251 252
};
253

  
254
static void bdrv_bochs_init(void)
255
{
256
    bdrv_register(&bdrv_bochs);
257
}
258

  
259
block_init(bdrv_bochs_init);
b/block-cloop.c
23 23
 */
24 24
#include "qemu-common.h"
25 25
#include "block_int.h"
26
#include "module.h"
26 27
#include <zlib.h>
27 28

  
28 29
typedef struct BDRVCloopState {
......
153 154
    inflateEnd(&s->zstream);
154 155
}
155 156

  
156
BlockDriver bdrv_cloop = {
157
static BlockDriver bdrv_cloop = {
157 158
    .format_name	= "cloop",
158 159
    .instance_size	= sizeof(BDRVCloopState),
159 160
    .bdrv_probe		= cloop_probe,
......
161 162
    .bdrv_read		= cloop_read,
162 163
    .bdrv_close		= cloop_close,
163 164
};
165

  
166
static void bdrv_cloop_init(void)
167
{
168
    bdrv_register(&bdrv_cloop);
169
}
170

  
171
block_init(bdrv_cloop_init);
b/block-cow.c
24 24
#ifndef _WIN32
25 25
#include "qemu-common.h"
26 26
#include "block_int.h"
27
#include "module.h"
27 28
#include <sys/mman.h>
28 29

  
29 30
/**************************************************************/
......
252 253
    fsync(s->fd);
253 254
}
254 255

  
255
BlockDriver bdrv_cow = {
256
static BlockDriver bdrv_cow = {
256 257
    .format_name	= "cow",
257 258
    .instance_size	= sizeof(BDRVCowState),
258 259
    .bdrv_probe		= cow_probe,
......
264 265
    .bdrv_flush		= cow_flush,
265 266
    .bdrv_is_allocated	= cow_is_allocated,
266 267
};
268

  
269
static void bdrv_cow_init(void)
270
{
271
    bdrv_register(&bdrv_cow);
272
}
273

  
274
block_init(bdrv_cow_init);
267 275
#endif
b/block-dmg.c
24 24
#include "qemu-common.h"
25 25
#include "block_int.h"
26 26
#include "bswap.h"
27
#include "module.h"
27 28
#include <zlib.h>
28 29

  
29 30
typedef struct BDRVDMGState {
......
92 93
dmg_close:
93 94
	close(s->fd);
94 95
	/* open raw instead */
95
	bs->drv=&bdrv_raw;
96
	bs->drv=bdrv_find_format("raw");
96 97
	return bs->drv->bdrv_open(bs, filename, flags);
97 98
    }
98 99
    info_begin=read_off(s->fd);
......
283 284
    inflateEnd(&s->zstream);
284 285
}
285 286

  
286
BlockDriver bdrv_dmg = {
287
static BlockDriver bdrv_dmg = {
287 288
    .format_name	= "dmg",
288 289
    .instance_size	= sizeof(BDRVDMGState),
289 290
    .bdrv_probe		= dmg_probe,
......
291 292
    .bdrv_read		= dmg_read,
292 293
    .bdrv_close		= dmg_close,
293 294
};
295

  
296
static void bdrv_dmg_init(void)
297
{
298
    bdrv_register(&bdrv_dmg);
299
}
300

  
301
block_init(bdrv_dmg_init);
b/block-nbd.c
28 28

  
29 29
#include "qemu-common.h"
30 30
#include "nbd.h"
31
#include "module.h"
31 32

  
32 33
#include <sys/types.h>
33 34
#include <unistd.h>
......
176 177
    return s->size;
177 178
}
178 179

  
179
BlockDriver bdrv_nbd = {
180
static BlockDriver bdrv_nbd = {
180 181
    .format_name	= "nbd",
181 182
    .instance_size	= sizeof(BDRVNBDState),
182 183
    .bdrv_open		= nbd_open,
......
186 187
    .bdrv_getlength	= nbd_getlength,
187 188
    .protocol_name	= "nbd",
188 189
};
190

  
191
static void bdrv_nbd_init(void)
192
{
193
    bdrv_register(&bdrv_nbd);
194
}
195

  
196
block_init(bdrv_nbd_init);
b/block-parallels.c
25 25
 */
26 26
#include "qemu-common.h"
27 27
#include "block_int.h"
28
#include "module.h"
28 29

  
29 30
/**************************************************************/
30 31

  
......
163 164
    close(s->fd);
164 165
}
165 166

  
166
BlockDriver bdrv_parallels = {
167
static BlockDriver bdrv_parallels = {
167 168
    .format_name	= "parallels",
168 169
    .instance_size	= sizeof(BDRVParallelsState),
169 170
    .bdrv_probe		= parallels_probe,
......
171 172
    .bdrv_read		= parallels_read,
172 173
    .bdrv_close		= parallels_close,
173 174
};
175

  
176
static void bdrv_parallels_init(void)
177
{
178
    bdrv_register(&bdrv_parallels);
179
}
180

  
181
block_init(bdrv_parallels_init);
b/block-qcow.c
23 23
 */
24 24
#include "qemu-common.h"
25 25
#include "block_int.h"
26
#include "module.h"
26 27
#include <zlib.h>
27 28
#include "aes.h"
28 29

  
......
917 918
    return 0;
918 919
}
919 920

  
920
BlockDriver bdrv_qcow = {
921
static BlockDriver bdrv_qcow = {
921 922
    .format_name	= "qcow",
922 923
    .instance_size	= sizeof(BDRVQcowState),
923 924
    .bdrv_probe		= qcow_probe,
......
935 936
    .bdrv_write_compressed = qcow_write_compressed,
936 937
    .bdrv_get_info	= qcow_get_info,
937 938
};
939

  
940
static void bdrv_qcow_init(void)
941
{
942
    bdrv_register(&bdrv_qcow);
943
}
944

  
945
block_init(bdrv_qcow_init);
b/block-qcow2.c
23 23
 */
24 24
#include "qemu-common.h"
25 25
#include "block_int.h"
26
#include "module.h"
26 27
#include <zlib.h>
27 28
#include "aes.h"
28 29

  
......
2891 2892
    return ret;
2892 2893
}
2893 2894

  
2894
BlockDriver bdrv_qcow2 = {
2895
static BlockDriver bdrv_qcow2 = {
2895 2896
    .format_name	= "qcow2",
2896 2897
    .instance_size	= sizeof(BDRVQcowState),
2897 2898
    .bdrv_probe		= qcow_probe,
......
2921 2922
    .bdrv_create2 = qcow_create2,
2922 2923
    .bdrv_check = qcow_check,
2923 2924
};
2925

  
2926
static void bdrv_qcow2_init(void)
2927
{
2928
    bdrv_register(&bdrv_qcow2);
2929
}
2930

  
2931
block_init(bdrv_qcow2_init);
b/block-raw-posix.c
25 25
#include "qemu-timer.h"
26 26
#include "qemu-char.h"
27 27
#include "block_int.h"
28
#include "module.h"
28 29
#ifdef CONFIG_AIO
29 30
#include "posix-aio-compat.h"
30 31
#endif
......
845 846
    fsync(s->fd);
846 847
}
847 848

  
848
BlockDriver bdrv_raw = {
849
static BlockDriver bdrv_raw = {
849 850
    .format_name = "raw",
850 851
    .instance_size = sizeof(BDRVRawState),
851 852
    .bdrv_probe = NULL, /* no probe for protocols */
......
1397 1398
}
1398 1399
#endif
1399 1400

  
1400
BlockDriver bdrv_host_device = {
1401
static BlockDriver bdrv_host_device = {
1401 1402
    .format_name	= "host_device",
1402 1403
    .instance_size	= sizeof(BDRVRawState),
1403 1404
    .bdrv_open		= hdev_open,
......
1427 1428
    .bdrv_aio_ioctl	= raw_aio_ioctl,
1428 1429
#endif
1429 1430
};
1431

  
1432
static void bdrv_raw_init(void)
1433
{
1434
    bdrv_register(&bdrv_raw);
1435
    bdrv_register(&bdrv_host_device);
1436
}
1437

  
1438
block_init(bdrv_raw_init);
b/block-raw-win32.c
24 24
#include "qemu-common.h"
25 25
#include "qemu-timer.h"
26 26
#include "block_int.h"
27
#include "module.h"
27 28
#include <windows.h>
28 29
#include <winioctl.h>
29 30

  
......
227 228
    return 0;
228 229
}
229 230

  
230
BlockDriver bdrv_raw = {
231
static BlockDriver bdrv_raw = {
231 232
    .format_name	= "raw",
232 233
    .instance_size	= sizeof(BDRVRawState),
233 234
    .bdrv_open		= raw_open,
......
371 372
}
372 373
#endif
373 374

  
374
BlockDriver bdrv_host_device = {
375
static BlockDriver bdrv_host_device = {
375 376
    .format_name	= "host_device",
376 377
    .instance_size	= sizeof(BDRVRawState),
377 378
    .bdrv_open		= hdev_open,
......
382 383
    .bdrv_write	        = raw_write,
383 384
    .bdrv_getlength	= raw_getlength,
384 385
};
386

  
387
static void bdrv_raw_init(void)
388
{
389
    bdrv_register(&bdrv_raw);
390
    bdrv_register(&bdrv_host_device);
391
}
392

  
393
block_init(bdrv_raw_init);
b/block-vmdk.c
25 25

  
26 26
#include "qemu-common.h"
27 27
#include "block_int.h"
28
#include "module.h"
28 29

  
29 30
#define VMDK3_MAGIC (('C' << 24) | ('O' << 16) | ('W' << 8) | 'D')
30 31
#define VMDK4_MAGIC (('K' << 24) | ('D' << 16) | ('M' << 8) | 'V')
......
811 812
    bdrv_flush(s->hd);
812 813
}
813 814

  
814
BlockDriver bdrv_vmdk = {
815
static BlockDriver bdrv_vmdk = {
815 816
    .format_name	= "vmdk",
816 817
    .instance_size	= sizeof(BDRVVmdkState),
817 818
    .bdrv_probe		= vmdk_probe,
......
823 824
    .bdrv_flush		= vmdk_flush,
824 825
    .bdrv_is_allocated	= vmdk_is_allocated,
825 826
};
827

  
828
static void bdrv_vmdk_init(void)
829
{
830
    bdrv_register(&bdrv_vmdk);
831
}
832

  
833
block_init(bdrv_vmdk_init);
b/block-vpc.c
24 24
 */
25 25
#include "qemu-common.h"
26 26
#include "block_int.h"
27
#include "module.h"
27 28

  
28 29
/**************************************************************/
29 30

  
......
586 587
    bdrv_delete(s->hd);
587 588
}
588 589

  
589
BlockDriver bdrv_vpc = {
590
static BlockDriver bdrv_vpc = {
590 591
    .format_name	= "vpc",
591 592
    .instance_size	= sizeof(BDRVVPCState),
592 593
    .bdrv_probe		= vpc_probe,
......
596 597
    .bdrv_close		= vpc_close,
597 598
    .bdrv_create	= vpc_create,
598 599
};
600

  
601
static void bdrv_vpc_init(void)
602
{
603
    bdrv_register(&bdrv_vpc);
604
}
605

  
606
block_init(bdrv_vpc_init);
b/block-vvfat.c
26 26
#include <dirent.h>
27 27
#include "qemu-common.h"
28 28
#include "block_int.h"
29
#include "module.h"
29 30

  
30 31
#ifndef S_IWGRP
31 32
#define S_IWGRP 0
......
2776 2777

  
2777 2778
    s->qcow_filename = qemu_malloc(1024);
2778 2779
    get_tmp_filename(s->qcow_filename, 1024);
2779
    if (bdrv_create(&bdrv_qcow,
2780
    if (bdrv_create(bdrv_find_format("qcow"),
2780 2781
		s->qcow_filename, s->sector_count, "fat:", 0) < 0)
2781 2782
	return -1;
2782 2783
    s->qcow = bdrv_new("");
......
2806 2807
        free(s->cluster_buffer);
2807 2808
}
2808 2809

  
2809
BlockDriver bdrv_vvfat = {
2810
static BlockDriver bdrv_vvfat = {
2810 2811
    .format_name	= "vvfat",
2811 2812
    .instance_size	= sizeof(BDRVVVFATState),
2812 2813
    .bdrv_open		= vvfat_open,
......
2817 2818
    .protocol_name	= "fat",
2818 2819
};
2819 2820

  
2821
static void bdrv_vvfat_init(void)
2822
{
2823
    bdrv_register(&bdrv_vvfat);
2824
}
2825

  
2826
block_init(bdrv_vvfat_init);
2827

  
2820 2828
#ifdef DEBUG
2821 2829
static void checkpoint(void) {
2822 2830
    assert(((mapping_t*)array_get(&(vvv->mapping), 0))->end == 2);
b/block.c
30 30
#include "qemu-common.h"
31 31
#include "monitor.h"
32 32
#include "block_int.h"
33
#include "module.h"
33 34

  
34 35
#ifdef HOST_BSD
35 36
#include <sys/types.h>
......
138 139
}
139 140

  
140 141

  
141
static void bdrv_register(BlockDriver *bdrv)
142
void bdrv_register(BlockDriver *bdrv)
142 143
{
143 144
    if (!bdrv->bdrv_aio_readv) {
144 145
        /* add AIO emulation layer */
......
259 260
#ifdef _WIN32
260 261
    if (is_windows_drive(filename) ||
261 262
        is_windows_drive_prefix(filename))
262
        return &bdrv_raw;
263
        return bdrv_find_format("raw");
263 264
#endif
264 265
    p = strchr(filename, ':');
265 266
    if (!p)
266
        return &bdrv_raw;
267
        return bdrv_find_format("raw");
267 268
    len = p - filename;
268 269
    if (len > sizeof(protocol) - 1)
269 270
        len = sizeof(protocol) - 1;
......
289 290
    /* detect host devices. By convention, /dev/cdrom[N] is always
290 291
       recognized as a host CDROM */
291 292
    if (strstart(filename, "/dev/cdrom", NULL))
292
        return &bdrv_host_device;
293
        return bdrv_find_format("host_device");
293 294
#ifdef _WIN32
294 295
    if (is_windows_drive(filename))
295
        return &bdrv_host_device;
296
        return bdrv_find_format("host_device");
296 297
#else
297 298
    {
298 299
        struct stat st;
299 300
        if (stat(filename, &st) >= 0 &&
300 301
            (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) {
301
            return &bdrv_host_device;
302
            return bdrv_find_format("host_device");
302 303
        }
303 304
    }
304 305
#endif
305 306

  
306 307
    drv = find_protocol(filename);
307 308
    /* no need to test disk image formats for vvfat */
308
    if (drv == &bdrv_vvfat)
309
    if (strcmp(drv->format_name, "vvfat") == 0)
309 310
        return drv;
310 311

  
311 312
    ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
......
396 397
        else
397 398
            realpath(filename, backing_filename);
398 399

  
399
        ret = bdrv_create2(&bdrv_qcow2, tmp_filename,
400
        ret = bdrv_create2(bdrv_find_format("qcow2"), tmp_filename,
400 401
                           total_size, backing_filename, 
401 402
                           (drv ? drv->format_name : NULL), 0);
402 403
        if (ret < 0) {
403 404
            return ret;
404 405
        }
405 406
        filename = tmp_filename;
406
        drv = &bdrv_qcow2;
407
        drv = bdrv_find_format("qcow2");
407 408
        bs->is_temporary = 1;
408 409
    }
409 410

  
......
1494 1495

  
1495 1496
void bdrv_init(void)
1496 1497
{
1497
    bdrv_register(&bdrv_raw);
1498
    bdrv_register(&bdrv_host_device);
1499
#ifndef _WIN32
1500
    bdrv_register(&bdrv_cow);
1501
#endif
1502
    bdrv_register(&bdrv_qcow);
1503
    bdrv_register(&bdrv_vmdk);
1504
    bdrv_register(&bdrv_cloop);
1505
    bdrv_register(&bdrv_dmg);
1506
    bdrv_register(&bdrv_bochs);
1507
    bdrv_register(&bdrv_vpc);
1508
    bdrv_register(&bdrv_vvfat);
1509
    bdrv_register(&bdrv_qcow2);
1510
    bdrv_register(&bdrv_parallels);
1511
    bdrv_register(&bdrv_nbd);
1498
    module_call_init(MODULE_INIT_BLOCK);
1512 1499
}
1513 1500

  
1514 1501
void aio_pool_init(AIOPool *pool, int aiocb_size,
b/block.h
7 7
/* block.c */
8 8
typedef struct BlockDriver BlockDriver;
9 9

  
10
extern BlockDriver bdrv_raw;
11
extern BlockDriver bdrv_host_device;
12
extern BlockDriver bdrv_cow;
13
extern BlockDriver bdrv_qcow;
14
extern BlockDriver bdrv_vmdk;
15
extern BlockDriver bdrv_cloop;
16
extern BlockDriver bdrv_dmg;
17
extern BlockDriver bdrv_bochs;
18
extern BlockDriver bdrv_vpc;
19
extern BlockDriver bdrv_vvfat;
20
extern BlockDriver bdrv_qcow2;
21
extern BlockDriver bdrv_parallels;
22
extern BlockDriver bdrv_nbd;
23

  
24 10
typedef struct BlockDriverInfo {
25 11
    /* in bytes, 0 if irrelevant */
26 12
    int cluster_size;
......
87 73
void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
88 74
void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs);
89 75
int bdrv_commit(BlockDriverState *bs);
76
void bdrv_register(BlockDriver *bdrv);
77

  
90 78
/* async block I/O */
91 79
typedef struct BlockDriverAIOCB BlockDriverAIOCB;
92 80
typedef void BlockDriverCompletionFunc(void *opaque, int ret);
b/qemu-img.c
542 542
    drv = bdrv_find_format(out_fmt);
543 543
    if (!drv)
544 544
        error("Unknown file format '%s'", out_fmt);
545
    if (flags & BLOCK_FLAG_COMPRESS && drv != &bdrv_qcow && drv != &bdrv_qcow2)
545
    if (flags & BLOCK_FLAG_COMPRESS && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2"))
546 546
        error("Compression not supported for this file format");
547
    if (flags & BLOCK_FLAG_ENCRYPT && drv != &bdrv_qcow && drv != &bdrv_qcow2)
547
    if (flags & BLOCK_FLAG_ENCRYPT && strcmp(drv->format_name, "qcow") && strcmp(drv->format_name, "qcow2"))
548 548
        error("Encryption not supported for this file format");
549
    if (flags & BLOCK_FLAG_COMPAT6 && drv != &bdrv_vmdk)
549
    if (flags & BLOCK_FLAG_COMPAT6 && strcmp(drv->format_name, "vmdk"))
550 550
        error("Alternative compatibility level not supported for this file format");
551 551
    if (flags & BLOCK_FLAG_ENCRYPT && flags & BLOCK_FLAG_COMPRESS)
552 552
        error("Compression and encryption not supported at the same time");
......
655 655
            if (n > bs_offset + bs_sectors - sector_num)
656 656
                n = bs_offset + bs_sectors - sector_num;
657 657

  
658
            if (drv != &bdrv_host_device) {
658
            if (strcmp(drv->format_name, "host_device")) {
659 659
                if (!bdrv_is_allocated(bs[bs_i], sector_num - bs_offset,
660 660
                                       n, &n1)) {
661 661
                    sector_num += n1;
......
682 682
                   If the output is to a host device, we also write out
683 683
                   sectors that are entirely 0, since whatever data was
684 684
                   already there is garbage, not 0s. */
685
                if (drv == &bdrv_host_device || out_baseimg ||
685
                if (strcmp(drv->format_name, "host_device") == 0 || out_baseimg ||
686 686
                    is_allocated_sectors(buf1, n, &n1)) {
687 687
                    if (bdrv_write(out_bs, sector_num, buf1, n1) < 0)
688 688
                        error("error while writing");

Also available in: Unified diff