diff options
author | Christoph Hellwig <hch@lst.de> | 2009-06-15 14:04:22 +0200 |
---|---|---|
committer | Christoph Hellwig <hch@brick.lst.de> | 2009-06-15 14:04:22 +0200 |
commit | 0968db3e1f89506967b70305225f4a2937cf7119 (patch) | |
tree | aba6e675fcd8b94b7019e3eaa56e4cc06502b9c5 /block.c | |
parent | 795174f0ba7208e713ee5dbe4fcc50d99a5591c0 (diff) | |
download | qemu-0968db3e1f89506967b70305225f4a2937cf7119.tar.gz qemu-0968db3e1f89506967b70305225f4a2937cf7119.tar.bz2 qemu-0968db3e1f89506967b70305225f4a2937cf7119.zip |
block: add bdrv_probe_device method
Add a bdrv_probe_device method to all BlockDriver instances implementing
host devices to move matching of host device types into the actual drivers.
For now we keep exacly the old matching behaviour based on the devices names,
although we really should have better detetion methods based on device
information in the future.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 44 |
1 files changed, 12 insertions, 32 deletions
@@ -209,7 +209,7 @@ static int is_windows_drive_prefix(const char *filename) filename[1] == ':'); } -static int is_windows_drive(const char *filename) +int is_windows_drive(const char *filename) { if (is_windows_drive_prefix(filename) && filename[2] == '\0') @@ -253,43 +253,23 @@ static BlockDriver *find_protocol(const char *filename) * Detect host devices. By convention, /dev/cdrom[N] is always * recognized as a host CDROM. */ -#ifdef _WIN32 -static BlockDriver *find_hdev_driver(const char *filename) -{ - if (strstart(filename, "/dev/cdrom", NULL)) - return bdrv_find_format("host_device"); - if (is_windows_drive(filename)) - return bdrv_find_format("host_device"); - return NULL; -} -#else static BlockDriver *find_hdev_driver(const char *filename) { - struct stat st; - -#ifdef __linux__ - if (strstart(filename, "/dev/fd", NULL)) - return bdrv_find_format("host_floppy"); - if (strstart(filename, "/dev/cd", NULL)) - return bdrv_find_format("host_cdrom"); -#elif defined(__FreeBSD__) - if (strstart(filename, "/dev/cd", NULL) || - strstart(filename, "/dev/acd", NULL)) { - return bdrv_find_format("host_cdrom"); - } -#else - if (strstart(filename, "/dev/cdrom", NULL)) - return bdrv_find_format("host_device"); -#endif + int score_max = 0, score; + BlockDriver *drv = NULL, *d; - if (stat(filename, &st) >= 0 && - (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode))) { - return bdrv_find_format("host_device"); + for (d = first_drv; d; d = d->next) { + if (d->bdrv_probe_device) { + score = d->bdrv_probe_device(filename); + if (score > score_max) { + score_max = score; + drv = d; + } + } } - return NULL; + return drv; } -#endif static BlockDriver *find_image_format(const char *filename) { |