aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Turner <digit@android.com>2010-09-10 10:15:07 +0200
committerDavid 'Digit' Turner <digit@android.com>2010-09-13 00:30:34 -0700
commita25351325187eb8eff8b9b090acd8f2d7684c6ff (patch)
treea692498d0473066d512d5fc39ad1c6327cb6be81
parent2abe02c0511b2278af9386e7ac5e266d890a38b1 (diff)
downloadexternal_qemu-a25351325187eb8eff8b9b090acd8f2d7684c6ff.zip
external_qemu-a25351325187eb8eff8b9b090acd8f2d7684c6ff.tar.gz
external_qemu-a25351325187eb8eff8b9b090acd8f2d7684c6ff.tar.bz2
upstream: minow hw updates.
-rw-r--r--block/vmdk.c296
-rw-r--r--block/vvfat.c58
-rw-r--r--hw/arm-misc.h7
-rw-r--r--hw/arm_boot.c20
-rw-r--r--hw/bt-hci-csr.c11
-rw-r--r--hw/bt-hci.c7
-rw-r--r--hw/bt-hid.c3
-rw-r--r--hw/bt-l2cap.c12
-rw-r--r--hw/bt-sdp.c7
-rw-r--r--hw/bt.c3
-rw-r--r--hw/bt.h4
-rw-r--r--hw/devices.h6
-rw-r--r--hw/isa.h1
-rw-r--r--hw/watchdog.h4
14 files changed, 224 insertions, 215 deletions
diff --git a/block/vmdk.c b/block/vmdk.c
index f21f02b..2d4ba42 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -76,7 +76,6 @@ typedef struct BDRVVmdkState {
unsigned int cluster_sectors;
uint32_t parent_cid;
- int is_parent;
} BDRVVmdkState;
typedef struct VmdkMetaData {
@@ -87,14 +86,6 @@ typedef struct VmdkMetaData {
int valid;
} VmdkMetaData;
-typedef struct ActiveBDRVState{
- BlockDriverState *hd; // active image handler
- uint64_t cluster_offset; // current write offset
-}ActiveBDRVState;
-
-static ActiveBDRVState activeBDRV;
-
-
static int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename)
{
uint32_t magic;
@@ -117,14 +108,13 @@ static int vmdk_probe(const uint8_t *buf, int buf_size, const char *filename)
static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
{
- BDRVVmdkState *s = bs->opaque;
char desc[DESC_SIZE];
uint32_t cid;
const char *p_name, *cid_str;
size_t cid_str_size;
/* the descriptor offset = 0x200 */
- if (bdrv_pread(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+ if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
return 0;
if (parent) {
@@ -145,12 +135,11 @@ static uint32_t vmdk_read_cid(BlockDriverState *bs, int parent)
static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
{
- BDRVVmdkState *s = bs->opaque;
char desc[DESC_SIZE], tmp_desc[DESC_SIZE];
char *p_name, *tmp_str;
/* the descriptor offset = 0x200 */
- if (bdrv_pread(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+ if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
return -1;
tmp_str = strstr(desc,"parentCID");
@@ -161,7 +150,7 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
pstrcat(desc, sizeof(desc), tmp_desc);
}
- if (bdrv_pwrite(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+ if (bdrv_pwrite_sync(bs->file, 0x200, desc, DESC_SIZE) < 0)
return -1;
return 0;
}
@@ -170,7 +159,7 @@ static int vmdk_is_cid_valid(BlockDriverState *bs)
{
#ifdef CHECK_CID
BDRVVmdkState *s = bs->opaque;
- BlockDriverState *p_bs = s->hd->backing_hd;
+ BlockDriverState *p_bs = bs->backing_hd;
uint32_t cur_pcid;
if (p_bs) {
@@ -187,6 +176,7 @@ static int vmdk_is_cid_valid(BlockDriverState *bs)
static int vmdk_snapshot_create(const char *filename, const char *backing_file)
{
int snp_fd, p_fd;
+ int ret;
uint32_t p_cid;
char *p_name, *gd_buf, *rgd_buf;
const char *real_filename, *temp_str;
@@ -211,34 +201,49 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
snp_fd = open(filename, O_RDWR | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 0644);
if (snp_fd < 0)
- return -1;
+ return -errno;
p_fd = open(backing_file, O_RDONLY | O_BINARY | O_LARGEFILE);
if (p_fd < 0) {
close(snp_fd);
- return -1;
+ return -errno;
}
/* read the header */
- if (lseek(p_fd, 0x0, SEEK_SET) == -1)
+ if (lseek(p_fd, 0x0, SEEK_SET) == -1) {
+ ret = -errno;
goto fail;
- if (read(p_fd, hdr, HEADER_SIZE) != HEADER_SIZE)
+ }
+ if (read(p_fd, hdr, HEADER_SIZE) != HEADER_SIZE) {
+ ret = -errno;
goto fail;
+ }
/* write the header */
- if (lseek(snp_fd, 0x0, SEEK_SET) == -1)
+ if (lseek(snp_fd, 0x0, SEEK_SET) == -1) {
+ ret = -errno;
goto fail;
- if (write(snp_fd, hdr, HEADER_SIZE) == -1)
+ }
+ if (write(snp_fd, hdr, HEADER_SIZE) == -1) {
+ ret = -errno;
goto fail;
+ }
memset(&header, 0, sizeof(header));
memcpy(&header,&hdr[4], sizeof(header)); // skip the VMDK4_MAGIC
- ftruncate(snp_fd, header.grain_offset << 9);
+ if (ftruncate(snp_fd, header.grain_offset << 9)) {
+ ret = -errno;
+ goto fail;
+ }
/* the descriptor offset = 0x200 */
- if (lseek(p_fd, 0x200, SEEK_SET) == -1)
+ if (lseek(p_fd, 0x200, SEEK_SET) == -1) {
+ ret = -errno;
goto fail;
- if (read(p_fd, p_desc, DESC_SIZE) != DESC_SIZE)
+ }
+ if (read(p_fd, p_desc, DESC_SIZE) != DESC_SIZE) {
+ ret = -errno;
goto fail;
+ }
if ((p_name = strstr(p_desc,"CID")) != NULL) {
p_name += sizeof("CID");
@@ -257,10 +262,14 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
(uint32_t)header.capacity, real_filename);
/* write the descriptor */
- if (lseek(snp_fd, 0x200, SEEK_SET) == -1)
+ if (lseek(snp_fd, 0x200, SEEK_SET) == -1) {
+ ret = -errno;
goto fail;
- if (write(snp_fd, s_desc, strlen(s_desc)) == -1)
+ }
+ if (write(snp_fd, s_desc, strlen(s_desc)) == -1) {
+ ret = -errno;
goto fail;
+ }
gd_offset = header.gd_offset * SECTOR_SIZE; // offset of GD table
rgd_offset = header.rgd_offset * SECTOR_SIZE; // offset of RGD table
@@ -270,122 +279,100 @@ static int vmdk_snapshot_create(const char *filename, const char *backing_file)
* 512 GTE per GT, each GTE points to grain
*/
gt_size = (int64_t)header.num_gtes_per_gte * header.granularity * SECTOR_SIZE;
- if (!gt_size)
+ if (!gt_size) {
+ ret = -EINVAL;
goto fail;
+ }
gde_entries = (uint32_t)(capacity / gt_size); // number of gde/rgde
gd_size = gde_entries * sizeof(uint32_t);
/* write RGD */
rgd_buf = qemu_malloc(gd_size);
- if (lseek(p_fd, rgd_offset, SEEK_SET) == -1)
+ if (lseek(p_fd, rgd_offset, SEEK_SET) == -1) {
+ ret = -errno;
goto fail_rgd;
- if (read(p_fd, rgd_buf, gd_size) != gd_size)
+ }
+ if (read(p_fd, rgd_buf, gd_size) != gd_size) {
+ ret = -errno;
goto fail_rgd;
- if (lseek(snp_fd, rgd_offset, SEEK_SET) == -1)
+ }
+ if (lseek(snp_fd, rgd_offset, SEEK_SET) == -1) {
+ ret = -errno;
goto fail_rgd;
- if (write(snp_fd, rgd_buf, gd_size) == -1)
+ }
+ if (write(snp_fd, rgd_buf, gd_size) == -1) {
+ ret = -errno;
goto fail_rgd;
- qemu_free(rgd_buf);
+ }
/* write GD */
gd_buf = qemu_malloc(gd_size);
- if (lseek(p_fd, gd_offset, SEEK_SET) == -1)
+ if (lseek(p_fd, gd_offset, SEEK_SET) == -1) {
+ ret = -errno;
goto fail_gd;
- if (read(p_fd, gd_buf, gd_size) != gd_size)
+ }
+ if (read(p_fd, gd_buf, gd_size) != gd_size) {
+ ret = -errno;
goto fail_gd;
- if (lseek(snp_fd, gd_offset, SEEK_SET) == -1)
+ }
+ if (lseek(snp_fd, gd_offset, SEEK_SET) == -1) {
+ ret = -errno;
goto fail_gd;
- if (write(snp_fd, gd_buf, gd_size) == -1)
+ }
+ if (write(snp_fd, gd_buf, gd_size) == -1) {
+ ret = -errno;
goto fail_gd;
- qemu_free(gd_buf);
-
- close(p_fd);
- close(snp_fd);
- return 0;
+ }
+ ret = 0;
- fail_gd:
+fail_gd:
qemu_free(gd_buf);
- fail_rgd:
+fail_rgd:
qemu_free(rgd_buf);
- fail:
+fail:
close(p_fd);
close(snp_fd);
- return -1;
+ return ret;
}
-static void vmdk_parent_close(BlockDriverState *bs)
+static int vmdk_parent_open(BlockDriverState *bs)
{
- if (bs->backing_hd)
- bdrv_close(bs->backing_hd);
-}
-
-static int parent_open = 0;
-static int vmdk_parent_open(BlockDriverState *bs, const char * filename)
-{
- BDRVVmdkState *s = bs->opaque;
char *p_name;
char desc[DESC_SIZE];
- char parent_img_name[1024];
/* the descriptor offset = 0x200 */
- if (bdrv_pread(s->hd, 0x200, desc, DESC_SIZE) != DESC_SIZE)
+ if (bdrv_pread(bs->file, 0x200, desc, DESC_SIZE) != DESC_SIZE)
return -1;
if ((p_name = strstr(desc,"parentFileNameHint")) != NULL) {
char *end_name;
- struct stat file_buf;
p_name += sizeof("parentFileNameHint") + 1;
if ((end_name = strchr(p_name,'\"')) == NULL)
return -1;
- if ((end_name - p_name) > sizeof (s->hd->backing_file) - 1)
+ if ((end_name - p_name) > sizeof (bs->backing_file) - 1)
return -1;
- pstrcpy(s->hd->backing_file, end_name - p_name + 1, p_name);
- if (stat(s->hd->backing_file, &file_buf) != 0) {
- path_combine(parent_img_name, sizeof(parent_img_name),
- filename, s->hd->backing_file);
- } else {
- pstrcpy(parent_img_name, sizeof(parent_img_name),
- s->hd->backing_file);
- }
-
- s->hd->backing_hd = bdrv_new("");
- if (!s->hd->backing_hd) {
- failure:
- bdrv_close(s->hd);
- return -1;
- }
- parent_open = 1;
- if (bdrv_open(s->hd->backing_hd, parent_img_name, BDRV_O_RDONLY) < 0)
- goto failure;
- parent_open = 0;
+ pstrcpy(bs->backing_file, end_name - p_name + 1, p_name);
}
return 0;
}
-static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
+static int vmdk_open(BlockDriverState *bs, int flags)
{
BDRVVmdkState *s = bs->opaque;
uint32_t magic;
- int l1_size, i, ret;
+ int l1_size, i;
- if (parent_open)
- // Parent must be opened as RO.
- flags = BDRV_O_RDONLY;
-
- ret = bdrv_file_open(&s->hd, filename, flags);
- if (ret < 0)
- return ret;
- if (bdrv_pread(s->hd, 0, &magic, sizeof(magic)) != sizeof(magic))
+ if (bdrv_pread(bs->file, 0, &magic, sizeof(magic)) != sizeof(magic))
goto fail;
magic = be32_to_cpu(magic);
if (magic == VMDK3_MAGIC) {
VMDK3Header header;
- if (bdrv_pread(s->hd, sizeof(magic), &header, sizeof(header)) != sizeof(header))
+ if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header)) != sizeof(header))
goto fail;
s->cluster_sectors = le32_to_cpu(header.granularity);
s->l2_size = 1 << 9;
@@ -397,7 +384,7 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
} else if (magic == VMDK4_MAGIC) {
VMDK4Header header;
- if (bdrv_pread(s->hd, sizeof(magic), &header, sizeof(header)) != sizeof(header))
+ if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header)) != sizeof(header))
goto fail;
bs->total_sectors = le64_to_cpu(header.capacity);
s->cluster_sectors = le64_to_cpu(header.granularity);
@@ -410,13 +397,8 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
s->l1_table_offset = le64_to_cpu(header.rgd_offset) << 9;
s->l1_backup_table_offset = le64_to_cpu(header.gd_offset) << 9;
- if (parent_open)
- s->is_parent = 1;
- else
- s->is_parent = 0;
-
// try to open parent images, if exist
- if (vmdk_parent_open(bs, filename) != 0)
+ if (vmdk_parent_open(bs) != 0)
goto fail;
// write the CID once after the image creation
s->parent_cid = vmdk_read_cid(bs,1);
@@ -427,7 +409,7 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
/* read the L1 table */
l1_size = s->l1_size * sizeof(uint32_t);
s->l1_table = qemu_malloc(l1_size);
- if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, l1_size) != l1_size)
+ if (bdrv_pread(bs->file, s->l1_table_offset, s->l1_table, l1_size) != l1_size)
goto fail;
for(i = 0; i < s->l1_size; i++) {
le32_to_cpus(&s->l1_table[i]);
@@ -435,7 +417,7 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
if (s->l1_backup_table_offset) {
s->l1_backup_table = qemu_malloc(l1_size);
- if (bdrv_pread(s->hd, s->l1_backup_table_offset, s->l1_backup_table, l1_size) != l1_size)
+ if (bdrv_pread(bs->file, s->l1_backup_table_offset, s->l1_backup_table, l1_size) != l1_size)
goto fail;
for(i = 0; i < s->l1_size; i++) {
le32_to_cpus(&s->l1_backup_table[i]);
@@ -448,7 +430,6 @@ static int vmdk_open(BlockDriverState *bs, const char *filename, int flags)
qemu_free(s->l1_backup_table);
qemu_free(s->l1_table);
qemu_free(s->l2_cache);
- bdrv_delete(s->hd);
return -1;
}
@@ -458,29 +439,28 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, VmdkMetaData *m_data,
static int get_whole_cluster(BlockDriverState *bs, uint64_t cluster_offset,
uint64_t offset, int allocate)
{
- uint64_t parent_cluster_offset;
BDRVVmdkState *s = bs->opaque;
uint8_t whole_grain[s->cluster_sectors*512]; // 128 sectors * 512 bytes each = grain size 64KB
// we will be here if it's first write on non-exist grain(cluster).
// try to read from parent image, if exist
- if (s->hd->backing_hd) {
- BDRVVmdkState *ps = s->hd->backing_hd->opaque;
+ if (bs->backing_hd) {
+ int ret;
if (!vmdk_is_cid_valid(bs))
return -1;
- parent_cluster_offset = get_cluster_offset(s->hd->backing_hd, NULL, offset, allocate);
-
- if (parent_cluster_offset) {
- BDRVVmdkState *act_s = activeBDRV.hd->opaque;
-
- if (bdrv_pread(ps->hd, parent_cluster_offset, whole_grain, ps->cluster_sectors*512) != ps->cluster_sectors*512)
- return -1;
+ ret = bdrv_read(bs->backing_hd, offset >> 9, whole_grain,
+ s->cluster_sectors);
+ if (ret < 0) {
+ return -1;
+ }
- //Write grain only into the active image
- if (bdrv_pwrite(act_s->hd, activeBDRV.cluster_offset << 9, whole_grain, sizeof(whole_grain)) != sizeof(whole_grain))
- return -1;
+ //Write grain only into the active image
+ ret = bdrv_write(bs->file, cluster_offset, whole_grain,
+ s->cluster_sectors);
+ if (ret < 0) {
+ return -1;
}
}
return 0;
@@ -491,14 +471,14 @@ static int vmdk_L2update(BlockDriverState *bs, VmdkMetaData *m_data)
BDRVVmdkState *s = bs->opaque;
/* update L2 table */
- if (bdrv_pwrite(s->hd, ((int64_t)m_data->l2_offset * 512) + (m_data->l2_index * sizeof(m_data->offset)),
- &(m_data->offset), sizeof(m_data->offset)) != sizeof(m_data->offset))
+ if (bdrv_pwrite_sync(bs->file, ((int64_t)m_data->l2_offset * 512) + (m_data->l2_index * sizeof(m_data->offset)),
+ &(m_data->offset), sizeof(m_data->offset)) < 0)
return -1;
/* update backup L2 table */
if (s->l1_backup_table_offset != 0) {
m_data->l2_offset = s->l1_backup_table[m_data->l1_index];
- if (bdrv_pwrite(s->hd, ((int64_t)m_data->l2_offset * 512) + (m_data->l2_index * sizeof(m_data->offset)),
- &(m_data->offset), sizeof(m_data->offset)) != sizeof(m_data->offset))
+ if (bdrv_pwrite_sync(bs->file, ((int64_t)m_data->l2_offset * 512) + (m_data->l2_index * sizeof(m_data->offset)),
+ &(m_data->offset), sizeof(m_data->offset)) < 0)
return -1;
}
@@ -545,7 +525,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, VmdkMetaData *m_data,
}
}
l2_table = s->l2_cache + (min_index * s->l2_size);
- if (bdrv_pread(s->hd, (int64_t)l2_offset * 512, l2_table, s->l2_size * sizeof(uint32_t)) !=
+ if (bdrv_pread(bs->file, (int64_t)l2_offset * 512, l2_table, s->l2_size * sizeof(uint32_t)) !=
s->l2_size * sizeof(uint32_t))
return 0;
@@ -558,18 +538,15 @@ static uint64_t get_cluster_offset(BlockDriverState *bs, VmdkMetaData *m_data,
if (!cluster_offset) {
if (!allocate)
return 0;
+
// Avoid the L2 tables update for the images that have snapshots.
- if (!s->is_parent) {
- cluster_offset = bdrv_getlength(s->hd);
- bdrv_truncate(s->hd, cluster_offset + (s->cluster_sectors << 9));
-
- cluster_offset >>= 9;
- tmp = cpu_to_le32(cluster_offset);
- l2_table[l2_index] = tmp;
- // Save the active image state
- activeBDRV.cluster_offset = cluster_offset;
- activeBDRV.hd = bs;
- }
+ cluster_offset = bdrv_getlength(bs->file);
+ bdrv_truncate(bs->file, cluster_offset + (s->cluster_sectors << 9));
+
+ cluster_offset >>= 9;
+ tmp = cpu_to_le32(cluster_offset);
+ l2_table[l2_index] = tmp;
+
/* First of all we write grain itself, to avoid race condition
* that may to corrupt the image.
* This problem may occur because of insufficient space on host disk
@@ -621,17 +598,17 @@ static int vmdk_read(BlockDriverState *bs, int64_t sector_num,
n = nb_sectors;
if (!cluster_offset) {
// try to read from parent image, if exist
- if (s->hd->backing_hd) {
+ if (bs->backing_hd) {
if (!vmdk_is_cid_valid(bs))
return -1;
- ret = bdrv_read(s->hd->backing_hd, sector_num, buf, n);
+ ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
if (ret < 0)
return -1;
} else {
memset(buf, 0, 512 * n);
}
} else {
- if(bdrv_pread(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512) != n * 512)
+ if(bdrv_pread(bs->file, cluster_offset + index_in_cluster * 512, buf, n * 512) != n * 512)
return -1;
}
nb_sectors -= n;
@@ -667,7 +644,7 @@ static int vmdk_write(BlockDriverState *bs, int64_t sector_num,
if (!cluster_offset)
return -1;
- if (bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512) != n * 512)
+ if (bdrv_pwrite(bs->file, cluster_offset + index_in_cluster * 512, buf, n * 512) != n * 512)
return -1;
if (m_data.valid) {
/* update L2 tables */
@@ -715,6 +692,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
int64_t total_size = 0;
const char *backing_file = NULL;
int flags = 0;
+ int ret;
// Read out options
while (options && options->name) {
@@ -736,7 +714,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
0644);
if (fd < 0)
- return -1;
+ return -errno;
magic = cpu_to_be32(VMDK4_MAGIC);
memset(&header, 0, sizeof(header));
header.version = cpu_to_le32(1);
@@ -771,22 +749,44 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
header.check_bytes[3] = 0xa;
/* write all the data */
- write(fd, &magic, sizeof(magic));
- write(fd, &header, sizeof(header));
+ ret = qemu_write_full(fd, &magic, sizeof(magic));
+ if (ret != sizeof(magic)) {
+ ret = -errno;
+ goto exit;
+ }
+ ret = qemu_write_full(fd, &header, sizeof(header));
+ if (ret != sizeof(header)) {
+ ret = -errno;
+ goto exit;
+ }
- ftruncate(fd, header.grain_offset << 9);
+ ret = ftruncate(fd, header.grain_offset << 9);
+ if (ret < 0) {
+ ret = -errno;
+ goto exit;
+ }
/* write grain directory */
lseek(fd, le64_to_cpu(header.rgd_offset) << 9, SEEK_SET);
for (i = 0, tmp = header.rgd_offset + gd_size;
- i < gt_count; i++, tmp += gt_size)
- write(fd, &tmp, sizeof(tmp));
+ i < gt_count; i++, tmp += gt_size) {
+ ret = qemu_write_full(fd, &tmp, sizeof(tmp));
+ if (ret != sizeof(tmp)) {
+ ret = -errno;
+ goto exit;
+ }
+ }
/* write backup grain directory */
lseek(fd, le64_to_cpu(header.gd_offset) << 9, SEEK_SET);
for (i = 0, tmp = header.gd_offset + gd_size;
- i < gt_count; i++, tmp += gt_size)
- write(fd, &tmp, sizeof(tmp));
+ i < gt_count; i++, tmp += gt_size) {
+ ret = qemu_write_full(fd, &tmp, sizeof(tmp));
+ if (ret != sizeof(tmp)) {
+ ret = -errno;
+ goto exit;
+ }
+ }
/* compose the descriptor */
real_filename = filename;
@@ -803,10 +803,16 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
/* write the descriptor */
lseek(fd, le64_to_cpu(header.desc_offset) << 9, SEEK_SET);
- write(fd, desc, strlen(desc));
+ ret = qemu_write_full(fd, desc, strlen(desc));
+ if (ret != strlen(desc)) {
+ ret = -errno;
+ goto exit;
+ }
+ ret = 0;
+exit:
close(fd);
- return 0;
+ return ret;
}
static void vmdk_close(BlockDriverState *bs)
@@ -815,15 +821,11 @@ static void vmdk_close(BlockDriverState *bs)
qemu_free(s->l1_table);
qemu_free(s->l2_cache);
- // try to close parent image, if exist
- vmdk_parent_close(s->hd);
- bdrv_delete(s->hd);
}
static void vmdk_flush(BlockDriverState *bs)
{
- BDRVVmdkState *s = bs->opaque;
- bdrv_flush(s->hd);
+ bdrv_flush(bs->file);
}
@@ -850,7 +852,7 @@ static BlockDriver bdrv_vmdk = {
.format_name = "vmdk",
.instance_size = sizeof(BDRVVmdkState),
.bdrv_probe = vmdk_probe,
- .bdrv_open = vmdk_open,
+ .bdrv_open = vmdk_open,
.bdrv_read = vmdk_read,
.bdrv_write = vmdk_write,
.bdrv_close = vmdk_close,
diff --git a/block/vvfat.c b/block/vvfat.c
index 1e37b9f..de50dc7 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -379,7 +379,7 @@ static void init_mbr(BDRVVVFATState* s)
{
/* TODO: if the files mbr.img and bootsect.img exist, use them */
mbr_t* real_mbr=(mbr_t*)s->first_sectors;
- partition_t* partition=&(real_mbr->partition[0]);
+ partition_t* partition = &(real_mbr->partition[0]);
int lba;
memset(s->first_sectors,0,512);
@@ -512,7 +512,7 @@ static inline uint8_t fat_chksum(const direntry_t* entry)
for(i=0;i<11;i++) {
unsigned char c;
- c = (i <= 8) ? entry->name[i] : entry->extension[i-8];
+ c = (i < 8) ? entry->name[i] : entry->extension[i-8];
chksum=(((chksum&0xfe)>>1)|((chksum&0x01)?0x80:0)) + c;
}
@@ -526,7 +526,7 @@ static uint16_t fat_datetime(time_t time,int return_time) {
t=localtime(&time); /* this is not thread safe */
#else
struct tm t1;
- t=&t1;
+ t = &t1;
localtime_r(&time,t);
#endif
if(return_time)
@@ -868,7 +868,8 @@ static int init_directories(BDRVVVFATState* s,
{
direntry_t* entry=array_get_next(&(s->directory));
entry->attributes=0x28; /* archive | volume label */
- snprintf((char*)entry->name,11,"QEMU VVFAT");
+ memcpy(entry->name,"QEMU VVF",8);
+ memcpy(entry->extension,"AT ",3);
}
/* Now build FAT, and write back information into directory */
@@ -882,7 +883,7 @@ static int init_directories(BDRVVVFATState* s,
mapping->dir_index = 0;
mapping->info.dir.parent_mapping_index = -1;
mapping->first_mapping_index = -1;
- mapping->path = strdup(dirname);
+ mapping->path = qemu_strdup(dirname);
i = strlen(mapping->path);
if (i > 0 && mapping->path[i - 1] == '/')
mapping->path[i - 1] = '\0';
@@ -1098,8 +1099,8 @@ static inline void vvfat_close_current_file(BDRVVVFATState *s)
*/
static inline int find_mapping_for_cluster_aux(BDRVVVFATState* s,int cluster_num,int index1,int index2)
{
- int index3=index1+1;
while(1) {
+ int index3;
mapping_t* mapping;
index3=(index1+index2)/2;
mapping=array_get(&(s->mapping),index3);
@@ -1243,7 +1244,7 @@ static void print_direntry(const direntry_t* direntry)
int j = 0;
char buffer[1024];
- fprintf(stderr, "direntry 0x%x: ", (int)direntry);
+ fprintf(stderr, "direntry %p: ", direntry);
if(!direntry)
return;
if(is_long_name(direntry)) {
@@ -1272,7 +1273,11 @@ static void print_direntry(const direntry_t* direntry)
static void print_mapping(const mapping_t* mapping)
{
- fprintf(stderr, "mapping (0x%x): begin, end = %d, %d, dir_index = %d, first_mapping_index = %d, name = %s, mode = 0x%x, " , (int)mapping, mapping->begin, mapping->end, mapping->dir_index, mapping->first_mapping_index, mapping->path, mapping->mode);
+ fprintf(stderr, "mapping (%p): begin, end = %d, %d, dir_index = %d, "
+ "first_mapping_index = %d, name = %s, mode = 0x%x, " ,
+ mapping, mapping->begin, mapping->end, mapping->dir_index,
+ mapping->first_mapping_index, mapping->path, mapping->mode);
+
if (mapping->mode & MODE_DIRECTORY)
fprintf(stderr, "parent_mapping_index = %d, first_dir_index = %d\n", mapping->info.dir.parent_mapping_index, mapping->info.dir.first_dir_index);
else
@@ -1632,12 +1637,12 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
/* rename */
if (strcmp(basename, basename2))
- schedule_rename(s, cluster_num, strdup(path));
+ schedule_rename(s, cluster_num, qemu_strdup(path));
} else if (is_file(direntry))
/* new file */
- schedule_new_file(s, strdup(path), cluster_num);
+ schedule_new_file(s, qemu_strdup(path), cluster_num);
else {
- assert(0);
+ abort();
return 0;
}
}
@@ -1658,7 +1663,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
if (offset != mapping->info.file.offset + s->cluster_size
* (cluster_num - mapping->begin)) {
/* offset of this cluster in file chain has changed */
- assert(0);
+ abort();
copy_it = 1;
} else if (offset == 0) {
const char* basename = get_basename(mapping->path);
@@ -1670,7 +1675,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
if (mapping->first_mapping_index != first_mapping_index
&& mapping->info.file.offset > 0) {
- assert(0);
+ abort();
copy_it = 1;
}
@@ -1752,10 +1757,10 @@ static int check_directory_consistency(BDRVVVFATState *s,
mapping->mode &= ~MODE_DELETED;
if (strcmp(basename, basename2))
- schedule_rename(s, cluster_num, strdup(path));
+ schedule_rename(s, cluster_num, qemu_strdup(path));
} else
/* new directory */
- schedule_mkdir(s, cluster_num, strdup(path));
+ schedule_mkdir(s, cluster_num, qemu_strdup(path));
lfn_init(&lfn);
do {
@@ -1836,7 +1841,7 @@ DLOG(fprintf(stderr, "check direntry %d: \n", i); print_direntry(direntries + i)
goto fail;
}
} else
- assert(0); /* cluster_count = 0; */
+ abort(); /* cluster_count = 0; */
ret += cluster_count;
}
@@ -2256,7 +2261,11 @@ static int commit_one_file(BDRVVVFATState* s,
c = c1;
}
- ftruncate(fd, size);
+ if (ftruncate(fd, size)) {
+ perror("ftruncate()");
+ close(fd);
+ return -4;
+ }
close(fd);
return commit_mappings(s, first_cluster, dir_index);
@@ -2453,14 +2462,17 @@ static int handle_commits(BDRVVVFATState* s)
commit_t* commit = array_get(&(s->commits), i);
switch(commit->action) {
case ACTION_RENAME: case ACTION_MKDIR:
- assert(0);
+ abort();
fail = -2;
break;
case ACTION_WRITEOUT: {
+#ifndef NDEBUG
+ /* these variables are only used by assert() below */
direntry_t* entry = array_get(&(s->directory),
commit->param.writeout.dir_index);
uint32_t begin = begin_of_direntry(entry);
mapping_t* mapping = find_mapping_for_cluster(s, begin);
+#endif
assert(mapping);
assert(mapping->begin == begin);
@@ -2511,7 +2523,7 @@ static int handle_commits(BDRVVVFATState* s)
break;
}
default:
- assert(0);
+ abort();
}
}
if (i > 0 && array_remove_slice(&(s->commits), 0, i))
@@ -2599,7 +2611,7 @@ static int do_commit(BDRVVVFATState* s)
ret = handle_renames_and_mkdirs(s);
if (ret) {
fprintf(stderr, "Error handling renames (%d)\n", ret);
- assert(0);
+ abort();
return ret;
}
@@ -2610,21 +2622,21 @@ static int do_commit(BDRVVVFATState* s)
ret = commit_direntries(s, 0, -1);
if (ret) {
fprintf(stderr, "Fatal: error while committing (%d)\n", ret);
- assert(0);
+ abort();
return ret;
}
ret = handle_commits(s);
if (ret) {
fprintf(stderr, "Error handling commits (%d)\n", ret);
- assert(0);
+ abort();
return ret;
}
ret = handle_deletes(s);
if (ret) {
fprintf(stderr, "Error deleting\n");
- assert(0);
+ abort();
return ret;
}
diff --git a/hw/arm-misc.h b/hw/arm-misc.h
index 7523d44..010acb4 100644
--- a/hw/arm-misc.h
+++ b/hw/arm-misc.h
@@ -11,8 +11,6 @@
#ifndef ARM_MISC_H
#define ARM_MISC_H 1
-#include "cpu.h"
-
/* The CPU is also modeled as an interrupt controller. */
#define ARM_PIC_CPU_IRQ 0
#define ARM_PIC_CPU_FIQ 1
@@ -30,9 +28,14 @@ struct arm_boot_info {
const char *initrd_filename;
target_phys_addr_t loader_start;
target_phys_addr_t smp_loader_start;
+ target_phys_addr_t smp_priv_base;
int nb_cpus;
int board_id;
int (*atag_board)(struct arm_boot_info *info, void *p);
+ /* Used internally by arm_boot.c */
+ int is_linux;
+ target_phys_addr_t initrd_size;
+ target_phys_addr_t entry;
};
void arm_load_kernel(CPUState *env, struct arm_boot_info *info);
diff --git a/hw/arm_boot.c b/hw/arm_boot.c
index acfa67e..2061ee3 100644
--- a/hw/arm_boot.c
+++ b/hw/arm_boot.c
@@ -191,7 +191,8 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info)
int n;
int is_linux = 0;
uint64_t elf_entry;
- target_ulong entry;
+ target_phys_addr_t entry;
+ int big_endian;
/* Load the kernel. */
if (!info->kernel_filename) {
@@ -199,12 +200,15 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info)
exit(1);
}
- if (!env->boot_info) {
- if (info->nb_cpus == 0)
- info->nb_cpus = 1;
- env->boot_info = info;
- qemu_register_reset(main_cpu_reset, 0, env);
- }
+ if (info->nb_cpus == 0)
+ info->nb_cpus = 1;
+ env->boot_info = info;
+
+#ifdef TARGET_WORDS_BIGENDIAN
+ big_endian = 1;
+#else
+ big_endian = 0;
+#endif
/* Assume that raw images are linux kernels, and ELF images are not. */
kernel_size = load_elf(info->kernel_filename, 0, &elf_entry, NULL, NULL);
@@ -259,4 +263,6 @@ void arm_load_kernel(CPUState *env, struct arm_boot_info *info)
else
set_kernel_args(info, initrd_size, info->loader_start);
}
+ info->is_linux = is_linux;
+ qemu_register_reset(main_cpu_reset, 0, env);
}
diff --git a/hw/bt-hci-csr.c b/hw/bt-hci-csr.c
index 183441b..982577d 100644
--- a/hw/bt-hci-csr.c
+++ b/hw/bt-hci-csr.c
@@ -15,8 +15,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu-common.h"
@@ -227,7 +226,7 @@ static void csrhci_in_packet(struct csrhci_s *s, uint8_t *pkt)
*rpkt ++ = 0x20; /* Operational settings negotation Ok */
memcpy(rpkt, pkt, 7); rpkt += 7;
*rpkt ++ = 0xff;
- *rpkt ++ = 0xff;
+ *rpkt = 0xff;
break;
case H4_ALIVE_PKT:
@@ -239,7 +238,7 @@ static void csrhci_in_packet(struct csrhci_s *s, uint8_t *pkt)
rpkt = csrhci_out_packet_csr(s, H4_ALIVE_PKT, 2);
*rpkt ++ = 0xcc;
- *rpkt ++ = 0x00;
+ *rpkt = 0x00;
break;
default:
@@ -364,7 +363,7 @@ static int csrhci_ioctl(struct CharDriverState *chr, int cmd, void *arg)
switch (cmd) {
case CHR_IOCTL_SERIAL_SET_PARAMS:
ssp = (QEMUSerialSetParams *) arg;
- s->baud_delay = ticks_per_sec / ssp->speed;
+ s->baud_delay = get_ticks_per_sec() / ssp->speed;
/* Moments later... (but shorter than 100ms) */
s->modem_state |= CHR_TIOCM_CTS;
break;
@@ -390,7 +389,7 @@ static void csrhci_reset(struct csrhci_s *s)
s->out_len = 0;
s->out_size = FIFO_LEN;
s->in_len = 0;
- s->baud_delay = ticks_per_sec;
+ s->baud_delay = get_ticks_per_sec();
s->enable = 0;
s->in_hdr = INT_MAX;
s->in_data = INT_MAX;
diff --git a/hw/bt-hci.c b/hw/bt-hci.c
index 669866a..f1ee92c 100644
--- a/hw/bt-hci.c
+++ b/hw/bt-hci.c
@@ -994,13 +994,12 @@ static int bt_hci_features_req(struct bt_hci_s *hci, uint16_t handle)
static int bt_hci_version_req(struct bt_hci_s *hci, uint16_t handle)
{
- struct bt_device_s *slave;
evt_read_remote_version_complete params;
if (bt_hci_handle_bad(hci, handle))
return -ENODEV;
- slave = bt_hci_remote_dev(hci, handle);
+ bt_hci_remote_dev(hci, handle);
bt_hci_event_status(hci, HCI_SUCCESS);
@@ -2080,7 +2079,6 @@ static void bt_submit_sco(struct HCIInfo *info,
const uint8_t *data, int length)
{
struct bt_hci_s *hci = hci_from_info(info);
- struct bt_link_s *link;
uint16_t handle;
int datalen;
@@ -2089,7 +2087,6 @@ static void bt_submit_sco(struct HCIInfo *info,
handle = acl_handle((data[1] << 8) | data[0]);
datalen = data[2];
- data += 3;
length -= 3;
if (bt_hci_handle_bad(hci, handle)) {
@@ -2097,7 +2094,6 @@ static void bt_submit_sco(struct HCIInfo *info,
__FUNCTION__, handle);
return;
}
- handle &= ~HCI_HANDLE_OFFSET;
if (datalen > length) {
fprintf(stderr, "%s: SCO packet too short (%iB < %iB)\n",
@@ -2105,7 +2101,6 @@ static void bt_submit_sco(struct HCIInfo *info,
return;
}
- link = hci->lm.handle[handle].link;
/* TODO */
/* TODO: increase counter and send EVT_NUM_COMP_PKTS if synchronous
diff --git a/hw/bt-hid.c b/hw/bt-hid.c
index af0c3d5..e495dbf 100644
--- a/hw/bt-hid.c
+++ b/hw/bt-hid.c
@@ -15,8 +15,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * with this program; if not, if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu-common.h"
diff --git a/hw/bt-l2cap.c b/hw/bt-l2cap.c
index b22b761..7e2f668 100644
--- a/hw/bt-l2cap.c
+++ b/hw/bt-l2cap.c
@@ -14,9 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- * MA 02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu-common.h"
@@ -998,10 +996,10 @@ static void l2cap_iframe_in(struct l2cap_chan_s *ch, uint16_t cid,
l2cap_rexmit_enable(ch, !(hdr->data[0] >> 7));
if (hdr->data[0] & 1) {
- if (len != 4)
- /* TODO: Signal an error? */;
+ if (len != 4) {
+ /* TODO: Signal an error? */
return;
-
+ }
return l2cap_sframe_in(ch, le16_to_cpup((void *) hdr->data));
}
@@ -1220,7 +1218,7 @@ static void l2cap_teardown(struct l2cap_instance_s *l2cap, int send_disconnect)
for (cid = L2CAP_CID_ALLOC; cid < L2CAP_CID_MAX; cid ++)
if (l2cap->cid[cid]) {
l2cap->cid[cid]->params.close(l2cap->cid[cid]->params.opaque);
- free(l2cap->cid[cid]);
+ qemu_free(l2cap->cid[cid]);
}
if (l2cap->role)
diff --git a/hw/bt-sdp.c b/hw/bt-sdp.c
index 992de0e..cc0bf2f 100644
--- a/hw/bt-sdp.c
+++ b/hw/bt-sdp.c
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu-common.h"
@@ -160,7 +159,7 @@ static ssize_t sdp_svc_search(struct bt_l2cap_sdp_state_s *sdp,
if (len < 3)
return -SDP_INVALID_SYNTAX;
- end = (req[0] << 8) | req[1];
+ max = (req[0] << 8) | req[1];
req += 2;
len -= 2;
@@ -172,7 +171,7 @@ static ssize_t sdp_svc_search(struct bt_l2cap_sdp_state_s *sdp,
} else
start = 0;
- if (len > 1);
+ if (len > 1)
return -SDP_INVALID_SYNTAX;
/* Output the results */
diff --git a/hw/bt.c b/hw/bt.c
index 3f886b4..34bf004 100644
--- a/hw/bt.c
+++ b/hw/bt.c
@@ -14,8 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu-common.h"
diff --git a/hw/bt.h b/hw/bt.h
index 726905f..4a702ad 100644
--- a/hw/bt.h
+++ b/hw/bt.h
@@ -20,9 +20,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
- * MA 02110-1301 USA
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
/* BD Address */
diff --git a/hw/devices.h b/hw/devices.h
index 156bde2..c788373 100644
--- a/hw/devices.h
+++ b/hw/devices.h
@@ -6,6 +6,9 @@
/* smc91c111.c */
void smc91c111_init(NICInfo *, uint32_t, qemu_irq);
+/* lan9118.c */
+void lan9118_init(NICInfo *, uint32_t, qemu_irq);
+
/* tsc210x.c */
uWireSlave *tsc2102_init(qemu_irq pint);
uWireSlave *tsc2301_init(qemu_irq penirq, qemu_irq kbirq, qemu_irq dav);
@@ -64,7 +67,4 @@ qemu_irq tc6393xb_l3v_get(TC6393xbState *s);
void sm501_init(uint32_t base, uint32_t local_mem_bytes, qemu_irq irq,
CharDriverState *chr);
-/* usb-ohci.c */
-void usb_ohci_init_sm501(uint32_t mmio_base, uint32_t localmem_base,
- int num_ports, int devfn, qemu_irq irq);
#endif
diff --git a/hw/isa.h b/hw/isa.h
index f00a993..09b32a1 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -1,5 +1,6 @@
#ifndef HW_ISA_H
#define HW_ISA_H
+
/* ISA bus */
#include "ioport.h"
diff --git a/hw/watchdog.h b/hw/watchdog.h
index 77b9965..8e955cc 100644
--- a/hw/watchdog.h
+++ b/hw/watchdog.h
@@ -14,9 +14,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
- * USA.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* By Richard W.M. Jones (rjones@redhat.com).
*/