bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 1 | /* |
ths | 223d467 | 2007-12-15 17:28:36 +0000 | [diff] [blame] | 2 | * Block driver for RAW files (posix) |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 4 | * Copyright (c) 2006 Fabrice Bellard |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 5 | * |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
pbrook | faf0796 | 2007-11-11 02:51:17 +0000 | [diff] [blame] | 24 | #include "qemu-common.h" |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 25 | #include "qemu-timer.h" |
aliguori | baf35cb | 2008-09-10 15:45:19 +0000 | [diff] [blame] | 26 | #include "qemu-char.h" |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 27 | #include "block_int.h" |
Anthony Liguori | 5efa9d5 | 2009-05-09 17:03:42 -0500 | [diff] [blame] | 28 | #include "module.h" |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 29 | #ifdef CONFIG_AIO |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 30 | #include "posix-aio-compat.h" |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 31 | #endif |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 32 | |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 33 | #ifdef CONFIG_COCOA |
| 34 | #include <paths.h> |
| 35 | #include <sys/param.h> |
| 36 | #include <IOKit/IOKitLib.h> |
| 37 | #include <IOKit/IOBSD.h> |
| 38 | #include <IOKit/storage/IOMediaBSDClient.h> |
| 39 | #include <IOKit/storage/IOMedia.h> |
| 40 | #include <IOKit/storage/IOCDMedia.h> |
| 41 | //#include <IOKit/storage/IOCDTypes.h> |
| 42 | #include <CoreFoundation/CoreFoundation.h> |
| 43 | #endif |
| 44 | |
| 45 | #ifdef __sun__ |
ths | 2e9671d | 2007-01-05 17:44:41 +0000 | [diff] [blame] | 46 | #define _POSIX_PTHREAD_SEMANTICS 1 |
| 47 | #include <signal.h> |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 48 | #include <sys/dkio.h> |
| 49 | #endif |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 50 | #ifdef __linux__ |
| 51 | #include <sys/ioctl.h> |
| 52 | #include <linux/cdrom.h> |
| 53 | #include <linux/fd.h> |
| 54 | #endif |
ths | 1cb6c3f | 2006-12-21 19:14:11 +0000 | [diff] [blame] | 55 | #ifdef __FreeBSD__ |
blueswir1 | 543952c | 2008-08-24 10:43:12 +0000 | [diff] [blame] | 56 | #include <signal.h> |
ths | 1cb6c3f | 2006-12-21 19:14:11 +0000 | [diff] [blame] | 57 | #include <sys/disk.h> |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 58 | #include <sys/cdio.h> |
ths | 1cb6c3f | 2006-12-21 19:14:11 +0000 | [diff] [blame] | 59 | #endif |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 60 | |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 61 | #ifdef __OpenBSD__ |
| 62 | #include <sys/ioctl.h> |
| 63 | #include <sys/disklabel.h> |
| 64 | #include <sys/dkio.h> |
| 65 | #endif |
| 66 | |
blueswir1 | c5e9723 | 2009-03-07 20:06:23 +0000 | [diff] [blame] | 67 | #ifdef __DragonFly__ |
| 68 | #include <sys/ioctl.h> |
| 69 | #include <sys/diskslice.h> |
| 70 | #endif |
| 71 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 72 | //#define DEBUG_FLOPPY |
| 73 | |
pbrook | faf0796 | 2007-11-11 02:51:17 +0000 | [diff] [blame] | 74 | //#define DEBUG_BLOCK |
aliguori | 03ff3ca | 2008-09-15 15:51:35 +0000 | [diff] [blame] | 75 | #if defined(DEBUG_BLOCK) |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 76 | #define DEBUG_BLOCK_PRINT(formatCstr, ...) do { if (qemu_log_enabled()) \ |
| 77 | { qemu_log(formatCstr, ## __VA_ARGS__); qemu_log_flush(); } } while (0) |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 78 | #else |
Blue Swirl | 001faf3 | 2009-05-13 17:53:17 +0000 | [diff] [blame] | 79 | #define DEBUG_BLOCK_PRINT(formatCstr, ...) |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 80 | #endif |
| 81 | |
aliguori | f646557 | 2008-10-14 18:00:38 +0000 | [diff] [blame] | 82 | /* OS X does not have O_DSYNC */ |
| 83 | #ifndef O_DSYNC |
aliguori | 7ab064d | 2008-10-14 18:14:47 +0000 | [diff] [blame] | 84 | #define O_DSYNC O_SYNC |
aliguori | f646557 | 2008-10-14 18:00:38 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |
aliguori | 9f7965c | 2008-10-14 14:42:54 +0000 | [diff] [blame] | 87 | /* Approximate O_DIRECT with O_DSYNC if O_DIRECT isn't available */ |
| 88 | #ifndef O_DIRECT |
| 89 | #define O_DIRECT O_DSYNC |
| 90 | #endif |
| 91 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 92 | #define FTYPE_FILE 0 |
| 93 | #define FTYPE_CD 1 |
| 94 | #define FTYPE_FD 2 |
| 95 | |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 96 | #define ALIGNED_BUFFER_SIZE (32 * 512) |
| 97 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 98 | /* if the FD is not accessed during that time (in ms), we try to |
| 99 | reopen it to see if the disk has been changed */ |
| 100 | #define FD_OPEN_TIMEOUT 1000 |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 101 | |
| 102 | typedef struct BDRVRawState { |
| 103 | int fd; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 104 | int type; |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 105 | unsigned int lseek_err_cnt; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 106 | #if defined(__linux__) |
| 107 | /* linux floppy specific */ |
blueswir1 | 6dd2db5 | 2008-05-07 15:26:22 +0000 | [diff] [blame] | 108 | int fd_open_flags; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 109 | int64_t fd_open_time; |
| 110 | int64_t fd_error_time; |
| 111 | int fd_got_error; |
| 112 | int fd_media_changed; |
| 113 | #endif |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 114 | #if defined(__FreeBSD__) |
| 115 | int cd_open_flags; |
| 116 | #endif |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 117 | uint8_t* aligned_buf; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 118 | } BDRVRawState; |
| 119 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 120 | static int posix_aio_init(void); |
| 121 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 122 | static int fd_open(BlockDriverState *bs); |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 123 | |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 124 | #if defined(__FreeBSD__) |
| 125 | static int cd_open(BlockDriverState *bs); |
| 126 | #endif |
| 127 | |
| 128 | static int raw_is_inserted(BlockDriverState *bs); |
| 129 | |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 130 | static int raw_open(BlockDriverState *bs, const char *filename, int flags) |
| 131 | { |
| 132 | BDRVRawState *s = bs->opaque; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 133 | int fd, open_flags, ret; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 134 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 135 | posix_aio_init(); |
| 136 | |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 137 | s->lseek_err_cnt = 0; |
| 138 | |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 139 | open_flags = O_BINARY; |
| 140 | if ((flags & BDRV_O_ACCESS) == O_RDWR) { |
| 141 | open_flags |= O_RDWR; |
| 142 | } else { |
| 143 | open_flags |= O_RDONLY; |
| 144 | bs->read_only = 1; |
| 145 | } |
| 146 | if (flags & BDRV_O_CREAT) |
| 147 | open_flags |= O_CREAT | O_TRUNC; |
aliguori | 9f7965c | 2008-10-14 14:42:54 +0000 | [diff] [blame] | 148 | |
| 149 | /* Use O_DSYNC for write-through caching, no flags for write-back caching, |
| 150 | * and O_DIRECT for no caching. */ |
| 151 | if ((flags & BDRV_O_NOCACHE)) |
balrog | 33f0027 | 2007-12-24 14:33:24 +0000 | [diff] [blame] | 152 | open_flags |= O_DIRECT; |
aliguori | 9f7965c | 2008-10-14 14:42:54 +0000 | [diff] [blame] | 153 | else if (!(flags & BDRV_O_CACHE_WB)) |
| 154 | open_flags |= O_DSYNC; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 155 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 156 | s->type = FTYPE_FILE; |
| 157 | |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 158 | fd = open(filename, open_flags, 0644); |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 159 | if (fd < 0) { |
| 160 | ret = -errno; |
| 161 | if (ret == -EROFS) |
| 162 | ret = -EACCES; |
| 163 | return ret; |
| 164 | } |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 165 | s->fd = fd; |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 166 | s->aligned_buf = NULL; |
aliguori | 9f7965c | 2008-10-14 14:42:54 +0000 | [diff] [blame] | 167 | if ((flags & BDRV_O_NOCACHE)) { |
aliguori | e268ca5 | 2009-04-22 20:20:00 +0000 | [diff] [blame] | 168 | s->aligned_buf = qemu_blockalign(bs, ALIGNED_BUFFER_SIZE); |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 169 | if (s->aligned_buf == NULL) { |
| 170 | ret = -errno; |
| 171 | close(fd); |
| 172 | return ret; |
| 173 | } |
| 174 | } |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /* XXX: use host sector size if necessary with: |
| 179 | #ifdef DIOCGSECTORSIZE |
| 180 | { |
| 181 | unsigned int sectorsize = 512; |
| 182 | if (!ioctl(fd, DIOCGSECTORSIZE, §orsize) && |
| 183 | sectorsize > bufsize) |
| 184 | bufsize = sectorsize; |
| 185 | } |
| 186 | #endif |
| 187 | #ifdef CONFIG_COCOA |
| 188 | u_int32_t blockSize = 512; |
| 189 | if ( !ioctl( fd, DKIOCGETBLOCKSIZE, &blockSize ) && blockSize > bufsize) { |
| 190 | bufsize = blockSize; |
| 191 | } |
| 192 | #endif |
| 193 | */ |
| 194 | |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 195 | /* |
| 196 | * offset and count are in bytes, but must be multiples of 512 for files |
| 197 | * opened with O_DIRECT. buf must be aligned to 512 bytes then. |
| 198 | * |
| 199 | * This function may be called without alignment if the caller ensures |
| 200 | * that O_DIRECT is not in effect. |
| 201 | */ |
| 202 | static int raw_pread_aligned(BlockDriverState *bs, int64_t offset, |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 203 | uint8_t *buf, int count) |
| 204 | { |
| 205 | BDRVRawState *s = bs->opaque; |
| 206 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 207 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 208 | ret = fd_open(bs); |
| 209 | if (ret < 0) |
| 210 | return ret; |
| 211 | |
ths | 985a03b | 2007-12-24 16:10:43 +0000 | [diff] [blame] | 212 | if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 213 | ++(s->lseek_err_cnt); |
| 214 | if(s->lseek_err_cnt <= 10) { |
j_mayer | 9286841 | 2007-09-21 06:09:39 +0000 | [diff] [blame] | 215 | DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 |
| 216 | "] lseek failed : %d = %s\n", |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 217 | s->fd, bs->filename, offset, buf, count, |
| 218 | bs->total_sectors, errno, strerror(errno)); |
| 219 | } |
| 220 | return -1; |
| 221 | } |
| 222 | s->lseek_err_cnt=0; |
| 223 | |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 224 | ret = read(s->fd, buf, count); |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 225 | if (ret == count) |
| 226 | goto label__raw_read__success; |
| 227 | |
j_mayer | 9286841 | 2007-09-21 06:09:39 +0000 | [diff] [blame] | 228 | DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 |
| 229 | "] read failed %d : %d = %s\n", |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 230 | s->fd, bs->filename, offset, buf, count, |
| 231 | bs->total_sectors, ret, errno, strerror(errno)); |
| 232 | |
| 233 | /* Try harder for CDrom. */ |
| 234 | if (bs->type == BDRV_TYPE_CDROM) { |
| 235 | lseek(s->fd, offset, SEEK_SET); |
| 236 | ret = read(s->fd, buf, count); |
| 237 | if (ret == count) |
| 238 | goto label__raw_read__success; |
| 239 | lseek(s->fd, offset, SEEK_SET); |
| 240 | ret = read(s->fd, buf, count); |
| 241 | if (ret == count) |
| 242 | goto label__raw_read__success; |
| 243 | |
j_mayer | 9286841 | 2007-09-21 06:09:39 +0000 | [diff] [blame] | 244 | DEBUG_BLOCK_PRINT("raw_pread(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 |
| 245 | "] retry read failed %d : %d = %s\n", |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 246 | s->fd, bs->filename, offset, buf, count, |
| 247 | bs->total_sectors, ret, errno, strerror(errno)); |
| 248 | } |
| 249 | |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 250 | label__raw_read__success: |
| 251 | |
Christoph Hellwig | 94c6d6d | 2009-05-25 10:08:52 +0200 | [diff] [blame^] | 252 | return (ret < 0) ? -errno : ret; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 253 | } |
| 254 | |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 255 | /* |
| 256 | * offset and count are in bytes, but must be multiples of 512 for files |
| 257 | * opened with O_DIRECT. buf must be aligned to 512 bytes then. |
| 258 | * |
| 259 | * This function may be called without alignment if the caller ensures |
| 260 | * that O_DIRECT is not in effect. |
| 261 | */ |
| 262 | static int raw_pwrite_aligned(BlockDriverState *bs, int64_t offset, |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 263 | const uint8_t *buf, int count) |
| 264 | { |
| 265 | BDRVRawState *s = bs->opaque; |
| 266 | int ret; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 267 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 268 | ret = fd_open(bs); |
| 269 | if (ret < 0) |
aliguori | 4141d4c | 2009-01-15 20:44:26 +0000 | [diff] [blame] | 270 | return -errno; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 271 | |
ths | 985a03b | 2007-12-24 16:10:43 +0000 | [diff] [blame] | 272 | if (offset >= 0 && lseek(s->fd, offset, SEEK_SET) == (off_t)-1) { |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 273 | ++(s->lseek_err_cnt); |
| 274 | if(s->lseek_err_cnt) { |
j_mayer | 9286841 | 2007-09-21 06:09:39 +0000 | [diff] [blame] | 275 | DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %" PRId64 ", %p, %d) [%" |
| 276 | PRId64 "] lseek failed : %d = %s\n", |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 277 | s->fd, bs->filename, offset, buf, count, |
| 278 | bs->total_sectors, errno, strerror(errno)); |
| 279 | } |
aliguori | 4141d4c | 2009-01-15 20:44:26 +0000 | [diff] [blame] | 280 | return -EIO; |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 281 | } |
| 282 | s->lseek_err_cnt = 0; |
| 283 | |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 284 | ret = write(s->fd, buf, count); |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 285 | if (ret == count) |
| 286 | goto label__raw_write__success; |
| 287 | |
j_mayer | 9286841 | 2007-09-21 06:09:39 +0000 | [diff] [blame] | 288 | DEBUG_BLOCK_PRINT("raw_pwrite(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 |
| 289 | "] write failed %d : %d = %s\n", |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 290 | s->fd, bs->filename, offset, buf, count, |
| 291 | bs->total_sectors, ret, errno, strerror(errno)); |
| 292 | |
ths | 8c05dbf | 2007-09-13 12:29:23 +0000 | [diff] [blame] | 293 | label__raw_write__success: |
| 294 | |
aliguori | 4141d4c | 2009-01-15 20:44:26 +0000 | [diff] [blame] | 295 | return (ret < 0) ? -errno : ret; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 296 | } |
| 297 | |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 298 | |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 299 | /* |
| 300 | * offset and count are in bytes and possibly not aligned. For files opened |
| 301 | * with O_DIRECT, necessary alignments are ensured before calling |
| 302 | * raw_pread_aligned to do the actual read. |
| 303 | */ |
| 304 | static int raw_pread(BlockDriverState *bs, int64_t offset, |
| 305 | uint8_t *buf, int count) |
| 306 | { |
| 307 | BDRVRawState *s = bs->opaque; |
| 308 | int size, ret, shift, sum; |
| 309 | |
| 310 | sum = 0; |
| 311 | |
| 312 | if (s->aligned_buf != NULL) { |
| 313 | |
| 314 | if (offset & 0x1ff) { |
| 315 | /* align offset on a 512 bytes boundary */ |
| 316 | |
| 317 | shift = offset & 0x1ff; |
| 318 | size = (shift + count + 0x1ff) & ~0x1ff; |
| 319 | if (size > ALIGNED_BUFFER_SIZE) |
| 320 | size = ALIGNED_BUFFER_SIZE; |
| 321 | ret = raw_pread_aligned(bs, offset - shift, s->aligned_buf, size); |
| 322 | if (ret < 0) |
| 323 | return ret; |
| 324 | |
| 325 | size = 512 - shift; |
| 326 | if (size > count) |
| 327 | size = count; |
| 328 | memcpy(buf, s->aligned_buf + shift, size); |
| 329 | |
| 330 | buf += size; |
| 331 | offset += size; |
| 332 | count -= size; |
| 333 | sum += size; |
| 334 | |
| 335 | if (count == 0) |
| 336 | return sum; |
| 337 | } |
| 338 | if (count & 0x1ff || (uintptr_t) buf & 0x1ff) { |
| 339 | |
| 340 | /* read on aligned buffer */ |
| 341 | |
| 342 | while (count) { |
| 343 | |
| 344 | size = (count + 0x1ff) & ~0x1ff; |
| 345 | if (size > ALIGNED_BUFFER_SIZE) |
| 346 | size = ALIGNED_BUFFER_SIZE; |
| 347 | |
| 348 | ret = raw_pread_aligned(bs, offset, s->aligned_buf, size); |
| 349 | if (ret < 0) |
| 350 | return ret; |
| 351 | |
| 352 | size = ret; |
| 353 | if (size > count) |
| 354 | size = count; |
| 355 | |
| 356 | memcpy(buf, s->aligned_buf, size); |
| 357 | |
| 358 | buf += size; |
| 359 | offset += size; |
| 360 | count -= size; |
| 361 | sum += size; |
| 362 | } |
| 363 | |
| 364 | return sum; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | return raw_pread_aligned(bs, offset, buf, count) + sum; |
| 369 | } |
| 370 | |
aliguori | eda578e | 2009-03-12 19:57:16 +0000 | [diff] [blame] | 371 | static int raw_read(BlockDriverState *bs, int64_t sector_num, |
| 372 | uint8_t *buf, int nb_sectors) |
| 373 | { |
aliguori | 537a1d4 | 2009-03-13 03:12:03 +0000 | [diff] [blame] | 374 | int ret; |
| 375 | |
| 376 | ret = raw_pread(bs, sector_num * 512, buf, nb_sectors * 512); |
| 377 | if (ret == (nb_sectors * 512)) |
| 378 | ret = 0; |
| 379 | return ret; |
aliguori | eda578e | 2009-03-12 19:57:16 +0000 | [diff] [blame] | 380 | } |
| 381 | |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 382 | /* |
| 383 | * offset and count are in bytes and possibly not aligned. For files opened |
| 384 | * with O_DIRECT, necessary alignments are ensured before calling |
| 385 | * raw_pwrite_aligned to do the actual write. |
| 386 | */ |
| 387 | static int raw_pwrite(BlockDriverState *bs, int64_t offset, |
| 388 | const uint8_t *buf, int count) |
| 389 | { |
| 390 | BDRVRawState *s = bs->opaque; |
| 391 | int size, ret, shift, sum; |
| 392 | |
| 393 | sum = 0; |
| 394 | |
| 395 | if (s->aligned_buf != NULL) { |
| 396 | |
| 397 | if (offset & 0x1ff) { |
| 398 | /* align offset on a 512 bytes boundary */ |
| 399 | shift = offset & 0x1ff; |
| 400 | ret = raw_pread_aligned(bs, offset - shift, s->aligned_buf, 512); |
| 401 | if (ret < 0) |
| 402 | return ret; |
| 403 | |
| 404 | size = 512 - shift; |
| 405 | if (size > count) |
| 406 | size = count; |
| 407 | memcpy(s->aligned_buf + shift, buf, size); |
| 408 | |
| 409 | ret = raw_pwrite_aligned(bs, offset - shift, s->aligned_buf, 512); |
| 410 | if (ret < 0) |
| 411 | return ret; |
| 412 | |
| 413 | buf += size; |
| 414 | offset += size; |
| 415 | count -= size; |
| 416 | sum += size; |
| 417 | |
| 418 | if (count == 0) |
| 419 | return sum; |
| 420 | } |
| 421 | if (count & 0x1ff || (uintptr_t) buf & 0x1ff) { |
| 422 | |
| 423 | while ((size = (count & ~0x1ff)) != 0) { |
| 424 | |
| 425 | if (size > ALIGNED_BUFFER_SIZE) |
| 426 | size = ALIGNED_BUFFER_SIZE; |
| 427 | |
| 428 | memcpy(s->aligned_buf, buf, size); |
| 429 | |
| 430 | ret = raw_pwrite_aligned(bs, offset, s->aligned_buf, size); |
| 431 | if (ret < 0) |
| 432 | return ret; |
| 433 | |
| 434 | buf += ret; |
| 435 | offset += ret; |
| 436 | count -= ret; |
| 437 | sum += ret; |
| 438 | } |
| 439 | /* here, count < 512 because (count & ~0x1ff) == 0 */ |
| 440 | if (count) { |
| 441 | ret = raw_pread_aligned(bs, offset, s->aligned_buf, 512); |
| 442 | if (ret < 0) |
| 443 | return ret; |
| 444 | memcpy(s->aligned_buf, buf, count); |
| 445 | |
| 446 | ret = raw_pwrite_aligned(bs, offset, s->aligned_buf, 512); |
| 447 | if (ret < 0) |
| 448 | return ret; |
| 449 | if (count < ret) |
| 450 | ret = count; |
| 451 | |
| 452 | sum += ret; |
| 453 | } |
| 454 | return sum; |
| 455 | } |
| 456 | } |
| 457 | return raw_pwrite_aligned(bs, offset, buf, count) + sum; |
| 458 | } |
| 459 | |
aliguori | eda578e | 2009-03-12 19:57:16 +0000 | [diff] [blame] | 460 | static int raw_write(BlockDriverState *bs, int64_t sector_num, |
| 461 | const uint8_t *buf, int nb_sectors) |
| 462 | { |
aliguori | 537a1d4 | 2009-03-13 03:12:03 +0000 | [diff] [blame] | 463 | int ret; |
| 464 | ret = raw_pwrite(bs, sector_num * 512, buf, nb_sectors * 512); |
| 465 | if (ret == (nb_sectors * 512)) |
| 466 | ret = 0; |
| 467 | return ret; |
aliguori | eda578e | 2009-03-12 19:57:16 +0000 | [diff] [blame] | 468 | } |
| 469 | |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 470 | #ifdef CONFIG_AIO |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 471 | /***********************************************************/ |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 472 | /* Unix AIO using POSIX AIO */ |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 473 | |
| 474 | typedef struct RawAIOCB { |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 475 | BlockDriverAIOCB common; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 476 | struct qemu_paiocb aiocb; |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 477 | struct RawAIOCB *next; |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 478 | int ret; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 479 | } RawAIOCB; |
| 480 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 481 | typedef struct PosixAioState |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 482 | { |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 483 | int rfd, wfd; |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 484 | RawAIOCB *first_aio; |
| 485 | } PosixAioState; |
| 486 | |
| 487 | static void posix_aio_read(void *opaque) |
| 488 | { |
| 489 | PosixAioState *s = opaque; |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 490 | RawAIOCB *acb, **pacb; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 491 | int ret; |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 492 | ssize_t len; |
aliguori | 2c41a5f | 2008-09-11 14:32:27 +0000 | [diff] [blame] | 493 | |
aliguori | e20e830 | 2008-11-13 19:23:17 +0000 | [diff] [blame] | 494 | /* read all bytes from signal pipe */ |
| 495 | for (;;) { |
| 496 | char bytes[16]; |
aliguori | 2c41a5f | 2008-09-11 14:32:27 +0000 | [diff] [blame] | 497 | |
aliguori | e20e830 | 2008-11-13 19:23:17 +0000 | [diff] [blame] | 498 | len = read(s->rfd, bytes, sizeof(bytes)); |
aliguori | 2c41a5f | 2008-09-11 14:32:27 +0000 | [diff] [blame] | 499 | if (len == -1 && errno == EINTR) |
aliguori | e20e830 | 2008-11-13 19:23:17 +0000 | [diff] [blame] | 500 | continue; /* try again */ |
| 501 | if (len == sizeof(bytes)) |
| 502 | continue; /* more to read */ |
| 503 | break; |
| 504 | } |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 505 | |
| 506 | for(;;) { |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 507 | pacb = &s->first_aio; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 508 | for(;;) { |
| 509 | acb = *pacb; |
| 510 | if (!acb) |
| 511 | goto the_end; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 512 | ret = qemu_paio_error(&acb->aiocb); |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 513 | if (ret == ECANCELED) { |
| 514 | /* remove the request */ |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 515 | *pacb = acb->next; |
| 516 | qemu_aio_release(acb); |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 517 | } else if (ret != EINPROGRESS) { |
| 518 | /* end of aio */ |
| 519 | if (ret == 0) { |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 520 | ret = qemu_paio_return(&acb->aiocb); |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 521 | if (ret == acb->aiocb.aio_nbytes) |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 522 | ret = 0; |
| 523 | else |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 524 | ret = -EINVAL; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 525 | } else { |
| 526 | ret = -ret; |
| 527 | } |
| 528 | /* remove the request */ |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 529 | *pacb = acb->next; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 530 | /* call the callback */ |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 531 | acb->common.cb(acb->common.opaque, ret); |
| 532 | qemu_aio_release(acb); |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 533 | break; |
| 534 | } else { |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 535 | pacb = &acb->next; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | } |
| 539 | the_end: ; |
| 540 | } |
| 541 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 542 | static int posix_aio_flush(void *opaque) |
| 543 | { |
| 544 | PosixAioState *s = opaque; |
| 545 | return !!s->first_aio; |
| 546 | } |
| 547 | |
| 548 | static PosixAioState *posix_aio_state; |
| 549 | |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 550 | static void aio_signal_handler(int signum) |
| 551 | { |
| 552 | if (posix_aio_state) { |
| 553 | char byte = 0; |
| 554 | |
| 555 | write(posix_aio_state->wfd, &byte, sizeof(byte)); |
| 556 | } |
| 557 | |
| 558 | qemu_service_io(); |
| 559 | } |
| 560 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 561 | static int posix_aio_init(void) |
aliguori | baf35cb | 2008-09-10 15:45:19 +0000 | [diff] [blame] | 562 | { |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 563 | struct sigaction act; |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 564 | PosixAioState *s; |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 565 | int fds[2]; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 566 | struct qemu_paioinit ai; |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 567 | |
| 568 | if (posix_aio_state) |
| 569 | return 0; |
aliguori | baf35cb | 2008-09-10 15:45:19 +0000 | [diff] [blame] | 570 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 571 | s = qemu_malloc(sizeof(PosixAioState)); |
aliguori | baf35cb | 2008-09-10 15:45:19 +0000 | [diff] [blame] | 572 | |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 573 | sigfillset(&act.sa_mask); |
| 574 | act.sa_flags = 0; /* do not restart syscalls to interrupt select() */ |
| 575 | act.sa_handler = aio_signal_handler; |
| 576 | sigaction(SIGUSR2, &act, NULL); |
| 577 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 578 | s->first_aio = NULL; |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 579 | if (pipe(fds) == -1) { |
| 580 | fprintf(stderr, "failed to create pipe\n"); |
aliguori | 2746310 | 2008-09-27 20:58:43 +0000 | [diff] [blame] | 581 | return -errno; |
| 582 | } |
aliguori | 2c41a5f | 2008-09-11 14:32:27 +0000 | [diff] [blame] | 583 | |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 584 | s->rfd = fds[0]; |
| 585 | s->wfd = fds[1]; |
aliguori | 2c41a5f | 2008-09-11 14:32:27 +0000 | [diff] [blame] | 586 | |
aliguori | e20e830 | 2008-11-13 19:23:17 +0000 | [diff] [blame] | 587 | fcntl(s->rfd, F_SETFL, O_NONBLOCK); |
aliguori | 9e472e1 | 2008-10-08 19:50:24 +0000 | [diff] [blame] | 588 | fcntl(s->wfd, F_SETFL, O_NONBLOCK); |
| 589 | |
| 590 | qemu_aio_set_fd_handler(s->rfd, posix_aio_read, NULL, posix_aio_flush, s); |
aliguori | baf35cb | 2008-09-10 15:45:19 +0000 | [diff] [blame] | 591 | |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 592 | memset(&ai, 0, sizeof(ai)); |
| 593 | ai.aio_threads = 64; |
| 594 | ai.aio_num = 64; |
| 595 | qemu_paio_init(&ai); |
aliguori | acce87f | 2008-09-26 16:12:14 +0000 | [diff] [blame] | 596 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 597 | posix_aio_state = s; |
aliguori | baf35cb | 2008-09-10 15:45:19 +0000 | [diff] [blame] | 598 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 599 | return 0; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 600 | } |
| 601 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 602 | static RawAIOCB *raw_aio_setup(BlockDriverState *bs, int64_t sector_num, |
| 603 | QEMUIOVector *qiov, int nb_sectors, |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 604 | BlockDriverCompletionFunc *cb, void *opaque) |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 605 | { |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 606 | BDRVRawState *s = bs->opaque; |
| 607 | RawAIOCB *acb; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 608 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 609 | if (fd_open(bs) < 0) |
| 610 | return NULL; |
| 611 | |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 612 | acb = qemu_aio_get(bs, cb, opaque); |
| 613 | if (!acb) |
| 614 | return NULL; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 615 | acb->aiocb.aio_fildes = s->fd; |
blueswir1 | 55f11ca | 2009-01-24 11:54:21 +0000 | [diff] [blame] | 616 | acb->aiocb.ev_signo = SIGUSR2; |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 617 | acb->aiocb.aio_iov = qiov->iov; |
| 618 | acb->aiocb.aio_niov = qiov->niov; |
| 619 | acb->aiocb.aio_nbytes = nb_sectors * 512; |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 620 | acb->aiocb.aio_offset = sector_num * 512; |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 621 | acb->aiocb.aio_flags = 0; |
| 622 | |
| 623 | /* |
| 624 | * If O_DIRECT is used the buffer needs to be aligned on a sector |
| 625 | * boundary. Tell the low level code to ensure that in case it's |
| 626 | * not done yet. |
| 627 | */ |
| 628 | if (s->aligned_buf) |
| 629 | acb->aiocb.aio_flags |= QEMU_AIO_SECTOR_ALIGNED; |
| 630 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 631 | acb->next = posix_aio_state->first_aio; |
| 632 | posix_aio_state->first_aio = acb; |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 633 | return acb; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 634 | } |
| 635 | |
aliguori | 22bf145 | 2009-01-29 17:02:08 +0000 | [diff] [blame] | 636 | static void raw_aio_remove(RawAIOCB *acb) |
| 637 | { |
| 638 | RawAIOCB **pacb; |
| 639 | |
| 640 | /* remove the callback from the queue */ |
| 641 | pacb = &posix_aio_state->first_aio; |
| 642 | for(;;) { |
| 643 | if (*pacb == NULL) { |
aliguori | 7a11b22 | 2009-02-26 16:40:19 +0000 | [diff] [blame] | 644 | fprintf(stderr, "raw_aio_remove: aio request not found!\n"); |
aliguori | 22bf145 | 2009-01-29 17:02:08 +0000 | [diff] [blame] | 645 | break; |
| 646 | } else if (*pacb == acb) { |
| 647 | *pacb = acb->next; |
| 648 | qemu_aio_release(acb); |
| 649 | break; |
| 650 | } |
aliguori | 7a11b22 | 2009-02-26 16:40:19 +0000 | [diff] [blame] | 651 | pacb = &(*pacb)->next; |
aliguori | 22bf145 | 2009-01-29 17:02:08 +0000 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 655 | static BlockDriverAIOCB *raw_aio_readv(BlockDriverState *bs, |
| 656 | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 657 | BlockDriverCompletionFunc *cb, void *opaque) |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 658 | { |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 659 | RawAIOCB *acb; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 660 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 661 | acb = raw_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque); |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 662 | if (!acb) |
| 663 | return NULL; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 664 | if (qemu_paio_read(&acb->aiocb) < 0) { |
aliguori | 22bf145 | 2009-01-29 17:02:08 +0000 | [diff] [blame] | 665 | raw_aio_remove(acb); |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 666 | return NULL; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 667 | } |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 668 | return &acb->common; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 669 | } |
| 670 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 671 | static BlockDriverAIOCB *raw_aio_writev(BlockDriverState *bs, |
| 672 | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 673 | BlockDriverCompletionFunc *cb, void *opaque) |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 674 | { |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 675 | RawAIOCB *acb; |
| 676 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 677 | acb = raw_aio_setup(bs, sector_num, qiov, nb_sectors, cb, opaque); |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 678 | if (!acb) |
| 679 | return NULL; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 680 | if (qemu_paio_write(&acb->aiocb) < 0) { |
aliguori | 22bf145 | 2009-01-29 17:02:08 +0000 | [diff] [blame] | 681 | raw_aio_remove(acb); |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 682 | return NULL; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 683 | } |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 684 | return &acb->common; |
| 685 | } |
| 686 | |
| 687 | static void raw_aio_cancel(BlockDriverAIOCB *blockacb) |
| 688 | { |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 689 | int ret; |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 690 | RawAIOCB *acb = (RawAIOCB *)blockacb; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 691 | |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 692 | ret = qemu_paio_cancel(acb->aiocb.aio_fildes, &acb->aiocb); |
| 693 | if (ret == QEMU_PAIO_NOTCANCELED) { |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 694 | /* fail safe: if the aio could not be canceled, we wait for |
| 695 | it */ |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 696 | while (qemu_paio_error(&acb->aiocb) == EINPROGRESS); |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 697 | } |
| 698 | |
aliguori | 22bf145 | 2009-01-29 17:02:08 +0000 | [diff] [blame] | 699 | raw_aio_remove(acb); |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 700 | } |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 701 | #else /* CONFIG_AIO */ |
| 702 | static int posix_aio_init(void) |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 703 | { |
blueswir1 | 674a24a | 2008-10-03 19:00:40 +0000 | [diff] [blame] | 704 | return 0; |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 705 | } |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 706 | #endif /* CONFIG_AIO */ |
| 707 | |
aliguori | 5353872 | 2008-09-26 15:59:29 +0000 | [diff] [blame] | 708 | |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 709 | static void raw_close(BlockDriverState *bs) |
| 710 | { |
| 711 | BDRVRawState *s = bs->opaque; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 712 | if (s->fd >= 0) { |
| 713 | close(s->fd); |
| 714 | s->fd = -1; |
bellard | bed5cc5 | 2008-05-28 09:51:09 +0000 | [diff] [blame] | 715 | if (s->aligned_buf != NULL) |
| 716 | qemu_free(s->aligned_buf); |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 717 | } |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | static int raw_truncate(BlockDriverState *bs, int64_t offset) |
| 721 | { |
| 722 | BDRVRawState *s = bs->opaque; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 723 | if (s->type != FTYPE_FILE) |
| 724 | return -ENOTSUP; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 725 | if (ftruncate(s->fd, offset) < 0) |
| 726 | return -errno; |
| 727 | return 0; |
| 728 | } |
| 729 | |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 730 | #ifdef __OpenBSD__ |
| 731 | static int64_t raw_getlength(BlockDriverState *bs) |
| 732 | { |
| 733 | BDRVRawState *s = bs->opaque; |
| 734 | int fd = s->fd; |
| 735 | struct stat st; |
| 736 | |
| 737 | if (fstat(fd, &st)) |
| 738 | return -1; |
| 739 | if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { |
| 740 | struct disklabel dl; |
| 741 | |
| 742 | if (ioctl(fd, DIOCGDINFO, &dl)) |
| 743 | return -1; |
| 744 | return (uint64_t)dl.d_secsize * |
| 745 | dl.d_partitions[DISKPART(st.st_rdev)].p_size; |
| 746 | } else |
| 747 | return st.st_size; |
| 748 | } |
| 749 | #else /* !__OpenBSD__ */ |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 750 | static int64_t raw_getlength(BlockDriverState *bs) |
| 751 | { |
| 752 | BDRVRawState *s = bs->opaque; |
| 753 | int fd = s->fd; |
| 754 | int64_t size; |
blueswir1 | 179a2c1 | 2009-03-08 08:23:32 +0000 | [diff] [blame] | 755 | #ifdef HOST_BSD |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 756 | struct stat sb; |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 757 | #ifdef __FreeBSD__ |
| 758 | int reopened = 0; |
| 759 | #endif |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 760 | #endif |
| 761 | #ifdef __sun__ |
| 762 | struct dk_minfo minfo; |
| 763 | int rv; |
| 764 | #endif |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 765 | int ret; |
| 766 | |
| 767 | ret = fd_open(bs); |
| 768 | if (ret < 0) |
| 769 | return ret; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 770 | |
blueswir1 | 179a2c1 | 2009-03-08 08:23:32 +0000 | [diff] [blame] | 771 | #ifdef HOST_BSD |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 772 | #ifdef __FreeBSD__ |
| 773 | again: |
| 774 | #endif |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 775 | if (!fstat(fd, &sb) && (S_IFCHR & sb.st_mode)) { |
| 776 | #ifdef DIOCGMEDIASIZE |
| 777 | if (ioctl(fd, DIOCGMEDIASIZE, (off_t *)&size)) |
blueswir1 | c5e9723 | 2009-03-07 20:06:23 +0000 | [diff] [blame] | 778 | #elif defined(DIOCGPART) |
| 779 | { |
| 780 | struct partinfo pi; |
| 781 | if (ioctl(fd, DIOCGPART, &pi) == 0) |
| 782 | size = pi.media_size; |
| 783 | else |
| 784 | size = 0; |
| 785 | } |
| 786 | if (size == 0) |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 787 | #endif |
| 788 | #ifdef CONFIG_COCOA |
| 789 | size = LONG_LONG_MAX; |
| 790 | #else |
| 791 | size = lseek(fd, 0LL, SEEK_END); |
| 792 | #endif |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 793 | #ifdef __FreeBSD__ |
| 794 | switch(s->type) { |
| 795 | case FTYPE_CD: |
| 796 | /* XXX FreeBSD acd returns UINT_MAX sectors for an empty drive */ |
| 797 | if (size == 2048LL * (unsigned)-1) |
| 798 | size = 0; |
| 799 | /* XXX no disc? maybe we need to reopen... */ |
| 800 | if (size <= 0 && !reopened && cd_open(bs) >= 0) { |
| 801 | reopened = 1; |
| 802 | goto again; |
| 803 | } |
| 804 | } |
| 805 | #endif |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 806 | } else |
| 807 | #endif |
| 808 | #ifdef __sun__ |
| 809 | /* |
| 810 | * use the DKIOCGMEDIAINFO ioctl to read the size. |
| 811 | */ |
| 812 | rv = ioctl ( fd, DKIOCGMEDIAINFO, &minfo ); |
| 813 | if ( rv != -1 ) { |
| 814 | size = minfo.dki_lbsize * minfo.dki_capacity; |
| 815 | } else /* there are reports that lseek on some devices |
| 816 | fails, but irc discussion said that contingency |
| 817 | on contingency was overkill */ |
| 818 | #endif |
| 819 | { |
| 820 | size = lseek(fd, 0, SEEK_END); |
| 821 | } |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 822 | return size; |
| 823 | } |
blueswir1 | 128ab2f | 2008-08-15 18:33:42 +0000 | [diff] [blame] | 824 | #endif |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 825 | |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 826 | static int raw_create(const char *filename, QEMUOptionParameter *options) |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 827 | { |
| 828 | int fd; |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 829 | int64_t total_size = 0; |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 830 | |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 831 | /* Read out options */ |
| 832 | while (options && options->name) { |
| 833 | if (!strcmp(options->name, BLOCK_OPT_SIZE)) { |
| 834 | total_size = options->value.n / 512; |
| 835 | } |
| 836 | options++; |
| 837 | } |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 838 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 839 | fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 840 | 0644); |
| 841 | if (fd < 0) |
| 842 | return -EIO; |
| 843 | ftruncate(fd, total_size * 512); |
| 844 | close(fd); |
| 845 | return 0; |
| 846 | } |
| 847 | |
| 848 | static void raw_flush(BlockDriverState *bs) |
| 849 | { |
| 850 | BDRVRawState *s = bs->opaque; |
| 851 | fsync(s->fd); |
| 852 | } |
| 853 | |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 854 | |
| 855 | static QEMUOptionParameter raw_create_options[] = { |
| 856 | { BLOCK_OPT_SIZE, OPT_SIZE }, |
| 857 | { NULL } |
| 858 | }; |
| 859 | |
Anthony Liguori | 5efa9d5 | 2009-05-09 17:03:42 -0500 | [diff] [blame] | 860 | static BlockDriver bdrv_raw = { |
blueswir1 | 856ae5c | 2009-04-07 17:57:09 +0000 | [diff] [blame] | 861 | .format_name = "raw", |
| 862 | .instance_size = sizeof(BDRVRawState), |
| 863 | .bdrv_probe = NULL, /* no probe for protocols */ |
| 864 | .bdrv_open = raw_open, |
| 865 | .bdrv_read = raw_read, |
| 866 | .bdrv_write = raw_write, |
| 867 | .bdrv_close = raw_close, |
| 868 | .bdrv_create = raw_create, |
| 869 | .bdrv_flush = raw_flush, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 870 | |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 871 | #ifdef CONFIG_AIO |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 872 | .bdrv_aio_readv = raw_aio_readv, |
| 873 | .bdrv_aio_writev = raw_aio_writev, |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 874 | .bdrv_aio_cancel = raw_aio_cancel, |
pbrook | ce1a14d | 2006-08-07 02:38:06 +0000 | [diff] [blame] | 875 | .aiocb_size = sizeof(RawAIOCB), |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 876 | #endif |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 877 | |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 878 | .bdrv_truncate = raw_truncate, |
| 879 | .bdrv_getlength = raw_getlength, |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 880 | |
| 881 | .create_options = raw_create_options, |
bellard | 83f6409 | 2006-08-01 16:21:11 +0000 | [diff] [blame] | 882 | }; |
| 883 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 884 | /***********************************************/ |
| 885 | /* host device */ |
| 886 | |
| 887 | #ifdef CONFIG_COCOA |
| 888 | static kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator ); |
| 889 | static kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFIndex maxPathSize ); |
| 890 | |
| 891 | kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator ) |
| 892 | { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 893 | kern_return_t kernResult; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 894 | mach_port_t masterPort; |
| 895 | CFMutableDictionaryRef classesToMatch; |
| 896 | |
| 897 | kernResult = IOMasterPort( MACH_PORT_NULL, &masterPort ); |
| 898 | if ( KERN_SUCCESS != kernResult ) { |
| 899 | printf( "IOMasterPort returned %d\n", kernResult ); |
| 900 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 901 | |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 902 | classesToMatch = IOServiceMatching( kIOCDMediaClass ); |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 903 | if ( classesToMatch == NULL ) { |
| 904 | printf( "IOServiceMatching returned a NULL dictionary.\n" ); |
| 905 | } else { |
| 906 | CFDictionarySetValue( classesToMatch, CFSTR( kIOMediaEjectableKey ), kCFBooleanTrue ); |
| 907 | } |
| 908 | kernResult = IOServiceGetMatchingServices( masterPort, classesToMatch, mediaIterator ); |
| 909 | if ( KERN_SUCCESS != kernResult ) |
| 910 | { |
| 911 | printf( "IOServiceGetMatchingServices returned %d\n", kernResult ); |
| 912 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 913 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 914 | return kernResult; |
| 915 | } |
| 916 | |
| 917 | kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFIndex maxPathSize ) |
| 918 | { |
| 919 | io_object_t nextMedia; |
| 920 | kern_return_t kernResult = KERN_FAILURE; |
| 921 | *bsdPath = '\0'; |
| 922 | nextMedia = IOIteratorNext( mediaIterator ); |
| 923 | if ( nextMedia ) |
| 924 | { |
| 925 | CFTypeRef bsdPathAsCFString; |
| 926 | bsdPathAsCFString = IORegistryEntryCreateCFProperty( nextMedia, CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, 0 ); |
| 927 | if ( bsdPathAsCFString ) { |
| 928 | size_t devPathLength; |
| 929 | strcpy( bsdPath, _PATH_DEV ); |
| 930 | strcat( bsdPath, "r" ); |
| 931 | devPathLength = strlen( bsdPath ); |
| 932 | if ( CFStringGetCString( bsdPathAsCFString, bsdPath + devPathLength, maxPathSize - devPathLength, kCFStringEncodingASCII ) ) { |
| 933 | kernResult = KERN_SUCCESS; |
| 934 | } |
| 935 | CFRelease( bsdPathAsCFString ); |
| 936 | } |
| 937 | IOObjectRelease( nextMedia ); |
| 938 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 939 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 940 | return kernResult; |
| 941 | } |
| 942 | |
| 943 | #endif |
| 944 | |
| 945 | static int hdev_open(BlockDriverState *bs, const char *filename, int flags) |
| 946 | { |
| 947 | BDRVRawState *s = bs->opaque; |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 948 | int fd, open_flags, ret; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 949 | |
aliguori | a76bab4 | 2008-09-22 19:17:18 +0000 | [diff] [blame] | 950 | posix_aio_init(); |
| 951 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 952 | #ifdef CONFIG_COCOA |
| 953 | if (strstart(filename, "/dev/cdrom", NULL)) { |
| 954 | kern_return_t kernResult; |
| 955 | io_iterator_t mediaIterator; |
| 956 | char bsdPath[ MAXPATHLEN ]; |
| 957 | int fd; |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 958 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 959 | kernResult = FindEjectableCDMedia( &mediaIterator ); |
| 960 | kernResult = GetBSDPath( mediaIterator, bsdPath, sizeof( bsdPath ) ); |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 961 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 962 | if ( bsdPath[ 0 ] != '\0' ) { |
| 963 | strcat(bsdPath,"s0"); |
| 964 | /* some CDs don't have a partition 0 */ |
| 965 | fd = open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE); |
| 966 | if (fd < 0) { |
| 967 | bsdPath[strlen(bsdPath)-1] = '1'; |
| 968 | } else { |
| 969 | close(fd); |
| 970 | } |
| 971 | filename = bsdPath; |
| 972 | } |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 973 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 974 | if ( mediaIterator ) |
| 975 | IOObjectRelease( mediaIterator ); |
| 976 | } |
| 977 | #endif |
| 978 | open_flags = O_BINARY; |
| 979 | if ((flags & BDRV_O_ACCESS) == O_RDWR) { |
| 980 | open_flags |= O_RDWR; |
| 981 | } else { |
| 982 | open_flags |= O_RDONLY; |
| 983 | bs->read_only = 1; |
| 984 | } |
aliguori | 9f7965c | 2008-10-14 14:42:54 +0000 | [diff] [blame] | 985 | /* Use O_DSYNC for write-through caching, no flags for write-back caching, |
| 986 | * and O_DIRECT for no caching. */ |
| 987 | if ((flags & BDRV_O_NOCACHE)) |
balrog | 33f0027 | 2007-12-24 14:33:24 +0000 | [diff] [blame] | 988 | open_flags |= O_DIRECT; |
aliguori | 9f7965c | 2008-10-14 14:42:54 +0000 | [diff] [blame] | 989 | else if (!(flags & BDRV_O_CACHE_WB)) |
| 990 | open_flags |= O_DSYNC; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 991 | |
| 992 | s->type = FTYPE_FILE; |
| 993 | #if defined(__linux__) |
| 994 | if (strstart(filename, "/dev/cd", NULL)) { |
| 995 | /* open will not fail even if no CD is inserted */ |
| 996 | open_flags |= O_NONBLOCK; |
| 997 | s->type = FTYPE_CD; |
| 998 | } else if (strstart(filename, "/dev/fd", NULL)) { |
| 999 | s->type = FTYPE_FD; |
blueswir1 | 6dd2db5 | 2008-05-07 15:26:22 +0000 | [diff] [blame] | 1000 | s->fd_open_flags = open_flags; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1001 | /* open will not fail even if no floppy is inserted */ |
| 1002 | open_flags |= O_NONBLOCK; |
aliguori | 8185d2c | 2009-04-05 19:10:50 +0000 | [diff] [blame] | 1003 | #ifdef CONFIG_AIO |
ths | 985a03b | 2007-12-24 16:10:43 +0000 | [diff] [blame] | 1004 | } else if (strstart(filename, "/dev/sg", NULL)) { |
| 1005 | bs->sg = 1; |
aliguori | 8185d2c | 2009-04-05 19:10:50 +0000 | [diff] [blame] | 1006 | #endif |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1007 | } |
| 1008 | #endif |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 1009 | #if defined(__FreeBSD__) |
| 1010 | if (strstart(filename, "/dev/cd", NULL) || |
| 1011 | strstart(filename, "/dev/acd", NULL)) { |
| 1012 | s->type = FTYPE_CD; |
| 1013 | s->cd_open_flags = open_flags; |
| 1014 | } |
| 1015 | #endif |
| 1016 | s->fd = -1; |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1017 | fd = open(filename, open_flags, 0644); |
| 1018 | if (fd < 0) { |
| 1019 | ret = -errno; |
| 1020 | if (ret == -EROFS) |
| 1021 | ret = -EACCES; |
| 1022 | return ret; |
| 1023 | } |
| 1024 | s->fd = fd; |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 1025 | #if defined(__FreeBSD__) |
| 1026 | /* make sure the door isnt locked at this time */ |
| 1027 | if (s->type == FTYPE_CD) |
| 1028 | ioctl (s->fd, CDIOCALLOW); |
| 1029 | #endif |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1030 | #if defined(__linux__) |
| 1031 | /* close fd so that we can reopen it as needed */ |
| 1032 | if (s->type == FTYPE_FD) { |
| 1033 | close(s->fd); |
| 1034 | s->fd = -1; |
| 1035 | s->fd_media_changed = 1; |
| 1036 | } |
| 1037 | #endif |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
aliguori | 03ff3ca | 2008-09-15 15:51:35 +0000 | [diff] [blame] | 1041 | #if defined(__linux__) |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1042 | /* Note: we do not have a reliable method to detect if the floppy is |
| 1043 | present. The current method is to try to open the floppy at every |
| 1044 | I/O and to keep it opened during a few hundreds of ms. */ |
| 1045 | static int fd_open(BlockDriverState *bs) |
| 1046 | { |
| 1047 | BDRVRawState *s = bs->opaque; |
| 1048 | int last_media_present; |
| 1049 | |
| 1050 | if (s->type != FTYPE_FD) |
| 1051 | return 0; |
| 1052 | last_media_present = (s->fd >= 0); |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1053 | if (s->fd >= 0 && |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1054 | (qemu_get_clock(rt_clock) - s->fd_open_time) >= FD_OPEN_TIMEOUT) { |
| 1055 | close(s->fd); |
| 1056 | s->fd = -1; |
| 1057 | #ifdef DEBUG_FLOPPY |
| 1058 | printf("Floppy closed\n"); |
| 1059 | #endif |
| 1060 | } |
| 1061 | if (s->fd < 0) { |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 1062 | if (s->fd_got_error && |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1063 | (qemu_get_clock(rt_clock) - s->fd_error_time) < FD_OPEN_TIMEOUT) { |
| 1064 | #ifdef DEBUG_FLOPPY |
| 1065 | printf("No floppy (open delayed)\n"); |
| 1066 | #endif |
| 1067 | return -EIO; |
| 1068 | } |
blueswir1 | 6dd2db5 | 2008-05-07 15:26:22 +0000 | [diff] [blame] | 1069 | s->fd = open(bs->filename, s->fd_open_flags); |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1070 | if (s->fd < 0) { |
| 1071 | s->fd_error_time = qemu_get_clock(rt_clock); |
| 1072 | s->fd_got_error = 1; |
| 1073 | if (last_media_present) |
| 1074 | s->fd_media_changed = 1; |
| 1075 | #ifdef DEBUG_FLOPPY |
| 1076 | printf("No floppy\n"); |
| 1077 | #endif |
| 1078 | return -EIO; |
| 1079 | } |
| 1080 | #ifdef DEBUG_FLOPPY |
| 1081 | printf("Floppy opened\n"); |
| 1082 | #endif |
| 1083 | } |
| 1084 | if (!last_media_present) |
| 1085 | s->fd_media_changed = 1; |
| 1086 | s->fd_open_time = qemu_get_clock(rt_clock); |
| 1087 | s->fd_got_error = 0; |
| 1088 | return 0; |
| 1089 | } |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1090 | |
| 1091 | static int raw_is_inserted(BlockDriverState *bs) |
| 1092 | { |
| 1093 | BDRVRawState *s = bs->opaque; |
| 1094 | int ret; |
| 1095 | |
| 1096 | switch(s->type) { |
| 1097 | case FTYPE_CD: |
| 1098 | ret = ioctl(s->fd, CDROM_DRIVE_STATUS, CDSL_CURRENT); |
| 1099 | if (ret == CDS_DISC_OK) |
| 1100 | return 1; |
| 1101 | else |
| 1102 | return 0; |
| 1103 | break; |
| 1104 | case FTYPE_FD: |
| 1105 | ret = fd_open(bs); |
| 1106 | return (ret >= 0); |
| 1107 | default: |
| 1108 | return 1; |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | /* currently only used by fdc.c, but a CD version would be good too */ |
| 1113 | static int raw_media_changed(BlockDriverState *bs) |
| 1114 | { |
| 1115 | BDRVRawState *s = bs->opaque; |
| 1116 | |
| 1117 | switch(s->type) { |
| 1118 | case FTYPE_FD: |
| 1119 | { |
| 1120 | int ret; |
| 1121 | /* XXX: we do not have a true media changed indication. It |
| 1122 | does not work if the floppy is changed without trying |
| 1123 | to read it */ |
| 1124 | fd_open(bs); |
| 1125 | ret = s->fd_media_changed; |
| 1126 | s->fd_media_changed = 0; |
| 1127 | #ifdef DEBUG_FLOPPY |
| 1128 | printf("Floppy changed=%d\n", ret); |
| 1129 | #endif |
| 1130 | return ret; |
| 1131 | } |
| 1132 | default: |
| 1133 | return -ENOTSUP; |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | static int raw_eject(BlockDriverState *bs, int eject_flag) |
| 1138 | { |
| 1139 | BDRVRawState *s = bs->opaque; |
| 1140 | |
| 1141 | switch(s->type) { |
| 1142 | case FTYPE_CD: |
| 1143 | if (eject_flag) { |
| 1144 | if (ioctl (s->fd, CDROMEJECT, NULL) < 0) |
| 1145 | perror("CDROMEJECT"); |
| 1146 | } else { |
| 1147 | if (ioctl (s->fd, CDROMCLOSETRAY, NULL) < 0) |
| 1148 | perror("CDROMEJECT"); |
| 1149 | } |
| 1150 | break; |
| 1151 | case FTYPE_FD: |
| 1152 | { |
| 1153 | int fd; |
| 1154 | if (s->fd >= 0) { |
| 1155 | close(s->fd); |
| 1156 | s->fd = -1; |
| 1157 | } |
blueswir1 | 6dd2db5 | 2008-05-07 15:26:22 +0000 | [diff] [blame] | 1158 | fd = open(bs->filename, s->fd_open_flags | O_NONBLOCK); |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1159 | if (fd >= 0) { |
| 1160 | if (ioctl(fd, FDEJECT, 0) < 0) |
| 1161 | perror("FDEJECT"); |
| 1162 | close(fd); |
| 1163 | } |
| 1164 | } |
| 1165 | break; |
| 1166 | default: |
| 1167 | return -ENOTSUP; |
| 1168 | } |
| 1169 | return 0; |
| 1170 | } |
| 1171 | |
| 1172 | static int raw_set_locked(BlockDriverState *bs, int locked) |
| 1173 | { |
| 1174 | BDRVRawState *s = bs->opaque; |
| 1175 | |
| 1176 | switch(s->type) { |
| 1177 | case FTYPE_CD: |
| 1178 | if (ioctl (s->fd, CDROM_LOCKDOOR, locked) < 0) { |
| 1179 | /* Note: an error can happen if the distribution automatically |
| 1180 | mounts the CD-ROM */ |
| 1181 | // perror("CDROM_LOCKDOOR"); |
| 1182 | } |
| 1183 | break; |
| 1184 | default: |
| 1185 | return -ENOTSUP; |
| 1186 | } |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
ths | 985a03b | 2007-12-24 16:10:43 +0000 | [diff] [blame] | 1190 | static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) |
| 1191 | { |
| 1192 | BDRVRawState *s = bs->opaque; |
| 1193 | |
| 1194 | return ioctl(s->fd, req, buf); |
| 1195 | } |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1196 | |
aliguori | 8185d2c | 2009-04-05 19:10:50 +0000 | [diff] [blame] | 1197 | #ifdef CONFIG_AIO |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1198 | static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs, |
| 1199 | unsigned long int req, void *buf, |
| 1200 | BlockDriverCompletionFunc *cb, void *opaque) |
| 1201 | { |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 1202 | BDRVRawState *s = bs->opaque; |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1203 | RawAIOCB *acb; |
| 1204 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 1205 | if (fd_open(bs) < 0) |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1206 | return NULL; |
| 1207 | |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 1208 | acb = qemu_aio_get(bs, cb, opaque); |
| 1209 | if (!acb) |
| 1210 | return NULL; |
| 1211 | acb->aiocb.aio_fildes = s->fd; |
| 1212 | acb->aiocb.ev_signo = SIGUSR2; |
| 1213 | acb->aiocb.aio_offset = 0; |
| 1214 | acb->aiocb.aio_flags = 0; |
| 1215 | |
| 1216 | acb->next = posix_aio_state->first_aio; |
| 1217 | posix_aio_state->first_aio = acb; |
| 1218 | |
| 1219 | acb->aiocb.aio_ioctl_buf = buf; |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1220 | acb->aiocb.aio_ioctl_cmd = req; |
| 1221 | if (qemu_paio_ioctl(&acb->aiocb) < 0) { |
| 1222 | raw_aio_remove(acb); |
| 1223 | return NULL; |
| 1224 | } |
| 1225 | |
| 1226 | return &acb->common; |
| 1227 | } |
aliguori | 8185d2c | 2009-04-05 19:10:50 +0000 | [diff] [blame] | 1228 | #endif |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1229 | |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 1230 | #elif defined(__FreeBSD__) |
| 1231 | |
| 1232 | static int fd_open(BlockDriverState *bs) |
| 1233 | { |
| 1234 | BDRVRawState *s = bs->opaque; |
| 1235 | |
| 1236 | /* this is just to ensure s->fd is sane (its called by io ops) */ |
| 1237 | if (s->fd >= 0) |
| 1238 | return 0; |
| 1239 | return -EIO; |
| 1240 | } |
| 1241 | |
| 1242 | static int cd_open(BlockDriverState *bs) |
| 1243 | { |
| 1244 | #if defined(__FreeBSD__) |
| 1245 | BDRVRawState *s = bs->opaque; |
| 1246 | int fd; |
| 1247 | |
| 1248 | switch(s->type) { |
| 1249 | case FTYPE_CD: |
| 1250 | /* XXX force reread of possibly changed/newly loaded disc, |
| 1251 | * FreeBSD seems to not notice sometimes... */ |
| 1252 | if (s->fd >= 0) |
| 1253 | close (s->fd); |
| 1254 | fd = open(bs->filename, s->cd_open_flags, 0644); |
| 1255 | if (fd < 0) { |
| 1256 | s->fd = -1; |
| 1257 | return -EIO; |
| 1258 | } |
| 1259 | s->fd = fd; |
| 1260 | /* make sure the door isnt locked at this time */ |
| 1261 | ioctl (s->fd, CDIOCALLOW); |
| 1262 | } |
| 1263 | #endif |
| 1264 | return 0; |
| 1265 | } |
| 1266 | |
| 1267 | static int raw_is_inserted(BlockDriverState *bs) |
| 1268 | { |
| 1269 | BDRVRawState *s = bs->opaque; |
| 1270 | |
| 1271 | switch(s->type) { |
| 1272 | case FTYPE_CD: |
| 1273 | return (raw_getlength(bs) > 0); |
| 1274 | case FTYPE_FD: |
| 1275 | /* XXX handle this */ |
| 1276 | /* FALLTHRU */ |
| 1277 | default: |
| 1278 | return 1; |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | static int raw_media_changed(BlockDriverState *bs) |
| 1283 | { |
| 1284 | return -ENOTSUP; |
| 1285 | } |
| 1286 | |
| 1287 | static int raw_eject(BlockDriverState *bs, int eject_flag) |
| 1288 | { |
| 1289 | BDRVRawState *s = bs->opaque; |
| 1290 | |
| 1291 | switch(s->type) { |
| 1292 | case FTYPE_CD: |
| 1293 | if (s->fd < 0) |
| 1294 | return -ENOTSUP; |
| 1295 | (void) ioctl (s->fd, CDIOCALLOW); |
| 1296 | if (eject_flag) { |
| 1297 | if (ioctl (s->fd, CDIOCEJECT) < 0) |
| 1298 | perror("CDIOCEJECT"); |
| 1299 | } else { |
| 1300 | if (ioctl (s->fd, CDIOCCLOSE) < 0) |
| 1301 | perror("CDIOCCLOSE"); |
| 1302 | } |
| 1303 | if (cd_open(bs) < 0) |
| 1304 | return -ENOTSUP; |
| 1305 | break; |
| 1306 | case FTYPE_FD: |
| 1307 | /* XXX handle this */ |
| 1308 | /* FALLTHRU */ |
| 1309 | default: |
| 1310 | return -ENOTSUP; |
| 1311 | } |
| 1312 | return 0; |
| 1313 | } |
| 1314 | |
| 1315 | static int raw_set_locked(BlockDriverState *bs, int locked) |
| 1316 | { |
| 1317 | BDRVRawState *s = bs->opaque; |
| 1318 | |
| 1319 | switch(s->type) { |
| 1320 | case FTYPE_CD: |
| 1321 | if (s->fd < 0) |
| 1322 | return -ENOTSUP; |
| 1323 | if (ioctl (s->fd, (locked ? CDIOCPREVENT : CDIOCALLOW)) < 0) { |
| 1324 | /* Note: an error can happen if the distribution automatically |
| 1325 | mounts the CD-ROM */ |
| 1326 | // perror("CDROM_LOCKDOOR"); |
| 1327 | } |
| 1328 | break; |
| 1329 | default: |
| 1330 | return -ENOTSUP; |
| 1331 | } |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
| 1335 | static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) |
| 1336 | { |
| 1337 | return -ENOTSUP; |
| 1338 | } |
| 1339 | #else /* !linux && !FreeBSD */ |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1340 | |
aliguori | 08af02e | 2008-09-15 16:48:11 +0000 | [diff] [blame] | 1341 | static int fd_open(BlockDriverState *bs) |
| 1342 | { |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1346 | static int raw_is_inserted(BlockDriverState *bs) |
| 1347 | { |
| 1348 | return 1; |
| 1349 | } |
| 1350 | |
| 1351 | static int raw_media_changed(BlockDriverState *bs) |
| 1352 | { |
| 1353 | return -ENOTSUP; |
| 1354 | } |
| 1355 | |
| 1356 | static int raw_eject(BlockDriverState *bs, int eject_flag) |
| 1357 | { |
| 1358 | return -ENOTSUP; |
| 1359 | } |
| 1360 | |
| 1361 | static int raw_set_locked(BlockDriverState *bs, int locked) |
| 1362 | { |
| 1363 | return -ENOTSUP; |
| 1364 | } |
| 1365 | |
ths | 985a03b | 2007-12-24 16:10:43 +0000 | [diff] [blame] | 1366 | static int raw_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) |
| 1367 | { |
| 1368 | return -ENOTSUP; |
| 1369 | } |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1370 | |
| 1371 | static BlockDriverAIOCB *raw_aio_ioctl(BlockDriverState *bs, |
| 1372 | unsigned long int req, void *buf, |
| 1373 | BlockDriverCompletionFunc *cb, void *opaque) |
| 1374 | { |
blueswir1 | bbeea53 | 2009-03-30 17:51:29 +0000 | [diff] [blame] | 1375 | return NULL; |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1376 | } |
blueswir1 | 9f23011 | 2009-03-28 08:37:13 +0000 | [diff] [blame] | 1377 | #endif /* !linux && !FreeBSD */ |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1378 | |
aliguori | 93c65b4 | 2009-04-05 17:40:43 +0000 | [diff] [blame] | 1379 | #if defined(__linux__) || defined(__FreeBSD__) |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 1380 | static int hdev_create(const char *filename, QEMUOptionParameter *options) |
aliguori | 93c65b4 | 2009-04-05 17:40:43 +0000 | [diff] [blame] | 1381 | { |
| 1382 | int fd; |
| 1383 | int ret = 0; |
| 1384 | struct stat stat_buf; |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 1385 | int64_t total_size = 0; |
aliguori | 93c65b4 | 2009-04-05 17:40:43 +0000 | [diff] [blame] | 1386 | |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 1387 | /* Read out options */ |
| 1388 | while (options && options->name) { |
| 1389 | if (!strcmp(options->name, "size")) { |
| 1390 | total_size = options->value.n / 512; |
| 1391 | } |
| 1392 | options++; |
| 1393 | } |
aliguori | 93c65b4 | 2009-04-05 17:40:43 +0000 | [diff] [blame] | 1394 | |
| 1395 | fd = open(filename, O_WRONLY | O_BINARY); |
| 1396 | if (fd < 0) |
| 1397 | return -EIO; |
| 1398 | |
| 1399 | if (fstat(fd, &stat_buf) < 0) |
| 1400 | ret = -EIO; |
| 1401 | else if (!S_ISBLK(stat_buf.st_mode)) |
| 1402 | ret = -EIO; |
| 1403 | else if (lseek(fd, 0, SEEK_END) < total_size * 512) |
| 1404 | ret = -ENOSPC; |
| 1405 | |
| 1406 | close(fd); |
| 1407 | return ret; |
| 1408 | } |
| 1409 | |
| 1410 | #else /* !(linux || freebsd) */ |
| 1411 | |
Kevin Wolf | 0e7e198 | 2009-05-18 16:42:10 +0200 | [diff] [blame] | 1412 | static int hdev_create(const char *filename, QEMUOptionParameter *options) |
aliguori | 93c65b4 | 2009-04-05 17:40:43 +0000 | [diff] [blame] | 1413 | { |
| 1414 | return -ENOTSUP; |
| 1415 | } |
| 1416 | #endif |
| 1417 | |
Anthony Liguori | 5efa9d5 | 2009-05-09 17:03:42 -0500 | [diff] [blame] | 1418 | static BlockDriver bdrv_host_device = { |
aurel32 | e60f469 | 2009-03-07 22:00:29 +0000 | [diff] [blame] | 1419 | .format_name = "host_device", |
| 1420 | .instance_size = sizeof(BDRVRawState), |
| 1421 | .bdrv_open = hdev_open, |
| 1422 | .bdrv_close = raw_close, |
aliguori | 93c65b4 | 2009-04-05 17:40:43 +0000 | [diff] [blame] | 1423 | .bdrv_create = hdev_create, |
aurel32 | e60f469 | 2009-03-07 22:00:29 +0000 | [diff] [blame] | 1424 | .bdrv_flush = raw_flush, |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 1425 | |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 1426 | #ifdef CONFIG_AIO |
aliguori | f141eaf | 2009-04-07 18:43:24 +0000 | [diff] [blame] | 1427 | .bdrv_aio_readv = raw_aio_readv, |
| 1428 | .bdrv_aio_writev = raw_aio_writev, |
aurel32 | e60f469 | 2009-03-07 22:00:29 +0000 | [diff] [blame] | 1429 | .bdrv_aio_cancel = raw_aio_cancel, |
| 1430 | .aiocb_size = sizeof(RawAIOCB), |
blueswir1 | 414f0da | 2008-08-15 18:20:52 +0000 | [diff] [blame] | 1431 | #endif |
aliguori | 3c529d9 | 2008-12-12 16:41:40 +0000 | [diff] [blame] | 1432 | |
aliguori | eda578e | 2009-03-12 19:57:16 +0000 | [diff] [blame] | 1433 | .bdrv_read = raw_read, |
| 1434 | .bdrv_write = raw_write, |
aurel32 | e60f469 | 2009-03-07 22:00:29 +0000 | [diff] [blame] | 1435 | .bdrv_getlength = raw_getlength, |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1436 | |
| 1437 | /* removable device support */ |
aurel32 | e60f469 | 2009-03-07 22:00:29 +0000 | [diff] [blame] | 1438 | .bdrv_is_inserted = raw_is_inserted, |
| 1439 | .bdrv_media_changed = raw_media_changed, |
| 1440 | .bdrv_eject = raw_eject, |
| 1441 | .bdrv_set_locked = raw_set_locked, |
ths | 985a03b | 2007-12-24 16:10:43 +0000 | [diff] [blame] | 1442 | /* generic scsi device */ |
aurel32 | e60f469 | 2009-03-07 22:00:29 +0000 | [diff] [blame] | 1443 | .bdrv_ioctl = raw_ioctl, |
aliguori | 8185d2c | 2009-04-05 19:10:50 +0000 | [diff] [blame] | 1444 | #ifdef CONFIG_AIO |
aliguori | 221f715 | 2009-03-28 17:28:41 +0000 | [diff] [blame] | 1445 | .bdrv_aio_ioctl = raw_aio_ioctl, |
aliguori | 8185d2c | 2009-04-05 19:10:50 +0000 | [diff] [blame] | 1446 | #endif |
bellard | 19cb373 | 2006-08-19 11:45:59 +0000 | [diff] [blame] | 1447 | }; |
Anthony Liguori | 5efa9d5 | 2009-05-09 17:03:42 -0500 | [diff] [blame] | 1448 | |
| 1449 | static void bdrv_raw_init(void) |
| 1450 | { |
| 1451 | bdrv_register(&bdrv_raw); |
| 1452 | bdrv_register(&bdrv_host_device); |
| 1453 | } |
| 1454 | |
| 1455 | block_init(bdrv_raw_init); |