Commit 609497ab3cf9ca65595ea78dbce253309bd11da3
1 parent
5697ff6b
Change -drive parsing so that paths don't have to be double-escaped (Laurent Viv…
…ier, Johannes Schindelin) git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3909 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
64 additions
and
47 deletions
qemu-doc.texi
... | ... | @@ -234,7 +234,8 @@ Define a new drive. Valid options are: |
234 | 234 | @table @code |
235 | 235 | @item file=@var{file} |
236 | 236 | This option defines which disk image (@pxref{disk_images}) to use with |
237 | -this drive. | |
237 | +this drive. If the filename contains comma, you must double it | |
238 | +(for instance, "file=my,,file" to use file "my,file"). | |
238 | 239 | @item if=@var{interface} |
239 | 240 | This option defines on which type on interface the drive is connected. |
240 | 241 | Available types are: ide, scsi, sd, mtd, floppy, pflash. | ... | ... |
vl.c
... | ... | @@ -231,7 +231,10 @@ unsigned int nb_prom_envs = 0; |
231 | 231 | const char *prom_envs[MAX_PROM_ENVS]; |
232 | 232 | #endif |
233 | 233 | int nb_drives_opt; |
234 | -char drives_opt[MAX_DRIVES][1024]; | |
234 | +struct drive_opt { | |
235 | + const char *file; | |
236 | + char opt[1024]; | |
237 | +} drives_opt[MAX_DRIVES]; | |
235 | 238 | |
236 | 239 | static CPUState *cur_cpu; |
237 | 240 | static CPUState *next_cpu; |
... | ... | @@ -4581,24 +4584,33 @@ static int net_socket_mcast_init(VLANState *vlan, const char *host_str) |
4581 | 4584 | |
4582 | 4585 | } |
4583 | 4586 | |
4584 | -static const char *get_word(char *buf, int buf_size, const char *p) | |
4587 | +static const char *get_opt_name(char *buf, int buf_size, const char *p) | |
4588 | +{ | |
4589 | + char *q; | |
4590 | + | |
4591 | + q = buf; | |
4592 | + while (*p != '\0' && *p != '=') { | |
4593 | + if (q && (q - buf) < buf_size - 1) | |
4594 | + *q++ = *p; | |
4595 | + p++; | |
4596 | + } | |
4597 | + if (q) | |
4598 | + *q = '\0'; | |
4599 | + | |
4600 | + return p; | |
4601 | +} | |
4602 | + | |
4603 | +static const char *get_opt_value(char *buf, int buf_size, const char *p) | |
4585 | 4604 | { |
4586 | 4605 | char *q; |
4587 | - int substring; | |
4588 | 4606 | |
4589 | - substring = 0; | |
4590 | 4607 | q = buf; |
4591 | 4608 | while (*p != '\0') { |
4592 | - if (*p == '\\') { | |
4593 | - p++; | |
4594 | - if (*p == '\0') | |
4609 | + if (*p == ',') { | |
4610 | + if (*(p + 1) != ',') | |
4595 | 4611 | break; |
4596 | - } else if (*p == '\"') { | |
4597 | - substring = !substring; | |
4598 | 4612 | p++; |
4599 | - continue; | |
4600 | - } else if (!substring && (*p == ',' || *p == '=')) | |
4601 | - break; | |
4613 | + } | |
4602 | 4614 | if (q && (q - buf) < buf_size - 1) |
4603 | 4615 | *q++ = *p; |
4604 | 4616 | p++; |
... | ... | @@ -4617,15 +4629,15 @@ static int get_param_value(char *buf, int buf_size, |
4617 | 4629 | |
4618 | 4630 | p = str; |
4619 | 4631 | for(;;) { |
4620 | - p = get_word(option, sizeof(option), p); | |
4632 | + p = get_opt_name(option, sizeof(option), p); | |
4621 | 4633 | if (*p != '=') |
4622 | 4634 | break; |
4623 | 4635 | p++; |
4624 | 4636 | if (!strcmp(tag, option)) { |
4625 | - (void)get_word(buf, buf_size, p); | |
4637 | + (void)get_opt_value(buf, buf_size, p); | |
4626 | 4638 | return strlen(buf); |
4627 | 4639 | } else { |
4628 | - p = get_word(NULL, 0, p); | |
4640 | + p = get_opt_value(NULL, 0, p); | |
4629 | 4641 | } |
4630 | 4642 | if (*p != ',') |
4631 | 4643 | break; |
... | ... | @@ -4642,7 +4654,7 @@ static int check_params(char *buf, int buf_size, |
4642 | 4654 | |
4643 | 4655 | p = str; |
4644 | 4656 | for(;;) { |
4645 | - p = get_word(buf, buf_size, p); | |
4657 | + p = get_opt_name(buf, buf_size, p); | |
4646 | 4658 | if (*p != '=') |
4647 | 4659 | return -1; |
4648 | 4660 | p++; |
... | ... | @@ -4651,7 +4663,7 @@ static int check_params(char *buf, int buf_size, |
4651 | 4663 | break; |
4652 | 4664 | if (params[i] == NULL) |
4653 | 4665 | return -1; |
4654 | - p = get_word(NULL, 0, p); | |
4666 | + p = get_opt_value(NULL, 0, p); | |
4655 | 4667 | if (*p != ',') |
4656 | 4668 | break; |
4657 | 4669 | p++; |
... | ... | @@ -4810,18 +4822,18 @@ void do_info_network(void) |
4810 | 4822 | } |
4811 | 4823 | } |
4812 | 4824 | |
4813 | -#define HD_ALIAS "file=\"%s\",index=%d,media=disk" | |
4825 | +#define HD_ALIAS "index=%d,media=disk" | |
4814 | 4826 | #ifdef TARGET_PPC |
4815 | 4827 | #define CDROM_ALIAS "index=1,media=cdrom" |
4816 | 4828 | #else |
4817 | 4829 | #define CDROM_ALIAS "index=2,media=cdrom" |
4818 | 4830 | #endif |
4819 | 4831 | #define FD_ALIAS "index=%d,if=floppy" |
4820 | -#define PFLASH_ALIAS "file=\"%s\",if=pflash" | |
4821 | -#define MTD_ALIAS "file=\"%s\",if=mtd" | |
4832 | +#define PFLASH_ALIAS "if=pflash" | |
4833 | +#define MTD_ALIAS "if=mtd" | |
4822 | 4834 | #define SD_ALIAS "index=0,if=sd" |
4823 | 4835 | |
4824 | -static int drive_add(const char *fmt, ...) | |
4836 | +static int drive_add(const char *file, const char *fmt, ...) | |
4825 | 4837 | { |
4826 | 4838 | va_list ap; |
4827 | 4839 | |
... | ... | @@ -4830,8 +4842,10 @@ static int drive_add(const char *fmt, ...) |
4830 | 4842 | exit(1); |
4831 | 4843 | } |
4832 | 4844 | |
4845 | + drives_opt[nb_drives_opt].file = file; | |
4833 | 4846 | va_start(ap, fmt); |
4834 | - vsnprintf(drives_opt[nb_drives_opt], sizeof(drives_opt[0]), fmt, ap); | |
4847 | + vsnprintf(drives_opt[nb_drives_opt].opt, | |
4848 | + sizeof(drives_opt[0].opt), fmt, ap); | |
4835 | 4849 | va_end(ap); |
4836 | 4850 | |
4837 | 4851 | return nb_drives_opt++; |
... | ... | @@ -4866,7 +4880,8 @@ int drive_get_max_bus(BlockInterfaceType type) |
4866 | 4880 | return max_bus; |
4867 | 4881 | } |
4868 | 4882 | |
4869 | -static int drive_init(const char *str, int snapshot, QEMUMachine *machine) | |
4883 | +static int drive_init(struct drive_opt *arg, int snapshot, | |
4884 | + QEMUMachine *machine) | |
4870 | 4885 | { |
4871 | 4886 | char buf[128]; |
4872 | 4887 | char file[1024]; |
... | ... | @@ -4881,6 +4896,7 @@ static int drive_init(const char *str, int snapshot, QEMUMachine *machine) |
4881 | 4896 | int index; |
4882 | 4897 | int cache; |
4883 | 4898 | int bdrv_flags; |
4899 | + char *str = arg->opt; | |
4884 | 4900 | char *params[] = { "bus", "unit", "if", "index", "cyls", "heads", |
4885 | 4901 | "secs", "trans", "media", "snapshot", "file", |
4886 | 4902 | "cache", NULL }; |
... | ... | @@ -5051,7 +5067,10 @@ static int drive_init(const char *str, int snapshot, QEMUMachine *machine) |
5051 | 5067 | } |
5052 | 5068 | } |
5053 | 5069 | |
5054 | - get_param_value(file, sizeof(file), "file", str); | |
5070 | + if (arg->file == NULL) | |
5071 | + get_param_value(file, sizeof(file), "file", str); | |
5072 | + else | |
5073 | + pstrcpy(file, sizeof(file), arg->file); | |
5055 | 5074 | |
5056 | 5075 | /* compute bus and unit according index */ |
5057 | 5076 | |
... | ... | @@ -8163,7 +8182,7 @@ int main(int argc, char **argv) |
8163 | 8182 | break; |
8164 | 8183 | r = argv[optind]; |
8165 | 8184 | if (r[0] != '-') { |
8166 | - hda_index = drive_add(HD_ALIAS, argv[optind++], 0); | |
8185 | + hda_index = drive_add(argv[optind++], HD_ALIAS, 0); | |
8167 | 8186 | } else { |
8168 | 8187 | const QEMUOption *popt; |
8169 | 8188 | |
... | ... | @@ -8224,11 +8243,11 @@ int main(int argc, char **argv) |
8224 | 8243 | break; |
8225 | 8244 | case QEMU_OPTION_hda: |
8226 | 8245 | if (cyls == 0) |
8227 | - hda_index = drive_add(HD_ALIAS, optarg, 0); | |
8246 | + hda_index = drive_add(optarg, HD_ALIAS, 0); | |
8228 | 8247 | else |
8229 | - hda_index = drive_add(HD_ALIAS | |
8248 | + hda_index = drive_add(optarg, HD_ALIAS | |
8230 | 8249 | ",cyls=%d,heads=%d,secs=%d%s", |
8231 | - optarg, 0, cyls, heads, secs, | |
8250 | + 0, cyls, heads, secs, | |
8232 | 8251 | translation == BIOS_ATA_TRANSLATION_LBA ? |
8233 | 8252 | ",trans=lba" : |
8234 | 8253 | translation == BIOS_ATA_TRANSLATION_NONE ? |
... | ... | @@ -8237,19 +8256,19 @@ int main(int argc, char **argv) |
8237 | 8256 | case QEMU_OPTION_hdb: |
8238 | 8257 | case QEMU_OPTION_hdc: |
8239 | 8258 | case QEMU_OPTION_hdd: |
8240 | - drive_add(HD_ALIAS, optarg, popt->index - QEMU_OPTION_hda); | |
8259 | + drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda); | |
8241 | 8260 | break; |
8242 | 8261 | case QEMU_OPTION_drive: |
8243 | - drive_add("%s", optarg); | |
8262 | + drive_add(NULL, "%s", optarg); | |
8244 | 8263 | break; |
8245 | 8264 | case QEMU_OPTION_mtdblock: |
8246 | - drive_add(MTD_ALIAS, optarg); | |
8265 | + drive_add(optarg, MTD_ALIAS); | |
8247 | 8266 | break; |
8248 | 8267 | case QEMU_OPTION_sd: |
8249 | - drive_add("file=\"%s\"," SD_ALIAS, optarg); | |
8268 | + drive_add(optarg, SD_ALIAS); | |
8250 | 8269 | break; |
8251 | 8270 | case QEMU_OPTION_pflash: |
8252 | - drive_add(PFLASH_ALIAS, optarg); | |
8271 | + drive_add(optarg, PFLASH_ALIAS); | |
8253 | 8272 | break; |
8254 | 8273 | case QEMU_OPTION_snapshot: |
8255 | 8274 | snapshot = 1; |
... | ... | @@ -8289,12 +8308,10 @@ int main(int argc, char **argv) |
8289 | 8308 | exit(1); |
8290 | 8309 | } |
8291 | 8310 | if (hda_index != -1) |
8292 | - snprintf(drives_opt[hda_index] + | |
8293 | - strlen(drives_opt[hda_index]), | |
8294 | - sizeof(drives_opt[0]) - | |
8295 | - strlen(drives_opt[hda_index]), | |
8296 | - ",cyls=%d,heads=%d,secs=%d%s", | |
8297 | - cyls, heads, secs, | |
8311 | + snprintf(drives_opt[hda_index].opt, | |
8312 | + sizeof(drives_opt[hda_index].opt), | |
8313 | + HD_ALIAS ",cyls=%d,heads=%d,secs=%d%s", | |
8314 | + 0, cyls, heads, secs, | |
8298 | 8315 | translation == BIOS_ATA_TRANSLATION_LBA ? |
8299 | 8316 | ",trans=lba" : |
8300 | 8317 | translation == BIOS_ATA_TRANSLATION_NONE ? |
... | ... | @@ -8317,7 +8334,7 @@ int main(int argc, char **argv) |
8317 | 8334 | kernel_cmdline = optarg; |
8318 | 8335 | break; |
8319 | 8336 | case QEMU_OPTION_cdrom: |
8320 | - drive_add("file=\"%s\"," CDROM_ALIAS, optarg); | |
8337 | + drive_add(optarg, CDROM_ALIAS); | |
8321 | 8338 | break; |
8322 | 8339 | case QEMU_OPTION_boot: |
8323 | 8340 | boot_devices = optarg; |
... | ... | @@ -8352,8 +8369,7 @@ int main(int argc, char **argv) |
8352 | 8369 | break; |
8353 | 8370 | case QEMU_OPTION_fda: |
8354 | 8371 | case QEMU_OPTION_fdb: |
8355 | - drive_add("file=\"%s\"," FD_ALIAS, optarg, | |
8356 | - popt->index - QEMU_OPTION_fda); | |
8372 | + drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda); | |
8357 | 8373 | break; |
8358 | 8374 | #ifdef TARGET_I386 |
8359 | 8375 | case QEMU_OPTION_no_fd_bootchk: |
... | ... | @@ -8822,22 +8838,22 @@ int main(int argc, char **argv) |
8822 | 8838 | /* we always create the cdrom drive, even if no disk is there */ |
8823 | 8839 | |
8824 | 8840 | if (nb_drives_opt < MAX_DRIVES) |
8825 | - drive_add(CDROM_ALIAS); | |
8841 | + drive_add(NULL, CDROM_ALIAS); | |
8826 | 8842 | |
8827 | 8843 | /* we always create at least one floppy */ |
8828 | 8844 | |
8829 | 8845 | if (nb_drives_opt < MAX_DRIVES) |
8830 | - drive_add(FD_ALIAS, 0); | |
8846 | + drive_add(NULL, FD_ALIAS, 0); | |
8831 | 8847 | |
8832 | 8848 | /* we always create one sd slot, even if no card is in it */ |
8833 | 8849 | |
8834 | 8850 | if (nb_drives_opt < MAX_DRIVES) |
8835 | - drive_add(SD_ALIAS); | |
8851 | + drive_add(NULL, SD_ALIAS); | |
8836 | 8852 | |
8837 | 8853 | /* open the virtual block devices */ |
8838 | 8854 | |
8839 | 8855 | for(i = 0; i < nb_drives_opt; i++) |
8840 | - if (drive_init(drives_opt[i], snapshot, machine) == -1) | |
8856 | + if (drive_init(&drives_opt[i], snapshot, machine) == -1) | |
8841 | 8857 | exit(1); |
8842 | 8858 | |
8843 | 8859 | register_savevm("timer", 0, 2, timer_save, timer_load, NULL); | ... | ... |