Change -drive parsing so that paths don't have to be double-escaped (Laurent Vivier, Johannes Schindelin)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3909 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
		
							parent
							
								
									5697ff6b88
								
							
						
					
					
						commit
						609497ab3c
					
				@ -234,7 +234,8 @@ Define a new drive. Valid options are:
 | 
				
			|||||||
@table @code
 | 
					@table @code
 | 
				
			||||||
@item file=@var{file}
 | 
					@item file=@var{file}
 | 
				
			||||||
This option defines which disk image (@pxref{disk_images}) to use with
 | 
					This option defines which disk image (@pxref{disk_images}) to use with
 | 
				
			||||||
this drive.
 | 
					this drive. If the filename contains comma, you must double it
 | 
				
			||||||
 | 
					(for instance, "file=my,,file" to use file "my,file").
 | 
				
			||||||
@item if=@var{interface}
 | 
					@item if=@var{interface}
 | 
				
			||||||
This option defines on which type on interface the drive is connected.
 | 
					This option defines on which type on interface the drive is connected.
 | 
				
			||||||
Available types are: ide, scsi, sd, mtd, floppy, pflash.
 | 
					Available types are: ide, scsi, sd, mtd, floppy, pflash.
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										106
									
								
								vl.c
									
									
									
									
									
								
							
							
						
						
									
										106
									
								
								vl.c
									
									
									
									
									
								
							@ -231,7 +231,10 @@ unsigned int nb_prom_envs = 0;
 | 
				
			|||||||
const char *prom_envs[MAX_PROM_ENVS];
 | 
					const char *prom_envs[MAX_PROM_ENVS];
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
int nb_drives_opt;
 | 
					int nb_drives_opt;
 | 
				
			||||||
char drives_opt[MAX_DRIVES][1024];
 | 
					struct drive_opt {
 | 
				
			||||||
 | 
					    const char *file;
 | 
				
			||||||
 | 
					    char opt[1024];
 | 
				
			||||||
 | 
					} drives_opt[MAX_DRIVES];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static CPUState *cur_cpu;
 | 
					static CPUState *cur_cpu;
 | 
				
			||||||
static CPUState *next_cpu;
 | 
					static CPUState *next_cpu;
 | 
				
			||||||
