mirror of https://github.com/xemu-project/xemu.git
probing fixes
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1425 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
7c35359cbf
commit
712e78744e
|
@ -54,7 +54,8 @@ static int cow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
{
|
{
|
||||||
const struct cow_header_v2 *cow_header = (const void *)buf;
|
const struct cow_header_v2 *cow_header = (const void *)buf;
|
||||||
|
|
||||||
if (be32_to_cpu(cow_header->magic) == COW_MAGIC &&
|
if (buf_size >= sizeof(struct cow_header_v2) &&
|
||||||
|
be32_to_cpu(cow_header->magic) == COW_MAGIC &&
|
||||||
be32_to_cpu(cow_header->version) == COW_VERSION)
|
be32_to_cpu(cow_header->version) == COW_VERSION)
|
||||||
return 100;
|
return 100;
|
||||||
else
|
else
|
||||||
|
|
19
block-qcow.c
19
block-qcow.c
|
@ -81,7 +81,8 @@ static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
{
|
{
|
||||||
const QCowHeader *cow_header = (const void *)buf;
|
const QCowHeader *cow_header = (const void *)buf;
|
||||||
|
|
||||||
if (be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
|
if (buf_size >= sizeof(QCowHeader) &&
|
||||||
|
be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
|
||||||
be32_to_cpu(cow_header->version) == QCOW_VERSION)
|
be32_to_cpu(cow_header->version) == QCOW_VERSION)
|
||||||
return 100;
|
return 100;
|
||||||
else
|
else
|
||||||
|
@ -551,9 +552,19 @@ static int qcow_create(const char *filename, int64_t total_size,
|
||||||
header_size = sizeof(header);
|
header_size = sizeof(header);
|
||||||
backing_filename_len = 0;
|
backing_filename_len = 0;
|
||||||
if (backing_file) {
|
if (backing_file) {
|
||||||
realpath(backing_file, backing_filename);
|
const char *p;
|
||||||
if (stat(backing_filename, &st) != 0) {
|
/* XXX: this is a hack: we do not attempt to check for URL
|
||||||
return -1;
|
like syntax */
|
||||||
|
p = strchr(backing_file, ':');
|
||||||
|
if (p && (p - backing_file) >= 2) {
|
||||||
|
/* URL like but exclude "c:" like filenames */
|
||||||
|
pstrcpy(backing_filename, sizeof(backing_filename),
|
||||||
|
backing_file);
|
||||||
|
} else {
|
||||||
|
realpath(backing_file, backing_filename);
|
||||||
|
if (stat(backing_filename, &st) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
header.mtime = cpu_to_be32(st.st_mtime);
|
header.mtime = cpu_to_be32(st.st_mtime);
|
||||||
header.backing_file_offset = cpu_to_be64(header_size);
|
header.backing_file_offset = cpu_to_be64(header_size);
|
||||||
|
|
|
@ -81,9 +81,8 @@ typedef struct BDRVVPCState {
|
||||||
|
|
||||||
static int vpc_probe(const uint8_t *buf, int buf_size, const char *filename)
|
static int vpc_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
{
|
{
|
||||||
if (!strncmp(buf, "conectix", 8))
|
if (buf_size >= 8 && !strncmp(buf, "conectix", 8))
|
||||||
return 100;
|
return 100;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
38
block.c
38
block.c
|
@ -106,26 +106,29 @@ static BlockDriver *find_image_format(const char *filename)
|
||||||
size_t bufsize = 1024;
|
size_t bufsize = 1024;
|
||||||
|
|
||||||
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||||
if (fd < 0)
|
if (fd < 0) {
|
||||||
return NULL;
|
buf = NULL;
|
||||||
|
ret = 0;
|
||||||
|
} else {
|
||||||
#ifdef DIOCGSECTORSIZE
|
#ifdef DIOCGSECTORSIZE
|
||||||
{
|
{
|
||||||
unsigned int sectorsize = 512;
|
unsigned int sectorsize = 512;
|
||||||
if (!ioctl(fd, DIOCGSECTORSIZE, §orsize) &&
|
if (!ioctl(fd, DIOCGSECTORSIZE, §orsize) &&
|
||||||
sectorsize > bufsize)
|
sectorsize > bufsize)
|
||||||
bufsize = sectorsize;
|
bufsize = sectorsize;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
buf = malloc(bufsize);
|
buf = qemu_malloc(bufsize);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return NULL;
|
return NULL;
|
||||||
ret = read(fd, buf, bufsize);
|
ret = read(fd, buf, bufsize);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
close(fd);
|
||||||
|
qemu_free(buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
free(buf);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
close(fd);
|
|
||||||
|
|
||||||
drv = NULL;
|
drv = NULL;
|
||||||
score_max = 0;
|
score_max = 0;
|
||||||
|
@ -136,7 +139,7 @@ static BlockDriver *find_image_format(const char *filename)
|
||||||
drv = drv1;
|
drv = drv1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(buf);
|
qemu_free(buf);
|
||||||
return drv;
|
return drv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,4 +656,5 @@ void bdrv_init(void)
|
||||||
bdrv_register(&bdrv_dmg);
|
bdrv_register(&bdrv_dmg);
|
||||||
bdrv_register(&bdrv_bochs);
|
bdrv_register(&bdrv_bochs);
|
||||||
bdrv_register(&bdrv_vpc);
|
bdrv_register(&bdrv_vpc);
|
||||||
|
bdrv_register(&bdrv_vvfat);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue