Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 1 | |
| 2 | #include "qemu-common.h" |
| 3 | #include "block_int.h" |
| 4 | #include "module.h" |
| 5 | |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 6 | static int raw_open(BlockDriverState *bs, int flags) |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 7 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 8 | bs->sg = bs->file->sg; |
| 9 | return 0; |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 10 | } |
| 11 | |
| 12 | static int raw_read(BlockDriverState *bs, int64_t sector_num, |
| 13 | uint8_t *buf, int nb_sectors) |
| 14 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 15 | return bdrv_read(bs->file, sector_num, buf, nb_sectors); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | static int raw_write(BlockDriverState *bs, int64_t sector_num, |
| 19 | const uint8_t *buf, int nb_sectors) |
| 20 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 21 | return bdrv_write(bs->file, sector_num, buf, nb_sectors); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs, |
| 25 | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, |
| 26 | BlockDriverCompletionFunc *cb, void *opaque) |
| 27 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 28 | return bdrv_aio_readv(bs->file, sector_num, qiov, nb_sectors, cb, opaque); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs, |
| 32 | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, |
| 33 | BlockDriverCompletionFunc *cb, void *opaque) |
| 34 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 35 | return bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, cb, opaque); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static void raw_close(BlockDriverState *bs) |
| 39 | { |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void raw_flush(BlockDriverState *bs) |
| 43 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 44 | bdrv_flush(bs->file); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static BlockDriverAIOCB *raw_aio_flush(BlockDriverState *bs, |
| 48 | BlockDriverCompletionFunc *cb, void *opaque) |
| 49 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 50 | return bdrv_aio_flush(bs->file, cb, opaque); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static int64_t raw_getlength(BlockDriverState *bs) |
| 54 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 55 | return bdrv_getlength(bs->file); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static int raw_truncate(BlockDriverState *bs, int64_t offset) |
| 59 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 60 | return bdrv_truncate(bs->file, offset); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static int raw_probe(const uint8_t *buf, int buf_size, const char *filename) |
| 64 | { |
| 65 | return 1; /* everything can be opened as raw image */ |
| 66 | } |
| 67 | |
| 68 | static int raw_is_inserted(BlockDriverState *bs) |
| 69 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 70 | return bdrv_is_inserted(bs->file); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static int raw_eject(BlockDriverState *bs, int eject_flag) |
| 74 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 75 | return bdrv_eject(bs->file, eject_flag); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | static int raw_set_locked(BlockDriverState *bs, int locked) |
| 79 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 80 | bdrv_set_locked(bs->file, locked); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) |
| 85 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 86 | return bdrv_ioctl(bs->file, req, buf); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs, |
| 90 | unsigned long int req, void *buf, |
| 91 | BlockDriverCompletionFunc *cb, void *opaque) |
| 92 | { |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 93 | return bdrv_aio_ioctl(bs->file, req, buf, cb, opaque); |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static int raw_create(const char *filename, QEMUOptionParameter *options) |
| 97 | { |
| 98 | return bdrv_create_file(filename, options); |
| 99 | } |
| 100 | |
| 101 | static QEMUOptionParameter raw_create_options[] = { |
| 102 | { |
| 103 | .name = BLOCK_OPT_SIZE, |
| 104 | .type = OPT_SIZE, |
| 105 | .help = "Virtual disk size" |
| 106 | }, |
| 107 | { NULL } |
| 108 | }; |
| 109 | |
| 110 | static BlockDriver bdrv_raw = { |
| 111 | .format_name = "raw", |
| 112 | |
Kevin Wolf | 66f82ce | 2010-04-14 14:17:38 +0200 | [diff] [blame] | 113 | /* It's really 0, but we need to make qemu_malloc() happy */ |
| 114 | .instance_size = 1, |
Christoph Hellwig | 84a12e6 | 2010-04-07 22:30:24 +0200 | [diff] [blame] | 115 | |
| 116 | .bdrv_open = raw_open, |
| 117 | .bdrv_close = raw_close, |
| 118 | .bdrv_read = raw_read, |
| 119 | .bdrv_write = raw_write, |
| 120 | .bdrv_flush = raw_flush, |
| 121 | .bdrv_probe = raw_probe, |
| 122 | .bdrv_getlength = raw_getlength, |
| 123 | .bdrv_truncate = raw_truncate, |
| 124 | |
| 125 | .bdrv_aio_readv = raw_aio_readv, |
| 126 | .bdrv_aio_writev = raw_aio_writev, |
| 127 | .bdrv_aio_flush = raw_aio_flush, |
| 128 | |
| 129 | .bdrv_is_inserted = raw_is_inserted, |
| 130 | .bdrv_eject = raw_eject, |
| 131 | .bdrv_set_locked = raw_set_locked, |
| 132 | .bdrv_ioctl = raw_ioctl, |
| 133 | .bdrv_aio_ioctl = raw_aio_ioctl, |
| 134 | |
| 135 | .bdrv_create = raw_create, |
| 136 | .create_options = raw_create_options, |
| 137 | }; |
| 138 | |
| 139 | static void bdrv_raw_init(void) |
| 140 | { |
| 141 | bdrv_register(&bdrv_raw); |
| 142 | } |
| 143 | |
| 144 | block_init(bdrv_raw_init); |