From: Stefan Weil Date: Sun, 1 Sep 2013 20:59:25 +0000 (+0200) Subject: w32: Fix access to host devices (regression) X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~645 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f307ee0beee37aa8f977582d5aa87e472623b1b5;p=sdk%2Femulator%2Fqemu.git w32: Fix access to host devices (regression) QEMU failed to open host devices like \\.\PhysicalDrive0 (first hard disk) since some time (commit 8a79380b8ef1b02d2abd705dd026a18863b09020?). Those devices use hdev_open which did not use the latest API for options. This resulted in a fatal runtime error: Block protocol 'host_device' doesn't support the option 'filename' Duplicate code from raw_open to fix this. Cc: qemu-stable@nongnu.org Reported-by: David Brenner Signed-off-by: Stefan Weil Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi (cherry picked from commit 68dc036488dfea170627a55e6ee3dfd7f2c2063e) Signed-off-by: Michael Roth --- diff --git a/block/raw-win32.c b/block/raw-win32.c index ae2a98caa7..9686afe702 100644 --- a/block/raw-win32.c +++ b/block/raw-win32.c @@ -578,18 +578,34 @@ static int hdev_probe_device(const char *filename) static int hdev_open(BlockDriverState *bs, QDict *options, int flags) { BDRVRawState *s = bs->opaque; - char device_name[64]; - const char *filename = qdict_get_str(options, "filename"); #ifndef CONFIG_MARU int access_flags, create_flags; DWORD overlapped; #else - int open_flags, ret; + int open_flags; #endif + int ret = 0; + char device_name[64]; + + Error *local_err = NULL; + const char *filename; + + QemuOpts *opts = qemu_opts_create_nofail(&raw_runtime_opts); + qemu_opts_absorb_qdict(opts, options, &local_err); + if (error_is_set(&local_err)) { + qerror_report_err(local_err); + error_free(local_err); + ret = -EINVAL; + goto done; + } + + filename = qemu_opt_get(opts, "filename"); if (strstart(filename, "/dev/cdrom", NULL)) { - if (find_cdrom(device_name, sizeof(device_name)) < 0) - return -ENOENT; + if (find_cdrom(device_name, sizeof(device_name)) < 0) { + ret = -ENOENT; + goto done; + } filename = device_name; } else { /* transform drive letters into device name */ @@ -613,9 +629,12 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags) if (s->hfile == INVALID_HANDLE_VALUE) { int err = GetLastError(); - if (err == ERROR_ACCESS_DENIED) - return -EACCES; - return -1; + if (err == ERROR_ACCESS_DENIED) { + ret = -EACCES; + } else { + ret = -1; + } + goto done; } #else /* @@ -650,6 +669,10 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags) s->hfile = (HANDLE)_get_osfhandle(ret); #endif return 0; + +done: + qemu_opts_del(opts); + return ret; } static BlockDriver bdrv_host_device = {