aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@android.com>2010-09-22 14:19:28 +0200
committerDavid 'Digit' Turner <digit@android.com>2010-09-22 14:19:28 +0200
commit4e024bb4f5c8aa8b07459f7fbd65c35122127fd1 (patch)
treeccd5835eef17757d3e1c069e391c415c0135023d /block
parent1d9873b37d2478554d9d678cd410bd3638c8dab3 (diff)
downloadexternal_qemu-4e024bb4f5c8aa8b07459f7fbd65c35122127fd1.zip
external_qemu-4e024bb4f5c8aa8b07459f7fbd65c35122127fd1.tar.gz
external_qemu-4e024bb4f5c8aa8b07459f7fbd65c35122127fd1.tar.bz2
Remove compiler warnings when building the emulator.
This forces -Wall during the build. Note that this patch doesn't remove all warnings, but most of the remaining ones are from upstream anyway. Change-Id: I8808d8495e99866e156ce5780d2e3c305eab491f
Diffstat (limited to 'block')
-rw-r--r--block/qcow2.c68
-rw-r--r--block/raw-posix.c10
2 files changed, 62 insertions, 16 deletions
diff --git a/block/qcow2.c b/block/qcow2.c
index aa8ff35..5ca20b2 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -71,7 +71,7 @@ static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
}
-/*
+/*
* read qcow2 extension and fill bs
* start reading from start_offset
* finish reading upon magic of value 0 or when end_offset reached
@@ -651,6 +651,35 @@ static int get_bits_from_size(size_t size)
return res;
}
+static int write_all(int fd, const void *buff, size_t bufsize)
+{
+ int ret = 0;
+ const char *ptr = buff;
+ while (bufsize > 0) {
+ ret = write(fd, ptr, bufsize);
+ if (ret < 0) {
+ if (errno != EINTR)
+ return -1;
+ } else {
+ bufsize -= ret;
+ }
+ }
+ return 0;
+}
+
+static int lseek_to(int fd, off_t offset)
+{
+ off_t ret;
+ do {
+ ret = lseek(fd, offset, SEEK_SET);
+ } while (ret == (off_t)-1 && errno == EINTR);
+
+ if (ret == (off_t)-1)
+ return -1;
+
+ return 0;
+}
+
static int qcow_create2(const char *filename, int64_t total_size,
const char *backing_file, const char *backing_format,
int flags, size_t cluster_size)
@@ -663,7 +692,6 @@ static int qcow_create2(const char *filename, int64_t total_size,
QCowCreateState s1, *s = &s1;
QCowExtension ext_bf = {0, 0};
-
memset(s, 0, sizeof(*s));
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
@@ -744,7 +772,8 @@ static int qcow_create2(const char *filename, int64_t total_size,
ref_clusters * s->cluster_size);
/* write all the data */
- write(fd, &header, sizeof(header));
+ if (write_all(fd, &header, sizeof(header)) < 0)
+ goto FAIL;
if (backing_file) {
if (backing_format_len) {
char zero[16];
@@ -753,29 +782,42 @@ static int qcow_create2(const char *filename, int64_t total_size,
memset(zero, 0, sizeof(zero));
cpu_to_be32s(&ext_bf.magic);
cpu_to_be32s(&ext_bf.len);
- write(fd, &ext_bf, sizeof(ext_bf));
- write(fd, backing_format, backing_format_len);
+ if (write_all(fd, &ext_bf, sizeof(ext_bf)) < 0 ||
+ write_all(fd, backing_format, backing_format_len) < 0)
+ goto FAIL;
if (d>0) {
- write(fd, zero, d);
+ if (write_all(fd, zero, d) < 0)
+ goto FAIL;
}
}
- write(fd, backing_file, backing_filename_len);
+ if (write_all(fd, backing_file, backing_filename_len) < 0)
+ goto FAIL;
}
- lseek(fd, s->l1_table_offset, SEEK_SET);
+ if (lseek_to(fd, s->l1_table_offset) < 0)
+ goto FAIL;
+
tmp = 0;
for(i = 0;i < l1_size; i++) {
- write(fd, &tmp, sizeof(tmp));
+ if (write_all(fd, &tmp, sizeof(tmp)) < 0)
+ goto FAIL;
}
- lseek(fd, s->refcount_table_offset, SEEK_SET);
- write(fd, s->refcount_table, s->cluster_size);
+ if (lseek_to(fd, s->refcount_table_offset) < 0 ||
+ write_all(fd, s->refcount_table, s->cluster_size) < 0)
+ goto FAIL;
- lseek(fd, s->refcount_block_offset, SEEK_SET);
- write(fd, s->refcount_block, ref_clusters * s->cluster_size);
+ if (lseek_to(fd, s->refcount_block_offset) < 0 ||
+ write_all(fd, s->refcount_block, ref_clusters * s->cluster_size) < 0)
+ goto FAIL;
qemu_free(s->refcount_table);
qemu_free(s->refcount_block);
close(fd);
return 0;
+FAIL:
+ qemu_free(s->refcount_table);
+ qemu_free(s->refcount_block);
+ close(fd);
+ return -errno;
}
static int qcow_create(const char *filename, QEMUOptionParameter *options)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 11effd7..0e9e343 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -570,7 +570,7 @@ static int posix_aio_init(void)
PosixAioState *s;
int fds[2];
struct qemu_paioinit ai;
-
+
if (posix_aio_state)
return 0;
@@ -836,7 +836,7 @@ again:
static int raw_create(const char *filename, QEMUOptionParameter *options)
{
- int fd;
+ int fd, ret;
int64_t total_size = 0;
/* Read out options */
@@ -851,8 +851,12 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
0644);
if (fd < 0)
return -EIO;
- ftruncate(fd, total_size * 512);
+ do {
+ ret = ftruncate(fd, total_size * 512);
+ } while (ret < 0 && errno == EINTR);
close(fd);
+ if (ret != 0)
+ return -errno;
return 0;
}