2 #include "qemu-common.h"
6 static int raw_open(BlockDriverState
*bs
, int flags
)
12 static int coroutine_fn
raw_co_readv(BlockDriverState
*bs
, int64_t sector_num
,
13 int nb_sectors
, QEMUIOVector
*qiov
)
15 BLKDBG_EVENT(bs
->file
, BLKDBG_READ_AIO
);
16 return bdrv_co_readv(bs
->file
, sector_num
, nb_sectors
, qiov
);
19 static int coroutine_fn
raw_co_writev(BlockDriverState
*bs
, int64_t sector_num
,
20 int nb_sectors
, QEMUIOVector
*qiov
)
22 BLKDBG_EVENT(bs
->file
, BLKDBG_WRITE_AIO
);
23 return bdrv_co_writev(bs
->file
, sector_num
, nb_sectors
, qiov
);
26 static void raw_close(BlockDriverState
*bs
)
30 static int coroutine_fn
raw_co_is_allocated(BlockDriverState
*bs
,
32 int nb_sectors
, int *pnum
)
34 return bdrv_co_is_allocated(bs
->file
, sector_num
, nb_sectors
, pnum
);
37 static int64_t raw_getlength(BlockDriverState
*bs
)
39 return bdrv_getlength(bs
->file
);
42 static int raw_truncate(BlockDriverState
*bs
, int64_t offset
)
44 return bdrv_truncate(bs
->file
, offset
);
47 static int raw_probe(const uint8_t *buf
, int buf_size
, const char *filename
)
49 return 1; /* everything can be opened as raw image */
52 static int coroutine_fn
raw_co_discard(BlockDriverState
*bs
,
53 int64_t sector_num
, int nb_sectors
)
55 return bdrv_co_discard(bs
->file
, sector_num
, nb_sectors
);
58 static int raw_is_inserted(BlockDriverState
*bs
)
60 return bdrv_is_inserted(bs
->file
);
63 static int raw_media_changed(BlockDriverState
*bs
)
65 return bdrv_media_changed(bs
->file
);
68 static void raw_eject(BlockDriverState
*bs
, bool eject_flag
)
70 bdrv_eject(bs
->file
, eject_flag
);
73 static void raw_lock_medium(BlockDriverState
*bs
, bool locked
)
75 bdrv_lock_medium(bs
->file
, locked
);
78 static int raw_ioctl(BlockDriverState
*bs
, unsigned long int req
, void *buf
)
80 return bdrv_ioctl(bs
->file
, req
, buf
);
83 static BlockDriverAIOCB
*raw_aio_ioctl(BlockDriverState
*bs
,
84 unsigned long int req
, void *buf
,
85 BlockDriverCompletionFunc
*cb
, void *opaque
)
87 return bdrv_aio_ioctl(bs
->file
, req
, buf
, cb
, opaque
);
90 static int raw_create(const char *filename
, QEMUOptionParameter
*options
)
92 return bdrv_create_file(filename
, options
);
95 static QEMUOptionParameter raw_create_options
[] = {
97 .name
= BLOCK_OPT_SIZE
,
99 .help
= "Virtual disk size"
104 static int raw_has_zero_init(BlockDriverState
*bs
)
106 return bdrv_has_zero_init(bs
->file
);
109 static BlockDriver bdrv_raw
= {
110 .format_name
= "raw",
112 /* It's really 0, but we need to make g_malloc() happy */
115 .bdrv_open
= raw_open
,
116 .bdrv_close
= raw_close
,
118 .bdrv_co_readv
= raw_co_readv
,
119 .bdrv_co_writev
= raw_co_writev
,
120 .bdrv_co_is_allocated
= raw_co_is_allocated
,
121 .bdrv_co_discard
= raw_co_discard
,
123 .bdrv_probe
= raw_probe
,
124 .bdrv_getlength
= raw_getlength
,
125 .bdrv_truncate
= raw_truncate
,
127 .bdrv_is_inserted
= raw_is_inserted
,
128 .bdrv_media_changed
= raw_media_changed
,
129 .bdrv_eject
= raw_eject
,
130 .bdrv_lock_medium
= raw_lock_medium
,
132 .bdrv_ioctl
= raw_ioctl
,
133 .bdrv_aio_ioctl
= raw_aio_ioctl
,
135 .bdrv_create
= raw_create
,
136 .create_options
= raw_create_options
,
137 .bdrv_has_zero_init
= raw_has_zero_init
,
140 static void bdrv_raw_init(void)
142 bdrv_register(&bdrv_raw
);
145 block_init(bdrv_raw_init
);