summaryrefslogtreecommitdiffstats
path: root/block.c
diff options
context:
space:
mode:
authorbellard2005-04-28 23:09:32 +0200
committerbellard2005-04-28 23:09:32 +0200
commit712e78744e3a0332825a80298f38225b30dec88c (patch)
treea2b59da7629b13843649281332fd0cf8be1267c2 /block.c
parentraw dmg support (diff)
downloadqemu-712e78744e3a0332825a80298f38225b30dec88c.tar.gz
qemu-712e78744e3a0332825a80298f38225b30dec88c.tar.xz
qemu-712e78744e3a0332825a80298f38225b30dec88c.zip
probing fixes
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1425 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'block.c')
-rw-r--r--block.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/block.c b/block.c
index 8baa3b87e2..18eaf46041 100644
--- a/block.c
+++ b/block.c
@@ -106,26 +106,29 @@ static BlockDriver *find_image_format(const char *filename)
size_t bufsize = 1024;
fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
- if (fd < 0)
- return NULL;
+ if (fd < 0) {
+ buf = NULL;
+ ret = 0;
+ } else {
#ifdef DIOCGSECTORSIZE
- {
- unsigned int sectorsize = 512;
- if (!ioctl(fd, DIOCGSECTORSIZE, &sectorsize) &&
- sectorsize > bufsize)
- bufsize = sectorsize;
- }
+ {
+ unsigned int sectorsize = 512;
+ if (!ioctl(fd, DIOCGSECTORSIZE, &sectorsize) &&
+ sectorsize > bufsize)
+ bufsize = sectorsize;
+ }
#endif
- buf = malloc(bufsize);
- if (!buf)
- return NULL;
- ret = read(fd, buf, bufsize);
- if (ret < 0) {
+ buf = qemu_malloc(bufsize);
+ if (!buf)
+ return NULL;
+ ret = read(fd, buf, bufsize);
+ if (ret < 0) {
+ close(fd);
+ qemu_free(buf);
+ return NULL;
+ }
close(fd);
- free(buf);
- return NULL;
}
- close(fd);
drv = NULL;
score_max = 0;
@@ -136,7 +139,7 @@ static BlockDriver *find_image_format(const char *filename)
drv = drv1;
}
}
- free(buf);
+ qemu_free(buf);
return drv;
}
@@ -154,7 +157,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
bs->read_only = 0;
bs->is_temporary = 0;
bs->encrypted = 0;
-
+
if (snapshot) {
BlockDriverState *bs1;
int64_t total_size;
@@ -183,7 +186,7 @@ int bdrv_open2(BlockDriverState *bs, const char *filename, int snapshot,
filename = tmp_filename;
bs->is_temporary = 1;
}
-
+
pstrcpy(bs->filename, sizeof(bs->filename), filename);
if (!drv) {
drv = find_image_format(filename);
@@ -653,4 +656,5 @@ void bdrv_init(void)
bdrv_register(&bdrv_dmg);
bdrv_register(&bdrv_bochs);
bdrv_register(&bdrv_vpc);
+ bdrv_register(&bdrv_vvfat);
}