static int open_f(BlockDriverState *bs, int argc, char **argv) { int flags = 0; int readonly = 0; int growable = 0; int c; QemuOpts *qopts; QDict *opts = NULL; while ((c = getopt(argc, argv, "snrgo:")) != EOF) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; break; case 'n': flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; break; case 'r': readonly = 1; break; case 'g': growable = 1; break; case 'o': qopts = qemu_opts_parse(&empty_opts, optarg, 0); if (qopts == NULL) { printf("could not parse option list -- %s\n", optarg); return 0; } opts = qemu_opts_to_qdict(qopts, opts); qemu_opts_del(qopts); break; default: return qemuio_command_usage(&open_cmd); } } if (!readonly) { flags |= BDRV_O_RDWR; } if (optind == argc - 1) { return openfile(argv[optind], flags, growable, opts); } else if (optind == argc) { return openfile(NULL, flags, growable, opts); } else { QDECREF(opts); return qemuio_command_usage(&open_cmd); } }
static int open_f(BlockDriverState *bs, int argc, char **argv) { int flags = 0; int readonly = 0; int growable = 0; int c; while ((c = getopt(argc, argv, "snrg")) != EOF) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; break; case 'n': flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB; break; case 'r': readonly = 1; break; case 'g': growable = 1; break; default: return qemuio_command_usage(&open_cmd); } } if (!readonly) { flags |= BDRV_O_RDWR; } if (optind != argc - 1) { return qemuio_command_usage(&open_cmd); } return openfile(argv[optind], flags, growable); }