@ -4581,24 +4584,33 @@ static int net_socket_mcast_init(VLANState *vlan, const char *host_str)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const char *get_word(char *buf, int buf_size, const char *p)
 | 
					static const char *get_opt_name(char *buf, int buf_size, const char *p)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    char *q;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    q = buf;
 | 
				
			||||||
 | 
					    while (*p != '\0' && *p != '=') {
 | 
				
			||||||
 | 
					        if (q && (q - buf) < buf_size - 1)
 | 
				
			||||||
 | 
					            *q++ = *p;
 | 
				
			||||||
 | 
					        p++;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (q)
 | 
				
			||||||
 | 
					        *q = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return p;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const char *get_opt_value(char *buf, int buf_size, const char *p)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    char *q;
 | 
					    char *q;
 | 
				
			||||||
    int substring;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    substring = 0;
 | 
					 | 
				
			||||||
    q = buf;
 | 
					    q = buf;
 | 
				
			||||||
    while (*p != '\0') {
 | 
					    while (*p != '\0') {
 | 
				
			||||||
        if (*p == '\\') {
 | 
					        if (*p == ',') {
 | 
				
			||||||
            p++;
 | 
					            if (*(p + 1) != ',')
 | 
				
			||||||
            if (*p == '\0')
 | 
					 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
        } else if (*p == '\"') {
 | 
					 | 
				
			||||||
            substring = !substring;
 | 
					 | 
				
			||||||
            p++;
 | 
					            p++;
 | 
				
			||||||
            continue;
 | 
					        }
 | 
				
			||||||
        } else if (!substring && (*p == ',' || *p == '='))
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
        if (q && (q - buf) < buf_size - 1)
 | 
					        if (q && (q - buf) < buf_size - 1)
 | 
				
			||||||
            *q++ = *p;
 | 
					            *q++ = *p;
 | 
				
			||||||
        p++;
 | 
					        p++;
 | 
				
			||||||
@ -4617,15 +4629,15 @@ static int get_param_value(char *buf, int buf_size,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    p = str;
 | 
					    p = str;
 | 
				
			||||||
    for(;;) {
 | 
					    for(;;) {
 | 
				
			||||||
        p = get_word(option, sizeof(option), p);
 | 
					        p = get_opt_name(option, sizeof(option), p);
 | 
				
			||||||
        if (*p != '=')
 | 
					        if (*p != '=')
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        p++;
 | 
					        p++;
 | 
				
			||||||
        if (!strcmp(tag, option)) {
 | 
					        if (!strcmp(tag, option)) {
 | 
				
			||||||
            (void)get_word(buf, buf_size, p);
 | 
					            (void)get_opt_value(buf, buf_size, p);
 | 
				
			||||||
            return strlen(buf);
 | 
					            return strlen(buf);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            p = get_word(NULL, 0, p);
 | 
					            p = get_opt_value(NULL, 0, p);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (*p != ',')
 | 
					        if (*p != ',')
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
@ -4642,7 +4654,7 @@ static int check_params(char *buf, int buf_size,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    p = str;
 | 
					    p = str;
 | 
				
			||||||
    for(;;) {
 | 
					    for(;;) {
 | 
				
			||||||
        p = get_word(buf, buf_size, p);
 | 
					        p = get_opt_name(buf, buf_size, p);
 | 
				
			||||||
        if (*p != '=')
 | 
					        if (*p != '=')
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        p++;
 | 
					        p++;
 | 
				
			||||||
@ -4651,7 +4663,7 @@ static int check_params(char *buf, int buf_size,
 | 
				
			|||||||
                break;
 | 
					                break;
 | 
				
			||||||
        if (params[i] == NULL)
 | 
					        if (params[i] == NULL)
 | 
				
			||||||
            return -1;
 | 
					            return -1;
 | 
				
			||||||
        p = get_word(NULL, 0, p);
 | 
					        p = get_opt_value(NULL, 0, p);
 | 
				
			||||||
        if (*p != ',')
 | 
					        if (*p != ',')
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        p++;
 | 
					        p++;
 | 
				
			||||||
@ -4810,18 +4822,18 @@ void do_info_network(void)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define HD_ALIAS "file=\"%s\",index=%d,media=disk"
 | 
					#define HD_ALIAS "index=%d,media=disk"
 | 
				
			||||||
#ifdef TARGET_PPC
 | 
					#ifdef TARGET_PPC
 | 
				
			||||||
#define CDROM_ALIAS "index=1,media=cdrom"
 | 
					#define CDROM_ALIAS "index=1,media=cdrom"
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
#define CDROM_ALIAS "index=2,media=cdrom"
 | 
					#define CDROM_ALIAS "index=2,media=cdrom"
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#define FD_ALIAS "index=%d,if=floppy"
 | 
					#define FD_ALIAS "index=%d,if=floppy"
 | 
				
			||||||
#define PFLASH_ALIAS "file=\"%s\",if=pflash"
 | 
					#define PFLASH_ALIAS "if=pflash"
 | 
				
			||||||
#define MTD_ALIAS "file=\"%s\",if=mtd"
 | 
					#define MTD_ALIAS "if=mtd"
 | 
				
			||||||
#define SD_ALIAS "index=0,if=sd"
 | 
					#define SD_ALIAS "index=0,if=sd"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int drive_add(const char *fmt, ...)
 | 
					static int drive_add(const char *file, const char *fmt, ...)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    va_list ap;
 | 
					    va_list ap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -4830,8 +4842,10 @@ static int drive_add(const char *fmt, ...)
 | 
				
			|||||||
        exit(1);
 | 
					        exit(1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    drives_opt[nb_drives_opt].file = file;
 | 
				
			||||||
    va_start(ap, fmt);
 | 
					    va_start(ap, fmt);
 | 
				
			||||||
    vsnprintf(drives_opt[nb_drives_opt], sizeof(drives_opt[0]), fmt, ap);
 | 
					    vsnprintf(drives_opt[nb_drives_opt].opt,
 | 
				
			||||||
 | 
					              sizeof(drives_opt[0].opt), fmt, ap);
 | 
				
			||||||
    va_end(ap);
 | 
					    va_end(ap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return nb_drives_opt++;
 | 
					    return nb_drives_opt++;
 | 
				
			||||||
@ -4866,7 +4880,8 @@ int drive_get_max_bus(BlockInterfaceType type)
 | 
				
			|||||||
    return max_bus;
 | 
					    return max_bus;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int drive_init(const char *str, int snapshot, QEMUMachine *machine)
 | 
					static int drive_init(struct drive_opt *arg, int snapshot,
 | 
				
			||||||
 | 
					                      QEMUMachine *machine)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    char buf[128];
 | 
					    char buf[128];
 | 
				
			||||||
    char file[1024];
 | 
					    char file[1024];
 | 
				
			||||||
@ -4881,6 +4896,7 @@ static int drive_init(const char *str, int snapshot, QEMUMachine *machine)
 | 
				
			|||||||
    int index;
 | 
					    int index;
 | 
				
			||||||
    int cache;
 | 
					    int cache;
 | 
				
			||||||
    int bdrv_flags;
 | 
					    int bdrv_flags;
 | 
				
			||||||
 | 
					    char *str = arg->opt;
 | 
				
			||||||
    char *params[] = { "bus", "unit", "if", "index", "cyls", "heads",
 | 
					    char *params[] = { "bus", "unit", "if", "index", "cyls", "heads",
 | 
				
			||||||
                       "secs", "trans", "media", "snapshot", "file",
 | 
					                       "secs", "trans", "media", "snapshot", "file",
 | 
				
			||||||
                       "cache", NULL };
 | 
					                       "cache", NULL };
 | 
				
			||||||
@ -5051,7 +5067,10 @@ static int drive_init(const char *str, int snapshot, QEMUMachine *machine)
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (arg->file == NULL)
 | 
				
			||||||
        get_param_value(file, sizeof(file), "file", str);
 | 
					        get_param_value(file, sizeof(file), "file", str);
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        pstrcpy(file, sizeof(file), arg->file);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* compute bus and unit according index */
 | 
					    /* compute bus and unit according index */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -8163,7 +8182,7 @@ int main(int argc, char **argv)
 | 
				
			|||||||
            break;
 | 
					            break;
 | 
				
			||||||
        r = argv[optind];
 | 
					        r = argv[optind];
 | 
				
			||||||
        if (r[0] != '-') {
 | 
					        if (r[0] != '-') {
 | 
				
			||||||
	    hda_index = drive_add(HD_ALIAS, argv[optind++], 0);
 | 
						    hda_index = drive_add(argv[optind++], HD_ALIAS, 0);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            const QEMUOption *popt;
 | 
					            const QEMUOption *popt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -8224,11 +8243,11 @@ int main(int argc, char **argv)
 | 
				
			|||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case QEMU_OPTION_hda:
 | 
					            case QEMU_OPTION_hda:
 | 
				
			||||||
                if (cyls == 0)
 | 
					                if (cyls == 0)
 | 
				
			||||||
                    hda_index = drive_add(HD_ALIAS, optarg, 0);
 | 
					                    hda_index = drive_add(optarg, HD_ALIAS, 0);
 | 
				
			||||||
                else
 | 
					                else
 | 
				
			||||||
                    hda_index = drive_add(HD_ALIAS
 | 
					                    hda_index = drive_add(optarg, HD_ALIAS
 | 
				
			||||||
			     ",cyls=%d,heads=%d,secs=%d%s",
 | 
								     ",cyls=%d,heads=%d,secs=%d%s",
 | 
				
			||||||
                             optarg, 0, cyls, heads, secs,
 | 
					                             0, cyls, heads, secs,
 | 
				
			||||||
                             translation == BIOS_ATA_TRANSLATION_LBA ?
 | 
					                             translation == BIOS_ATA_TRANSLATION_LBA ?
 | 
				
			||||||
                                 ",trans=lba" :
 | 
					                                 ",trans=lba" :
 | 
				
			||||||
                             translation == BIOS_ATA_TRANSLATION_NONE ?
 | 
					                             translation == BIOS_ATA_TRANSLATION_NONE ?
 | 
				
			||||||
@ -8237,19 +8256,19 @@ int main(int argc, char **argv)
 | 
				
			|||||||
            case QEMU_OPTION_hdb:
 | 
					            case QEMU_OPTION_hdb:
 | 
				
			||||||
            case QEMU_OPTION_hdc:
 | 
					            case QEMU_OPTION_hdc:
 | 
				
			||||||
            case QEMU_OPTION_hdd:
 | 
					            case QEMU_OPTION_hdd:
 | 
				
			||||||
		drive_add(HD_ALIAS, optarg, popt->index - QEMU_OPTION_hda);
 | 
					                drive_add(optarg, HD_ALIAS, popt->index - QEMU_OPTION_hda);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case QEMU_OPTION_drive:
 | 
					            case QEMU_OPTION_drive:
 | 
				
			||||||
                drive_add("%s", optarg);
 | 
					                drive_add(NULL, "%s", optarg);
 | 
				
			||||||
	        break;
 | 
						        break;
 | 
				
			||||||
            case QEMU_OPTION_mtdblock:
 | 
					            case QEMU_OPTION_mtdblock:
 | 
				
			||||||
	        drive_add(MTD_ALIAS, optarg);
 | 
					                drive_add(optarg, MTD_ALIAS);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case QEMU_OPTION_sd:
 | 
					            case QEMU_OPTION_sd:
 | 
				
			||||||
                drive_add("file=\"%s\"," SD_ALIAS, optarg);
 | 
					                drive_add(optarg, SD_ALIAS);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case QEMU_OPTION_pflash:
 | 
					            case QEMU_OPTION_pflash:
 | 
				
			||||||
	        drive_add(PFLASH_ALIAS, optarg);
 | 
					                drive_add(optarg, PFLASH_ALIAS);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case QEMU_OPTION_snapshot:
 | 
					            case QEMU_OPTION_snapshot:
 | 
				
			||||||
                snapshot = 1;
 | 
					                snapshot = 1;
 | 
				
			||||||
@ -8289,12 +8308,10 @@ int main(int argc, char **argv)
 | 
				
			|||||||
                        exit(1);
 | 
					                        exit(1);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
		    if (hda_index != -1)
 | 
							    if (hda_index != -1)
 | 
				
			||||||
		        snprintf(drives_opt[hda_index] +
 | 
					                        snprintf(drives_opt[hda_index].opt,
 | 
				
			||||||
			         strlen(drives_opt[hda_index]),
 | 
					                                 sizeof(drives_opt[hda_index].opt),
 | 
				
			||||||
			         sizeof(drives_opt[0]) -
 | 
					                                 HD_ALIAS ",cyls=%d,heads=%d,secs=%d%s",
 | 
				
			||||||
				 strlen(drives_opt[hda_index]),
 | 
					                                 0, cyls, heads, secs,
 | 
				
			||||||
		                 ",cyls=%d,heads=%d,secs=%d%s",
 | 
					 | 
				
			||||||
			         cyls, heads, secs,
 | 
					 | 
				
			||||||
			         translation == BIOS_ATA_TRANSLATION_LBA ?
 | 
								         translation == BIOS_ATA_TRANSLATION_LBA ?
 | 
				
			||||||
			     	    ",trans=lba" :
 | 
								     	    ",trans=lba" :
 | 
				
			||||||
			         translation == BIOS_ATA_TRANSLATION_NONE ?
 | 
								         translation == BIOS_ATA_TRANSLATION_NONE ?
 | 
				
			||||||
@ -8317,7 +8334,7 @@ int main(int argc, char **argv)
 | 
				
			|||||||
                kernel_cmdline = optarg;
 | 
					                kernel_cmdline = optarg;
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case QEMU_OPTION_cdrom:
 | 
					            case QEMU_OPTION_cdrom:
 | 
				
			||||||
		drive_add("file=\"%s\"," CDROM_ALIAS, optarg);
 | 
					                drive_add(optarg, CDROM_ALIAS);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case QEMU_OPTION_boot:
 | 
					            case QEMU_OPTION_boot:
 | 
				
			||||||
                boot_devices = optarg;
 | 
					                boot_devices = optarg;
 | 
				
			||||||
@ -8352,8 +8369,7 @@ int main(int argc, char **argv)
 | 
				
			|||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case QEMU_OPTION_fda:
 | 
					            case QEMU_OPTION_fda:
 | 
				
			||||||
            case QEMU_OPTION_fdb:
 | 
					            case QEMU_OPTION_fdb:
 | 
				
			||||||
		drive_add("file=\"%s\"," FD_ALIAS, optarg,
 | 
					                drive_add(optarg, FD_ALIAS, popt->index - QEMU_OPTION_fda);
 | 
				
			||||||
		          popt->index - QEMU_OPTION_fda);
 | 
					 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
#ifdef TARGET_I386
 | 
					#ifdef TARGET_I386
 | 
				
			||||||
            case QEMU_OPTION_no_fd_bootchk:
 | 
					            case QEMU_OPTION_no_fd_bootchk:
 | 
				
			||||||
@ -8822,22 +8838,22 @@ int main(int argc, char **argv)
 | 
				
			|||||||
    /* we always create the cdrom drive, even if no disk is there */
 | 
					    /* we always create the cdrom drive, even if no disk is there */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (nb_drives_opt < MAX_DRIVES)
 | 
					    if (nb_drives_opt < MAX_DRIVES)
 | 
				
			||||||
        drive_add(CDROM_ALIAS);
 | 
					        drive_add(NULL, CDROM_ALIAS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* we always create at least one floppy */
 | 
					    /* we always create at least one floppy */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (nb_drives_opt < MAX_DRIVES)
 | 
					    if (nb_drives_opt < MAX_DRIVES)
 | 
				
			||||||
        drive_add(FD_ALIAS, 0);
 | 
					        drive_add(NULL, FD_ALIAS, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* we always create one sd slot, even if no card is in it */
 | 
					    /* we always create one sd slot, even if no card is in it */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (nb_drives_opt < MAX_DRIVES)
 | 
					    if (nb_drives_opt < MAX_DRIVES)
 | 
				
			||||||
        drive_add(SD_ALIAS);
 | 
					        drive_add(NULL, SD_ALIAS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* open the virtual block devices */
 | 
					    /* open the virtual block devices */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for(i = 0; i < nb_drives_opt; i++)
 | 
					    for(i = 0; i < nb_drives_opt; i++)
 | 
				
			||||||
        if (drive_init(drives_opt[i], snapshot, machine) == -1)
 | 
					        if (drive_init(&drives_opt[i], snapshot, machine) == -1)
 | 
				
			||||||
	    exit(1);
 | 
						    exit(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
 | 
					    register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user