From 508c7cb3fa666f0c4723946869f318ec7751ecbd Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Mon, 15 Jun 2009 14:04:22 +0200 Subject: 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 --- block.c | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'block.c') diff --git a/block.c b/block.c index 2e2059333c..c7e0dcbc5c 100644 --- a/block.c +++ b/block.c @@ -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) { -- cgit v1.2.1