/* Extract source driver type */
- if (!(tmp = strchr(src, ':')) || !tmp[0])
- goto skipdisk;
- strncpy(drvName, src, (tmp-src));
- drvName[tmp-src] = '\0';
+ if (!src[0]) {
+ strcpy(drvName, "phy");
+ tmp = &src[0];
+ } else if (!(tmp = strchr(src, ':')) || !tmp[0]) {
+ goto skipdisk;
+ } else {
+ strncpy(drvName, src, (tmp-src));
+ drvName[tmp-src] = '\0';
+ }
/* And the source driver sub-type */
if (!strncmp(drvName, "tap", 3)) {
memmove(src, src+(tmp1-src)+1, strlen(src)-(tmp1-src));
} else {
drvType[0] = '\0';
- memmove(src, src+(tmp-src)+1, strlen(src)-(tmp-src));
+ if (src[0])
+ memmove(src, src+(tmp-src)+1, strlen(src)-(tmp-src));
}
/* phy: type indicates a block device */
virBufferVSprintf(buf, " <driver name='%s' type='%s'/>\n", drvName, drvType);
else
virBufferVSprintf(buf, " <driver name='%s'/>\n", drvName);
- virBufferVSprintf(buf, " <source %s='%s'/>\n", block ? "dev" : "file", src);
+ if (src[0])
+ virBufferVSprintf(buf, " <source %s='%s'/>\n", block ? "dev" : "file", src);
virBufferVSprintf(buf, " <target dev='%s'/>\n", dev);
if (!strcmp(head, "r") ||
!strcmp(head, "ro"))
cur = cur->next;
}
- if (source == NULL) {
- if (target != NULL)
- xmlFree(target);
- if (device != NULL)
- xmlFree(device);
- return (-1);
- }
if (target == NULL) {
if (source != NULL)
xmlFree(source);
}
}
+ if (source == NULL && !cdrom) {
+ if (target != NULL)
+ xmlFree(target);
+ if (device != NULL)
+ xmlFree(device);
+ return (-1);
+ }
+
if (drvName) {
buflen += strlen((const char*)drvName) + 1;
if (!strcmp((const char*)drvName, "tap")) {
buflen += 4;
}
- buflen += strlen((const char*)source) + 1;
+ if(source)
+ buflen += strlen((const char*)source) + 1;
+ else
+ buflen += 1;
buflen += strlen((const char*)target) + 1;
if (hvm && xendConfigVersion == 1) /* ioemu: */
buflen += 6;
if (!(buf = malloc(buflen)))
goto cleanup;
- if (drvName) {
- strcpy(buf, (const char*)drvName);
- if (!strcmp((const char*)drvName, "tap")) {
- strcat(buf, ":");
- if (drvType)
- strcat(buf, (const char*)drvType);
+ if(source) {
+ if (drvName) {
+ strcpy(buf, (const char*)drvName);
+ if (!strcmp((const char*)drvName, "tap")) {
+ strcat(buf, ":");
+ if (drvType)
+ strcat(buf, (const char*)drvType);
+ else
+ strcat(buf, "aio");
+ }
+ } else {
+ if (typ == 0)
+ strcpy(buf, "file");
else
- strcat(buf, "aio");
+ strcpy(buf, "phy");
}
+ strcat(buf, ":");
+ strcat(buf, (const char*)source);
} else {
- if (typ == 0)
- strcpy(buf, "file");
- else
- strcpy(buf, "phy");
+ strcpy(buf, "");
}
- strcat(buf, ":");
- strcat(buf, (const char*)source);
strcat(buf, ",");
if (hvm && xendConfigVersion == 1)
strcat(buf, "ioemu:");
xmlFree(drvName);
xmlFree(device);
xmlFree(target);
- xmlFree(source);
+ if(source)
+ xmlFree(source);
*disk = buf;
return (ret);