2 * Block driver for RAW files (posix)
4 * Copyright (c) 2006 Fabrice Bellard
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
24 #include "qemu-common.h"
25 #include "qemu/timer.h"
27 #include "block/block_int.h"
28 #include "qemu/module.h"
30 #include "block/thread-pool.h"
34 #if defined(__APPLE__) && (__MACH__)
36 #include <sys/param.h>
37 #include <IOKit/IOKitLib.h>
38 #include <IOKit/IOBSD.h>
39 #include <IOKit/storage/IOMediaBSDClient.h>
40 #include <IOKit/storage/IOMedia.h>
41 #include <IOKit/storage/IOCDMedia.h>
42 //#include <IOKit/storage/IOCDTypes.h>
43 #include <CoreFoundation/CoreFoundation.h>
47 #define _POSIX_PTHREAD_SEMANTICS 1
51 #include <sys/types.h>
53 #include <sys/ioctl.h>
54 #include <sys/param.h>
55 #include <linux/cdrom.h>
60 #include <linux/fiemap.h>
62 #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
68 #include <sys/ioctl.h>
69 #include <sys/disklabel.h>
74 #include <sys/ioctl.h>
75 #include <sys/disklabel.h>
81 #include <sys/ioctl.h>
82 #include <sys/diskslice.h>
89 //#define DEBUG_FLOPPY
92 #if defined(DEBUG_BLOCK)
93 #define DEBUG_BLOCK_PRINT(formatCstr, ...) do { if (qemu_log_enabled()) \
94 { qemu_log(formatCstr, ## __VA_ARGS__); qemu_log_flush(); } } while (0)
96 #define DEBUG_BLOCK_PRINT(formatCstr, ...)
99 /* OS X does not have O_DSYNC */
102 #define O_DSYNC O_SYNC
103 #elif defined(O_FSYNC)
104 #define O_DSYNC O_FSYNC
108 /* Approximate O_DIRECT with O_DSYNC if O_DIRECT isn't available */
110 #define O_DIRECT O_DSYNC
117 /* if the FD is not accessed during that time (in ns), we try to
118 reopen it to see if the disk has been changed */
119 #define FD_OPEN_TIMEOUT (1000000000)
121 #define MAX_BLOCKSIZE 4096
123 typedef struct BDRVRawState
{
127 #if defined(__linux__)
128 /* linux floppy specific */
129 int64_t fd_open_time
;
130 int64_t fd_error_time
;
132 int fd_media_changed
;
134 #ifdef CONFIG_LINUX_AIO
143 typedef struct BDRVRawReopenState
{
146 #ifdef CONFIG_LINUX_AIO
149 } BDRVRawReopenState
;
151 static int fd_open(BlockDriverState
*bs
);
152 static int64_t raw_getlength(BlockDriverState
*bs
);
154 typedef struct RawPosixAIOData
{
155 BlockDriverState
*bs
;
158 struct iovec
*aio_iov
;
163 #define aio_ioctl_cmd aio_nbytes /* for QEMU_AIO_IOCTL */
168 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
169 static int cdrom_reopen(BlockDriverState
*bs
);
172 #if defined(__NetBSD__)
173 static int raw_normalize_devicepath(const char **filename
)
175 static char namebuf
[PATH_MAX
];
176 const char *dp
, *fname
;
180 dp
= strrchr(fname
, '/');
181 if (lstat(fname
, &sb
) < 0) {
182 fprintf(stderr
, "%s: stat failed: %s\n",
183 fname
, strerror(errno
));
187 if (!S_ISBLK(sb
.st_mode
)) {
192 snprintf(namebuf
, PATH_MAX
, "r%s", fname
);
194 snprintf(namebuf
, PATH_MAX
, "%.*s/r%s",
195 (int)(dp
- fname
), fname
, dp
+ 1);
197 fprintf(stderr
, "%s is a block device", fname
);
199 fprintf(stderr
, ", using %s\n", *filename
);
204 static int raw_normalize_devicepath(const char **filename
)
210 static void raw_parse_flags(int bdrv_flags
, int *open_flags
)
212 assert(open_flags
!= NULL
);
214 *open_flags
|= O_BINARY
;
215 *open_flags
&= ~O_ACCMODE
;
216 if (bdrv_flags
& BDRV_O_RDWR
) {
217 *open_flags
|= O_RDWR
;
219 *open_flags
|= O_RDONLY
;
222 /* Use O_DSYNC for write-through caching, no flags for write-back caching,
223 * and O_DIRECT for no caching. */
224 if ((bdrv_flags
& BDRV_O_NOCACHE
)) {
225 *open_flags
|= O_DIRECT
;
229 #ifdef CONFIG_LINUX_AIO
230 static int raw_set_aio(void **aio_ctx
, int *use_aio
, int bdrv_flags
)
233 assert(aio_ctx
!= NULL
);
234 assert(use_aio
!= NULL
);
236 * Currently Linux do AIO only for files opened with O_DIRECT
237 * specified so check NOCACHE flag too
239 if ((bdrv_flags
& (BDRV_O_NOCACHE
|BDRV_O_NATIVE_AIO
)) ==
240 (BDRV_O_NOCACHE
|BDRV_O_NATIVE_AIO
)) {
242 /* if non-NULL, laio_init() has already been run */
243 if (*aio_ctx
== NULL
) {
244 *aio_ctx
= laio_init();
261 static int raw_open_common(BlockDriverState
*bs
, const char *filename
,
262 int bdrv_flags
, int open_flags
)
264 BDRVRawState
*s
= bs
->opaque
;
267 ret
= raw_normalize_devicepath(&filename
);
272 s
->open_flags
= open_flags
;
273 raw_parse_flags(bdrv_flags
, &s
->open_flags
);
276 fd
= qemu_open(filename
, s
->open_flags
, 0644);
285 #ifdef CONFIG_LINUX_AIO
286 if (raw_set_aio(&s
->aio_ctx
, &s
->use_aio
, bdrv_flags
)) {
293 if (platform_test_xfs_fd(s
->fd
)) {
301 static int raw_open(BlockDriverState
*bs
, const char *filename
, int flags
)
303 BDRVRawState
*s
= bs
->opaque
;
305 s
->type
= FTYPE_FILE
;
306 return raw_open_common(bs
, filename
, flags
, 0);
309 static int raw_reopen_prepare(BDRVReopenState
*state
,
310 BlockReopenQueue
*queue
, Error
**errp
)
313 BDRVRawReopenState
*raw_s
;
316 assert(state
!= NULL
);
317 assert(state
->bs
!= NULL
);
319 s
= state
->bs
->opaque
;
321 state
->opaque
= g_malloc0(sizeof(BDRVRawReopenState
));
322 raw_s
= state
->opaque
;
324 #ifdef CONFIG_LINUX_AIO
325 raw_s
->use_aio
= s
->use_aio
;
327 /* we can use s->aio_ctx instead of a copy, because the use_aio flag is
328 * valid in the 'false' condition even if aio_ctx is set, and raw_set_aio()
329 * won't override aio_ctx if aio_ctx is non-NULL */
330 if (raw_set_aio(&s
->aio_ctx
, &raw_s
->use_aio
, state
->flags
)) {
335 if (s
->type
== FTYPE_FD
|| s
->type
== FTYPE_CD
) {
336 raw_s
->open_flags
|= O_NONBLOCK
;
339 raw_parse_flags(state
->flags
, &raw_s
->open_flags
);
343 int fcntl_flags
= O_APPEND
| O_ASYNC
| O_NONBLOCK
;
345 fcntl_flags
|= O_NOATIME
;
348 if ((raw_s
->open_flags
& ~fcntl_flags
) == (s
->open_flags
& ~fcntl_flags
)) {
349 /* dup the original fd */
350 /* TODO: use qemu fcntl wrapper */
351 #ifdef F_DUPFD_CLOEXEC
352 raw_s
->fd
= fcntl(s
->fd
, F_DUPFD_CLOEXEC
, 0);
354 raw_s
->fd
= dup(s
->fd
);
355 if (raw_s
->fd
!= -1) {
356 qemu_set_cloexec(raw_s
->fd
);
359 if (raw_s
->fd
>= 0) {
360 ret
= fcntl_setfl(raw_s
->fd
, raw_s
->open_flags
);
362 qemu_close(raw_s
->fd
);
368 /* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */
369 if (raw_s
->fd
== -1) {
370 assert(!(raw_s
->open_flags
& O_CREAT
));
371 raw_s
->fd
= qemu_open(state
->bs
->filename
, raw_s
->open_flags
);
372 if (raw_s
->fd
== -1) {
380 static void raw_reopen_commit(BDRVReopenState
*state
)
382 BDRVRawReopenState
*raw_s
= state
->opaque
;
383 BDRVRawState
*s
= state
->bs
->opaque
;
385 s
->open_flags
= raw_s
->open_flags
;
389 #ifdef CONFIG_LINUX_AIO
390 s
->use_aio
= raw_s
->use_aio
;
393 g_free(state
->opaque
);
394 state
->opaque
= NULL
;
398 static void raw_reopen_abort(BDRVReopenState
*state
)
400 BDRVRawReopenState
*raw_s
= state
->opaque
;
402 /* nothing to do if NULL, we didn't get far enough */
407 if (raw_s
->fd
>= 0) {
408 qemu_close(raw_s
->fd
);
411 g_free(state
->opaque
);
412 state
->opaque
= NULL
;
416 /* XXX: use host sector size if necessary with:
417 #ifdef DIOCGSECTORSIZE
419 unsigned int sectorsize = 512;
420 if (!ioctl(fd, DIOCGSECTORSIZE, §orsize) &&
421 sectorsize > bufsize)
422 bufsize = sectorsize;
426 uint32_t blockSize = 512;
427 if ( !ioctl( fd, DKIOCGETBLOCKSIZE, &blockSize ) && blockSize > bufsize) {
433 static ssize_t
handle_aiocb_ioctl(RawPosixAIOData
*aiocb
)
437 ret
= ioctl(aiocb
->aio_fildes
, aiocb
->aio_ioctl_cmd
, aiocb
->aio_ioctl_buf
);
445 static ssize_t
handle_aiocb_flush(RawPosixAIOData
*aiocb
)
449 ret
= qemu_fdatasync(aiocb
->aio_fildes
);
458 static bool preadv_present
= true;
461 qemu_preadv(int fd
, const struct iovec
*iov
, int nr_iov
, off_t offset
)
463 return preadv(fd
, iov
, nr_iov
, offset
);
467 qemu_pwritev(int fd
, const struct iovec
*iov
, int nr_iov
, off_t offset
)
469 return pwritev(fd
, iov
, nr_iov
, offset
);
474 static bool preadv_present
= false;
477 qemu_preadv(int fd
, const struct iovec
*iov
, int nr_iov
, off_t offset
)
483 qemu_pwritev(int fd
, const struct iovec
*iov
, int nr_iov
, off_t offset
)
490 static ssize_t
handle_aiocb_rw_vector(RawPosixAIOData
*aiocb
)
495 if (aiocb
->aio_type
& QEMU_AIO_WRITE
)
496 len
= qemu_pwritev(aiocb
->aio_fildes
,
501 len
= qemu_preadv(aiocb
->aio_fildes
,
505 } while (len
== -1 && errno
== EINTR
);
514 * Read/writes the data to/from a given linear buffer.
516 * Returns the number of bytes handles or -errno in case of an error. Short
517 * reads are only returned if the end of the file is reached.
519 static ssize_t
handle_aiocb_rw_linear(RawPosixAIOData
*aiocb
, char *buf
)
524 while (offset
< aiocb
->aio_nbytes
) {
525 if (aiocb
->aio_type
& QEMU_AIO_WRITE
) {
526 len
= pwrite(aiocb
->aio_fildes
,
527 (const char *)buf
+ offset
,
528 aiocb
->aio_nbytes
- offset
,
529 aiocb
->aio_offset
+ offset
);
531 len
= pread(aiocb
->aio_fildes
,
533 aiocb
->aio_nbytes
- offset
,
534 aiocb
->aio_offset
+ offset
);
536 if (len
== -1 && errno
== EINTR
) {
538 } else if (len
== -1) {
541 } else if (len
== 0) {
550 static ssize_t
handle_aiocb_rw(RawPosixAIOData
*aiocb
)
555 if (!(aiocb
->aio_type
& QEMU_AIO_MISALIGNED
)) {
557 * If there is just a single buffer, and it is properly aligned
558 * we can just use plain pread/pwrite without any problems.
560 if (aiocb
->aio_niov
== 1) {
561 return handle_aiocb_rw_linear(aiocb
, aiocb
->aio_iov
->iov_base
);
564 * We have more than one iovec, and all are properly aligned.
566 * Try preadv/pwritev first and fall back to linearizing the
567 * buffer if it's not supported.
569 if (preadv_present
) {
570 nbytes
= handle_aiocb_rw_vector(aiocb
);
571 if (nbytes
== aiocb
->aio_nbytes
||
572 (nbytes
< 0 && nbytes
!= -ENOSYS
)) {
575 preadv_present
= false;
579 * XXX(hch): short read/write. no easy way to handle the reminder
580 * using these interfaces. For now retry using plain
586 * Ok, we have to do it the hard way, copy all segments into
587 * a single aligned buffer.
589 buf
= qemu_blockalign(aiocb
->bs
, aiocb
->aio_nbytes
);
590 if (aiocb
->aio_type
& QEMU_AIO_WRITE
) {
594 for (i
= 0; i
< aiocb
->aio_niov
; ++i
) {
595 memcpy(p
, aiocb
->aio_iov
[i
].iov_base
, aiocb
->aio_iov
[i
].iov_len
);
596 p
+= aiocb
->aio_iov
[i
].iov_len
;
600 nbytes
= handle_aiocb_rw_linear(aiocb
, buf
);
601 if (!(aiocb
->aio_type
& QEMU_AIO_WRITE
)) {
603 size_t count
= aiocb
->aio_nbytes
, copy
;
606 for (i
= 0; i
< aiocb
->aio_niov
&& count
; ++i
) {
608 if (copy
> aiocb
->aio_iov
[i
].iov_len
) {
609 copy
= aiocb
->aio_iov
[i
].iov_len
;
611 memcpy(aiocb
->aio_iov
[i
].iov_base
, p
, copy
);
621 static int aio_worker(void *arg
)
623 RawPosixAIOData
*aiocb
= arg
;
626 switch (aiocb
->aio_type
& QEMU_AIO_TYPE_MASK
) {
628 ret
= handle_aiocb_rw(aiocb
);
629 if (ret
>= 0 && ret
< aiocb
->aio_nbytes
&& aiocb
->bs
->growable
) {
630 iov_memset(aiocb
->aio_iov
, aiocb
->aio_niov
, ret
,
631 0, aiocb
->aio_nbytes
- ret
);
633 ret
= aiocb
->aio_nbytes
;
635 if (ret
== aiocb
->aio_nbytes
) {
637 } else if (ret
>= 0 && ret
< aiocb
->aio_nbytes
) {
642 ret
= handle_aiocb_rw(aiocb
);
643 if (ret
== aiocb
->aio_nbytes
) {
645 } else if (ret
>= 0 && ret
< aiocb
->aio_nbytes
) {
650 ret
= handle_aiocb_flush(aiocb
);
653 ret
= handle_aiocb_ioctl(aiocb
);
656 fprintf(stderr
, "invalid aio request (0x%x)\n", aiocb
->aio_type
);
661 g_slice_free(RawPosixAIOData
, aiocb
);
665 static BlockDriverAIOCB
*paio_submit(BlockDriverState
*bs
, int fd
,
666 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
667 BlockDriverCompletionFunc
*cb
, void *opaque
, int type
)
669 RawPosixAIOData
*acb
= g_slice_new(RawPosixAIOData
);
672 acb
->aio_type
= type
;
673 acb
->aio_fildes
= fd
;
676 acb
->aio_iov
= qiov
->iov
;
677 acb
->aio_niov
= qiov
->niov
;
679 acb
->aio_nbytes
= nb_sectors
* 512;
680 acb
->aio_offset
= sector_num
* 512;
682 trace_paio_submit(acb
, opaque
, sector_num
, nb_sectors
, type
);
683 return thread_pool_submit_aio(aio_worker
, acb
, cb
, opaque
);
686 static BlockDriverAIOCB
*raw_aio_submit(BlockDriverState
*bs
,
687 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
688 BlockDriverCompletionFunc
*cb
, void *opaque
, int type
)
690 BDRVRawState
*s
= bs
->opaque
;
696 * If O_DIRECT is used the buffer needs to be aligned on a sector
697 * boundary. Check if this is the case or tell the low-level
698 * driver that it needs to copy the buffer.
700 if ((bs
->open_flags
& BDRV_O_NOCACHE
)) {
701 if (!bdrv_qiov_is_aligned(bs
, qiov
)) {
702 type
|= QEMU_AIO_MISALIGNED
;
703 #ifdef CONFIG_LINUX_AIO
704 } else if (s
->use_aio
) {
705 return laio_submit(bs
, s
->aio_ctx
, s
->fd
, sector_num
, qiov
,
706 nb_sectors
, cb
, opaque
, type
);
711 return paio_submit(bs
, s
->fd
, sector_num
, qiov
, nb_sectors
,
715 static BlockDriverAIOCB
*raw_aio_readv(BlockDriverState
*bs
,
716 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
717 BlockDriverCompletionFunc
*cb
, void *opaque
)
719 return raw_aio_submit(bs
, sector_num
, qiov
, nb_sectors
,
720 cb
, opaque
, QEMU_AIO_READ
);
723 static BlockDriverAIOCB
*raw_aio_writev(BlockDriverState
*bs
,
724 int64_t sector_num
, QEMUIOVector
*qiov
, int nb_sectors
,
725 BlockDriverCompletionFunc
*cb
, void *opaque
)
727 return raw_aio_submit(bs
, sector_num
, qiov
, nb_sectors
,
728 cb
, opaque
, QEMU_AIO_WRITE
);
731 static BlockDriverAIOCB
*raw_aio_flush(BlockDriverState
*bs
,
732 BlockDriverCompletionFunc
*cb
, void *opaque
)
734 BDRVRawState
*s
= bs
->opaque
;
739 return paio_submit(bs
, s
->fd
, 0, NULL
, 0, cb
, opaque
, QEMU_AIO_FLUSH
);
742 static void raw_close(BlockDriverState
*bs
)
744 BDRVRawState
*s
= bs
->opaque
;
751 static int raw_truncate(BlockDriverState
*bs
, int64_t offset
)
753 BDRVRawState
*s
= bs
->opaque
;
756 if (fstat(s
->fd
, &st
)) {
760 if (S_ISREG(st
.st_mode
)) {
761 if (ftruncate(s
->fd
, offset
) < 0) {
764 } else if (S_ISCHR(st
.st_mode
) || S_ISBLK(st
.st_mode
)) {
765 if (offset
> raw_getlength(bs
)) {
776 static int64_t raw_getlength(BlockDriverState
*bs
)
778 BDRVRawState
*s
= bs
->opaque
;
784 if (S_ISCHR(st
.st_mode
) || S_ISBLK(st
.st_mode
)) {
787 if (ioctl(fd
, DIOCGDINFO
, &dl
))
789 return (uint64_t)dl
.d_secsize
*
790 dl
.d_partitions
[DISKPART(st
.st_rdev
)].p_size
;
794 #elif defined(__NetBSD__)
795 static int64_t raw_getlength(BlockDriverState
*bs
)
797 BDRVRawState
*s
= bs
->opaque
;
803 if (S_ISCHR(st
.st_mode
) || S_ISBLK(st
.st_mode
)) {
804 struct dkwedge_info dkw
;
806 if (ioctl(fd
, DIOCGWEDGEINFO
, &dkw
) != -1) {
807 return dkw
.dkw_size
* 512;
811 if (ioctl(fd
, DIOCGDINFO
, &dl
))
813 return (uint64_t)dl
.d_secsize
*
814 dl
.d_partitions
[DISKPART(st
.st_rdev
)].p_size
;
819 #elif defined(__sun__)
820 static int64_t raw_getlength(BlockDriverState
*bs
)
822 BDRVRawState
*s
= bs
->opaque
;
823 struct dk_minfo minfo
;
832 * Use the DKIOCGMEDIAINFO ioctl to read the size.
834 ret
= ioctl(s
->fd
, DKIOCGMEDIAINFO
, &minfo
);
836 return minfo
.dki_lbsize
* minfo
.dki_capacity
;
840 * There are reports that lseek on some devices fails, but
841 * irc discussion said that contingency on contingency was overkill.
843 return lseek(s
->fd
, 0, SEEK_END
);
845 #elif defined(CONFIG_BSD)
846 static int64_t raw_getlength(BlockDriverState
*bs
)
848 BDRVRawState
*s
= bs
->opaque
;
852 #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
861 #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
864 if (!fstat(fd
, &sb
) && (S_IFCHR
& sb
.st_mode
)) {
865 #ifdef DIOCGMEDIASIZE
866 if (ioctl(fd
, DIOCGMEDIASIZE
, (off_t
*)&size
))
867 #elif defined(DIOCGPART)
870 if (ioctl(fd
, DIOCGPART
, &pi
) == 0)
871 size
= pi
.media_size
;
877 #if defined(__APPLE__) && defined(__MACH__)
878 size
= LONG_LONG_MAX
;
880 size
= lseek(fd
, 0LL, SEEK_END
);
882 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
885 /* XXX FreeBSD acd returns UINT_MAX sectors for an empty drive */
886 if (size
== 2048LL * (unsigned)-1)
888 /* XXX no disc? maybe we need to reopen... */
889 if (size
<= 0 && !reopened
&& cdrom_reopen(bs
) >= 0) {
896 size
= lseek(fd
, 0, SEEK_END
);
901 static int64_t raw_getlength(BlockDriverState
*bs
)
903 BDRVRawState
*s
= bs
->opaque
;
911 return lseek(s
->fd
, 0, SEEK_END
);
915 static int64_t raw_get_allocated_file_size(BlockDriverState
*bs
)
918 BDRVRawState
*s
= bs
->opaque
;
920 if (fstat(s
->fd
, &st
) < 0) {
923 return (int64_t)st
.st_blocks
* 512;
926 static int raw_create(const char *filename
, QEMUOptionParameter
*options
)
930 int64_t total_size
= 0;
932 /* Read out options */
933 while (options
&& options
->name
) {
934 if (!strcmp(options
->name
, BLOCK_OPT_SIZE
)) {
935 total_size
= options
->value
.n
/ BDRV_SECTOR_SIZE
;
940 fd
= qemu_open(filename
, O_WRONLY
| O_CREAT
| O_TRUNC
| O_BINARY
,
945 if (ftruncate(fd
, total_size
* BDRV_SECTOR_SIZE
) != 0) {
948 if (qemu_close(fd
) != 0) {
956 * Returns true iff the specified sector is present in the disk image. Drivers
957 * not implementing the functionality are assumed to not support backing files,
958 * hence all their sectors are reported as allocated.
960 * If 'sector_num' is beyond the end of the disk image the return value is 0
961 * and 'pnum' is set to 0.
963 * 'pnum' is set to the number of sectors (including and immediately following
964 * the specified sector) that are known to be in the same
965 * allocated/unallocated state.
967 * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes
968 * beyond the end of the disk image it will be clamped.
970 static int coroutine_fn
raw_co_is_allocated(BlockDriverState
*bs
,
972 int nb_sectors
, int *pnum
)
974 off_t start
, data
, hole
;
982 start
= sector_num
* BDRV_SECTOR_SIZE
;
986 BDRVRawState
*s
= bs
->opaque
;
989 struct fiemap_extent fe
;
992 f
.fm
.fm_start
= start
;
993 f
.fm
.fm_length
= (int64_t)nb_sectors
* BDRV_SECTOR_SIZE
;
995 f
.fm
.fm_extent_count
= 1;
996 f
.fm
.fm_reserved
= 0;
997 if (ioctl(s
->fd
, FS_IOC_FIEMAP
, &f
) == -1) {
998 /* Assume everything is allocated. */
1003 if (f
.fm
.fm_mapped_extents
== 0) {
1004 /* No extents found, data is beyond f.fm.fm_start + f.fm.fm_length.
1005 * f.fm.fm_start + f.fm.fm_length must be clamped to the file size!
1007 off_t length
= lseek(s
->fd
, 0, SEEK_END
);
1008 hole
= f
.fm
.fm_start
;
1009 data
= MIN(f
.fm
.fm_start
+ f
.fm
.fm_length
, length
);
1011 data
= f
.fe
.fe_logical
;
1012 hole
= f
.fe
.fe_logical
+ f
.fe
.fe_length
;
1015 #elif defined SEEK_HOLE && defined SEEK_DATA
1017 BDRVRawState
*s
= bs
->opaque
;
1019 hole
= lseek(s
->fd
, start
, SEEK_HOLE
);
1021 /* -ENXIO indicates that sector_num was past the end of the file.
1022 * There is a virtual hole there. */
1023 assert(errno
!= -ENXIO
);
1025 /* Most likely EINVAL. Assume everything is allocated. */
1033 /* On a hole. We need another syscall to find its end. */
1034 data
= lseek(s
->fd
, start
, SEEK_DATA
);
1036 data
= lseek(s
->fd
, 0, SEEK_END
);
1044 if (data
<= start
) {
1045 /* On a data extent, compute sectors to the end of the extent. */
1046 *pnum
= MIN(nb_sectors
, (hole
- start
) / BDRV_SECTOR_SIZE
);
1049 /* On a hole, compute sectors to the beginning of the next extent. */
1050 *pnum
= MIN(nb_sectors
, (data
- start
) / BDRV_SECTOR_SIZE
);
1056 static int xfs_discard(BDRVRawState
*s
, int64_t sector_num
, int nb_sectors
)
1058 struct xfs_flock64 fl
;
1060 memset(&fl
, 0, sizeof(fl
));
1061 fl
.l_whence
= SEEK_SET
;
1062 fl
.l_start
= sector_num
<< 9;
1063 fl
.l_len
= (int64_t)nb_sectors
<< 9;
1065 if (xfsctl(NULL
, s
->fd
, XFS_IOC_UNRESVSP64
, &fl
) < 0) {
1066 DEBUG_BLOCK_PRINT("cannot punch hole (%s)\n", strerror(errno
));
1074 static coroutine_fn
int raw_co_discard(BlockDriverState
*bs
,
1075 int64_t sector_num
, int nb_sectors
)
1078 BDRVRawState
*s
= bs
->opaque
;
1081 return xfs_discard(s
, sector_num
, nb_sectors
);
1088 static QEMUOptionParameter raw_create_options
[] = {
1090 .name
= BLOCK_OPT_SIZE
,
1092 .help
= "Virtual disk size"
1097 static BlockDriver bdrv_file
= {
1098 .format_name
= "file",
1099 .protocol_name
= "file",
1100 .instance_size
= sizeof(BDRVRawState
),
1101 .bdrv_probe
= NULL
, /* no probe for protocols */
1102 .bdrv_file_open
= raw_open
,
1103 .bdrv_reopen_prepare
= raw_reopen_prepare
,
1104 .bdrv_reopen_commit
= raw_reopen_commit
,
1105 .bdrv_reopen_abort
= raw_reopen_abort
,
1106 .bdrv_close
= raw_close
,
1107 .bdrv_create
= raw_create
,
1108 .bdrv_co_discard
= raw_co_discard
,
1109 .bdrv_co_is_allocated
= raw_co_is_allocated
,
1111 .bdrv_aio_readv
= raw_aio_readv
,
1112 .bdrv_aio_writev
= raw_aio_writev
,
1113 .bdrv_aio_flush
= raw_aio_flush
,
1115 .bdrv_truncate
= raw_truncate
,
1116 .bdrv_getlength
= raw_getlength
,
1117 .bdrv_get_allocated_file_size
1118 = raw_get_allocated_file_size
,
1120 .create_options
= raw_create_options
,
1123 /***********************************************/
1126 #if defined(__APPLE__) && defined(__MACH__)
1127 static kern_return_t
FindEjectableCDMedia( io_iterator_t
*mediaIterator
);
1128 static kern_return_t
GetBSDPath( io_iterator_t mediaIterator
, char *bsdPath
, CFIndex maxPathSize
);
1130 kern_return_t
FindEjectableCDMedia( io_iterator_t
*mediaIterator
)
1132 kern_return_t kernResult
;
1133 mach_port_t masterPort
;
1134 CFMutableDictionaryRef classesToMatch
;
1136 kernResult
= IOMasterPort( MACH_PORT_NULL
, &masterPort
);
1137 if ( KERN_SUCCESS
!= kernResult
) {
1138 printf( "IOMasterPort returned %d\n", kernResult
);
1141 classesToMatch
= IOServiceMatching( kIOCDMediaClass
);
1142 if ( classesToMatch
== NULL
) {
1143 printf( "IOServiceMatching returned a NULL dictionary.\n" );
1145 CFDictionarySetValue( classesToMatch
, CFSTR( kIOMediaEjectableKey
), kCFBooleanTrue
);
1147 kernResult
= IOServiceGetMatchingServices( masterPort
, classesToMatch
, mediaIterator
);
1148 if ( KERN_SUCCESS
!= kernResult
)
1150 printf( "IOServiceGetMatchingServices returned %d\n", kernResult
);
1156 kern_return_t
GetBSDPath( io_iterator_t mediaIterator
, char *bsdPath
, CFIndex maxPathSize
)
1158 io_object_t nextMedia
;
1159 kern_return_t kernResult
= KERN_FAILURE
;
1161 nextMedia
= IOIteratorNext( mediaIterator
);
1164 CFTypeRef bsdPathAsCFString
;
1165 bsdPathAsCFString
= IORegistryEntryCreateCFProperty( nextMedia
, CFSTR( kIOBSDNameKey
), kCFAllocatorDefault
, 0 );
1166 if ( bsdPathAsCFString
) {
1167 size_t devPathLength
;
1168 strcpy( bsdPath
, _PATH_DEV
);
1169 strcat( bsdPath
, "r" );
1170 devPathLength
= strlen( bsdPath
);
1171 if ( CFStringGetCString( bsdPathAsCFString
, bsdPath
+ devPathLength
, maxPathSize
- devPathLength
, kCFStringEncodingASCII
) ) {
1172 kernResult
= KERN_SUCCESS
;
1174 CFRelease( bsdPathAsCFString
);
1176 IOObjectRelease( nextMedia
);
1184 static int hdev_probe_device(const char *filename
)
1188 /* allow a dedicated CD-ROM driver to match with a higher priority */
1189 if (strstart(filename
, "/dev/cdrom", NULL
))
1192 if (stat(filename
, &st
) >= 0 &&
1193 (S_ISCHR(st
.st_mode
) || S_ISBLK(st
.st_mode
))) {
1200 static int hdev_open(BlockDriverState
*bs
, const char *filename
, int flags
)
1202 BDRVRawState
*s
= bs
->opaque
;
1204 #if defined(__APPLE__) && defined(__MACH__)
1205 if (strstart(filename
, "/dev/cdrom", NULL
)) {
1206 kern_return_t kernResult
;
1207 io_iterator_t mediaIterator
;
1208 char bsdPath
[ MAXPATHLEN
];
1211 kernResult
= FindEjectableCDMedia( &mediaIterator
);
1212 kernResult
= GetBSDPath( mediaIterator
, bsdPath
, sizeof( bsdPath
) );
1214 if ( bsdPath
[ 0 ] != '\0' ) {
1215 strcat(bsdPath
,"s0");
1216 /* some CDs don't have a partition 0 */
1217 fd
= qemu_open(bsdPath
, O_RDONLY
| O_BINARY
| O_LARGEFILE
);
1219 bsdPath
[strlen(bsdPath
)-1] = '1';
1226 if ( mediaIterator
)
1227 IOObjectRelease( mediaIterator
);
1231 s
->type
= FTYPE_FILE
;
1232 #if defined(__linux__)
1234 char resolved_path
[ MAXPATHLEN
], *temp
;
1236 temp
= realpath(filename
, resolved_path
);
1237 if (temp
&& strstart(temp
, "/dev/sg", NULL
)) {
1243 return raw_open_common(bs
, filename
, flags
, 0);
1246 #if defined(__linux__)
1247 /* Note: we do not have a reliable method to detect if the floppy is
1248 present. The current method is to try to open the floppy at every
1249 I/O and to keep it opened during a few hundreds of ms. */
1250 static int fd_open(BlockDriverState
*bs
)
1252 BDRVRawState
*s
= bs
->opaque
;
1253 int last_media_present
;
1255 if (s
->type
!= FTYPE_FD
)
1257 last_media_present
= (s
->fd
>= 0);
1259 (get_clock() - s
->fd_open_time
) >= FD_OPEN_TIMEOUT
) {
1263 printf("Floppy closed\n");
1267 if (s
->fd_got_error
&&
1268 (get_clock() - s
->fd_error_time
) < FD_OPEN_TIMEOUT
) {
1270 printf("No floppy (open delayed)\n");
1274 s
->fd
= qemu_open(bs
->filename
, s
->open_flags
& ~O_NONBLOCK
);
1276 s
->fd_error_time
= get_clock();
1277 s
->fd_got_error
= 1;
1278 if (last_media_present
)
1279 s
->fd_media_changed
= 1;
1281 printf("No floppy\n");
1286 printf("Floppy opened\n");
1289 if (!last_media_present
)
1290 s
->fd_media_changed
= 1;
1291 s
->fd_open_time
= get_clock();
1292 s
->fd_got_error
= 0;
1296 static int hdev_ioctl(BlockDriverState
*bs
, unsigned long int req
, void *buf
)
1298 BDRVRawState
*s
= bs
->opaque
;
1300 return ioctl(s
->fd
, req
, buf
);
1303 static BlockDriverAIOCB
*hdev_aio_ioctl(BlockDriverState
*bs
,
1304 unsigned long int req
, void *buf
,
1305 BlockDriverCompletionFunc
*cb
, void *opaque
)
1307 BDRVRawState
*s
= bs
->opaque
;
1308 RawPosixAIOData
*acb
;
1310 if (fd_open(bs
) < 0)
1313 acb
= g_slice_new(RawPosixAIOData
);
1315 acb
->aio_type
= QEMU_AIO_IOCTL
;
1316 acb
->aio_fildes
= s
->fd
;
1317 acb
->aio_offset
= 0;
1318 acb
->aio_ioctl_buf
= buf
;
1319 acb
->aio_ioctl_cmd
= req
;
1320 return thread_pool_submit_aio(aio_worker
, acb
, cb
, opaque
);
1323 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1324 static int fd_open(BlockDriverState
*bs
)
1326 BDRVRawState
*s
= bs
->opaque
;
1328 /* this is just to ensure s->fd is sane (its called by io ops) */
1333 #else /* !linux && !FreeBSD */
1335 static int fd_open(BlockDriverState
*bs
)
1340 #endif /* !linux && !FreeBSD */
1342 static int hdev_create(const char *filename
, QEMUOptionParameter
*options
)
1346 struct stat stat_buf
;
1347 int64_t total_size
= 0;
1349 /* Read out options */
1350 while (options
&& options
->name
) {
1351 if (!strcmp(options
->name
, "size")) {
1352 total_size
= options
->value
.n
/ BDRV_SECTOR_SIZE
;
1357 fd
= qemu_open(filename
, O_WRONLY
| O_BINARY
);
1361 if (fstat(fd
, &stat_buf
) < 0)
1363 else if (!S_ISBLK(stat_buf
.st_mode
) && !S_ISCHR(stat_buf
.st_mode
))
1365 else if (lseek(fd
, 0, SEEK_END
) < total_size
* BDRV_SECTOR_SIZE
)
1372 static int hdev_has_zero_init(BlockDriverState
*bs
)
1377 static BlockDriver bdrv_host_device
= {
1378 .format_name
= "host_device",
1379 .protocol_name
= "host_device",
1380 .instance_size
= sizeof(BDRVRawState
),
1381 .bdrv_probe_device
= hdev_probe_device
,
1382 .bdrv_file_open
= hdev_open
,
1383 .bdrv_close
= raw_close
,
1384 .bdrv_reopen_prepare
= raw_reopen_prepare
,
1385 .bdrv_reopen_commit
= raw_reopen_commit
,
1386 .bdrv_reopen_abort
= raw_reopen_abort
,
1387 .bdrv_create
= hdev_create
,
1388 .create_options
= raw_create_options
,
1389 .bdrv_has_zero_init
= hdev_has_zero_init
,
1391 .bdrv_aio_readv
= raw_aio_readv
,
1392 .bdrv_aio_writev
= raw_aio_writev
,
1393 .bdrv_aio_flush
= raw_aio_flush
,
1395 .bdrv_truncate
= raw_truncate
,
1396 .bdrv_getlength
= raw_getlength
,
1397 .bdrv_get_allocated_file_size
1398 = raw_get_allocated_file_size
,
1400 /* generic scsi device */
1402 .bdrv_ioctl
= hdev_ioctl
,
1403 .bdrv_aio_ioctl
= hdev_aio_ioctl
,
1408 static int floppy_open(BlockDriverState
*bs
, const char *filename
, int flags
)
1410 BDRVRawState
*s
= bs
->opaque
;
1415 /* open will not fail even if no floppy is inserted, so add O_NONBLOCK */
1416 ret
= raw_open_common(bs
, filename
, flags
, O_NONBLOCK
);
1420 /* close fd so that we can reopen it as needed */
1423 s
->fd_media_changed
= 1;
1428 static int floppy_probe_device(const char *filename
)
1432 struct floppy_struct fdparam
;
1435 if (strstart(filename
, "/dev/fd", NULL
) &&
1436 !strstart(filename
, "/dev/fdset/", NULL
)) {
1440 fd
= qemu_open(filename
, O_RDONLY
| O_NONBLOCK
);
1444 ret
= fstat(fd
, &st
);
1445 if (ret
== -1 || !S_ISBLK(st
.st_mode
)) {
1449 /* Attempt to detect via a floppy specific ioctl */
1450 ret
= ioctl(fd
, FDGETPRM
, &fdparam
);
1461 static int floppy_is_inserted(BlockDriverState
*bs
)
1463 return fd_open(bs
) >= 0;
1466 static int floppy_media_changed(BlockDriverState
*bs
)
1468 BDRVRawState
*s
= bs
->opaque
;
1472 * XXX: we do not have a true media changed indication.
1473 * It does not work if the floppy is changed without trying to read it.
1476 ret
= s
->fd_media_changed
;
1477 s
->fd_media_changed
= 0;
1479 printf("Floppy changed=%d\n", ret
);
1484 static void floppy_eject(BlockDriverState
*bs
, bool eject_flag
)
1486 BDRVRawState
*s
= bs
->opaque
;
1493 fd
= qemu_open(bs
->filename
, s
->open_flags
| O_NONBLOCK
);
1495 if (ioctl(fd
, FDEJECT
, 0) < 0)
1501 static BlockDriver bdrv_host_floppy
= {
1502 .format_name
= "host_floppy",
1503 .protocol_name
= "host_floppy",
1504 .instance_size
= sizeof(BDRVRawState
),
1505 .bdrv_probe_device
= floppy_probe_device
,
1506 .bdrv_file_open
= floppy_open
,
1507 .bdrv_close
= raw_close
,
1508 .bdrv_reopen_prepare
= raw_reopen_prepare
,
1509 .bdrv_reopen_commit
= raw_reopen_commit
,
1510 .bdrv_reopen_abort
= raw_reopen_abort
,
1511 .bdrv_create
= hdev_create
,
1512 .create_options
= raw_create_options
,
1513 .bdrv_has_zero_init
= hdev_has_zero_init
,
1515 .bdrv_aio_readv
= raw_aio_readv
,
1516 .bdrv_aio_writev
= raw_aio_writev
,
1517 .bdrv_aio_flush
= raw_aio_flush
,
1519 .bdrv_truncate
= raw_truncate
,
1520 .bdrv_getlength
= raw_getlength
,
1521 .bdrv_get_allocated_file_size
1522 = raw_get_allocated_file_size
,
1524 /* removable device support */
1525 .bdrv_is_inserted
= floppy_is_inserted
,
1526 .bdrv_media_changed
= floppy_media_changed
,
1527 .bdrv_eject
= floppy_eject
,
1530 static int cdrom_open(BlockDriverState
*bs
, const char *filename
, int flags
)
1532 BDRVRawState
*s
= bs
->opaque
;
1536 /* open will not fail even if no CD is inserted, so add O_NONBLOCK */
1537 return raw_open_common(bs
, filename
, flags
, O_NONBLOCK
);
1540 static int cdrom_probe_device(const char *filename
)
1546 fd
= qemu_open(filename
, O_RDONLY
| O_NONBLOCK
);
1550 ret
= fstat(fd
, &st
);
1551 if (ret
== -1 || !S_ISBLK(st
.st_mode
)) {
1555 /* Attempt to detect via a CDROM specific ioctl */
1556 ret
= ioctl(fd
, CDROM_DRIVE_STATUS
, CDSL_CURRENT
);
1566 static int cdrom_is_inserted(BlockDriverState
*bs
)
1568 BDRVRawState
*s
= bs
->opaque
;
1571 ret
= ioctl(s
->fd
, CDROM_DRIVE_STATUS
, CDSL_CURRENT
);
1572 if (ret
== CDS_DISC_OK
)
1577 static void cdrom_eject(BlockDriverState
*bs
, bool eject_flag
)
1579 BDRVRawState
*s
= bs
->opaque
;
1582 if (ioctl(s
->fd
, CDROMEJECT
, NULL
) < 0)
1583 perror("CDROMEJECT");
1585 if (ioctl(s
->fd
, CDROMCLOSETRAY
, NULL
) < 0)
1586 perror("CDROMEJECT");
1590 static void cdrom_lock_medium(BlockDriverState
*bs
, bool locked
)
1592 BDRVRawState
*s
= bs
->opaque
;
1594 if (ioctl(s
->fd
, CDROM_LOCKDOOR
, locked
) < 0) {
1596 * Note: an error can happen if the distribution automatically
1599 /* perror("CDROM_LOCKDOOR"); */
1603 static BlockDriver bdrv_host_cdrom
= {
1604 .format_name
= "host_cdrom",
1605 .protocol_name
= "host_cdrom",
1606 .instance_size
= sizeof(BDRVRawState
),
1607 .bdrv_probe_device
= cdrom_probe_device
,
1608 .bdrv_file_open
= cdrom_open
,
1609 .bdrv_close
= raw_close
,
1610 .bdrv_reopen_prepare
= raw_reopen_prepare
,
1611 .bdrv_reopen_commit
= raw_reopen_commit
,
1612 .bdrv_reopen_abort
= raw_reopen_abort
,
1613 .bdrv_create
= hdev_create
,
1614 .create_options
= raw_create_options
,
1615 .bdrv_has_zero_init
= hdev_has_zero_init
,
1617 .bdrv_aio_readv
= raw_aio_readv
,
1618 .bdrv_aio_writev
= raw_aio_writev
,
1619 .bdrv_aio_flush
= raw_aio_flush
,
1621 .bdrv_truncate
= raw_truncate
,
1622 .bdrv_getlength
= raw_getlength
,
1623 .bdrv_get_allocated_file_size
1624 = raw_get_allocated_file_size
,
1626 /* removable device support */
1627 .bdrv_is_inserted
= cdrom_is_inserted
,
1628 .bdrv_eject
= cdrom_eject
,
1629 .bdrv_lock_medium
= cdrom_lock_medium
,
1631 /* generic scsi device */
1632 .bdrv_ioctl
= hdev_ioctl
,
1633 .bdrv_aio_ioctl
= hdev_aio_ioctl
,
1635 #endif /* __linux__ */
1637 #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
1638 static int cdrom_open(BlockDriverState
*bs
, const char *filename
, int flags
)
1640 BDRVRawState
*s
= bs
->opaque
;
1645 ret
= raw_open_common(bs
, filename
, flags
, 0);
1649 /* make sure the door isn't locked at this time */
1650 ioctl(s
->fd
, CDIOCALLOW
);
1654 static int cdrom_probe_device(const char *filename
)
1656 if (strstart(filename
, "/dev/cd", NULL
) ||
1657 strstart(filename
, "/dev/acd", NULL
))
1662 static int cdrom_reopen(BlockDriverState
*bs
)
1664 BDRVRawState
*s
= bs
->opaque
;
1668 * Force reread of possibly changed/newly loaded disc,
1669 * FreeBSD seems to not notice sometimes...
1673 fd
= qemu_open(bs
->filename
, s
->open_flags
, 0644);
1680 /* make sure the door isn't locked at this time */
1681 ioctl(s
->fd
, CDIOCALLOW
);
1685 static int cdrom_is_inserted(BlockDriverState
*bs
)
1687 return raw_getlength(bs
) > 0;
1690 static void cdrom_eject(BlockDriverState
*bs
, bool eject_flag
)
1692 BDRVRawState
*s
= bs
->opaque
;
1697 (void) ioctl(s
->fd
, CDIOCALLOW
);
1700 if (ioctl(s
->fd
, CDIOCEJECT
) < 0)
1701 perror("CDIOCEJECT");
1703 if (ioctl(s
->fd
, CDIOCCLOSE
) < 0)
1704 perror("CDIOCCLOSE");
1710 static void cdrom_lock_medium(BlockDriverState
*bs
, bool locked
)
1712 BDRVRawState
*s
= bs
->opaque
;
1716 if (ioctl(s
->fd
, (locked
? CDIOCPREVENT
: CDIOCALLOW
)) < 0) {
1718 * Note: an error can happen if the distribution automatically
1721 /* perror("CDROM_LOCKDOOR"); */
1725 static BlockDriver bdrv_host_cdrom
= {
1726 .format_name
= "host_cdrom",
1727 .protocol_name
= "host_cdrom",
1728 .instance_size
= sizeof(BDRVRawState
),
1729 .bdrv_probe_device
= cdrom_probe_device
,
1730 .bdrv_file_open
= cdrom_open
,
1731 .bdrv_close
= raw_close
,
1732 .bdrv_reopen_prepare
= raw_reopen_prepare
,
1733 .bdrv_reopen_commit
= raw_reopen_commit
,
1734 .bdrv_reopen_abort
= raw_reopen_abort
,
1735 .bdrv_create
= hdev_create
,
1736 .create_options
= raw_create_options
,
1737 .bdrv_has_zero_init
= hdev_has_zero_init
,
1739 .bdrv_aio_readv
= raw_aio_readv
,
1740 .bdrv_aio_writev
= raw_aio_writev
,
1741 .bdrv_aio_flush
= raw_aio_flush
,
1743 .bdrv_truncate
= raw_truncate
,
1744 .bdrv_getlength
= raw_getlength
,
1745 .bdrv_get_allocated_file_size
1746 = raw_get_allocated_file_size
,
1748 /* removable device support */
1749 .bdrv_is_inserted
= cdrom_is_inserted
,
1750 .bdrv_eject
= cdrom_eject
,
1751 .bdrv_lock_medium
= cdrom_lock_medium
,
1753 #endif /* __FreeBSD__ */
1755 #ifdef CONFIG_LINUX_AIO
1757 * Return the file descriptor for Linux AIO
1759 * This function is a layering violation and should be removed when it becomes
1760 * possible to call the block layer outside the global mutex. It allows the
1761 * caller to hijack the file descriptor so I/O can be performed outside the
1764 int raw_get_aio_fd(BlockDriverState
*bs
)
1772 if (bs
->drv
== bdrv_find_format("raw")) {
1776 /* raw-posix has several protocols so just check for raw_aio_readv */
1777 if (bs
->drv
->bdrv_aio_readv
!= raw_aio_readv
) {
1787 #endif /* CONFIG_LINUX_AIO */
1789 static void bdrv_file_init(void)
1792 * Register all the drivers. Note that order is important, the driver
1793 * registered last will get probed first.
1795 bdrv_register(&bdrv_file
);
1796 bdrv_register(&bdrv_host_device
);
1798 bdrv_register(&bdrv_host_floppy
);
1799 bdrv_register(&bdrv_host_cdrom
);
1801 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
1802 bdrv_register(&bdrv_host_cdrom
);
1806 block_init(bdrv_file_init
);